Map Curves to CAD Layers

hi Dynamites,
Im trying to recreate @Thomas_Mahon 's node > CAD.CurvesFromCADLayers in fact i started with his old code CADLayerNames (see code below) Ive managed to get cad geometry and i think they are in proper order. My problem is grouping geomtery by layer. Any ideas how to achieve that? Of course some may ask why just use Bimorph Package, same answer as the others, IT issue and company policy so i would appreciate your help, Thanks

#Copyright 2017. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.co.uk
#Written by Thomas Mahon @Thomas__Mahon info@bimorph.co.uk Package: bimorphNodes
#GitHub: https://github.com/ThomasMahon/bimorphNodes/
#Follow: facebook.com/bimorphBIM | linkedin.com/company/bimorph-bim | @bimorphBIM

import clr

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

doc = DocumentManager.Instance.CurrentDBDocument

importDWG = UnwrapElement(IN[0])

geomEnum = importDWG.Geometry[Options()].GetEnumerator()

failedFilter = []
layerList = []
while geomEnum.MoveNext(): 
	instGeom = geomEnum.Current.GetInstanceGeometry()
	instGeomEnum = instGeom.GetEnumerator()
	cadGeometry = []
	for i in instGeom:
		cadGeometry.append(i.Convert())
	while instGeomEnum.MoveNext():
		e = instGeomEnum.Current
		try:
			graphicStyleId = e.GraphicsStyleId
			eleGraphicStyle = doc.GetElement(graphicStyleId)
			eleGraphicStyleName = eleGraphicStyle.GraphicsStyleCategory.Name
			
			layerList.Add(eleGraphicStyleName)
			
		except:
			try:
				vol = e.Volume
				
				if vol == 0.0:
					edgesList = e.Edges
					edgesEnum = edgesList.GetEnumerator()

					while edgesEnum.MoveNext():
						edge = edgesEnum.Current
						eleGraphicStyle = doc.GetElement(edge.GraphicsStyleId)
						eleGraphicStyleName = eleGraphicStyle.GraphicsStyleCategory.Name
						
						layerList.Add(eleGraphicStyleName)
						break	
			except:
				failedFilter.Add(e)
		
OUT = cadGeometry,set(layerList)

here’s the result at the moment
image

I think you can use my source code in older versions of bimorph nodes. Download versions before 1.5 which are written in IronPython and if I remember correctly i structure the data as a dictionary which will answer all your questions. Failing that…just structure your data in a dictionary, layer name as key, list as value, then append your curves to the list which are from that layer.

1 Like

awesome!, Many Thanks Thomas :slight_smile: