DataShapes Civil 3D Select AutoCad Object Data

I would like to get the geometry of an existing solid in Civil3D so that i can check if it intersects with a generated solid within dynamo. I use the DataShapes SelectAutoCadObjects_Data node to select the element. After selection the result is a System.__ComObject anyone knows how the get the geometry of this kind of class?
UI works fine!
Same result in:
Civil 2020 Beta Dynamo 2.4.1.2161 Data-Shapes 2021.2.9
Civil 2021.0.1(hotfix) Dynamo 2.5.2.86 Data-Shapes 2021.2.9


Hi @GinoKoolman

You need to convert ComObject to Autodesk.AutoCAD.DynamoNodes.Object which can be done with few lines of python:

import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('Civil3DNodes')
clr.AddReference('AutoCADNodes')


# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
#Import References from dynamo
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor


def Get_Civil_Object(COMObject):
	if not isinstance(COMObject,list):
		COMObject = [COMObject]	
	output,handle = [],[]
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for c in COMObject:
					handle.append(str(c.Handle))
				t.Commit()
		for h in handle:
			output.append(SelectionByQuery.GetObjectByObjectHandle(h))
		return output


OUT = Get_Civil_Object(IN[0])

Great, thanks!

1 Like