Working with imported geometries (CAD blocks) through python in Dynamo

Hello,

I am trying to create a script using python to find the centroids of imported geometry in CAD blocks.

)

When the blocks are read by dynamo, it looks like they are UnknownInstances. How do I get Dynamo to ‘type’ them, so that I can use the API to sort the input array into a list of curves, and then run Curve.PointAtParameter to get the mid points. Averaging these would then allow me to get the centroid of the actual block itself, and that is the objective.

Could someone point me in the right direction please on how to work with UnknownInstances in order to accomplish this please?

The geometry referenced by the script. Each group of squiggles was imported as a block from a CAD file which was partially exploded.

There is a way to access Autocad data via

CAD=System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application").ActiveDocument
SEL= CAD.PickfirstSelectionSet
SEL = CAD.ModelSpace

if IN[0] == True and SEL != None and SEL.Count > 0:
	for obj in SEL:
		if obj.ObjectName == "AcDbPoint":
			PTX.append(obj)
		if obj.ObjectName == "AcDbBlockReference":
			AXX=obj.GetAttributes()
			if AXX != None:
				for att in AXX:
					BLK.append(obj)
					ATT.append(att)
		if obj.ObjectName == "AcDbText":
			TXT.append(obj)
		if obj.ObjectName == "AcDbMText":
			MTT.append(obj)
		if obj.ObjectName in ["AcDbSpline", "AcDbPolyline"]:
			PLY.append(obj)
		if obj.ObjectName == "AcDbFace":
			FAC.append(obj)

image

If the application is accessible this way, there must be a way to make the imported DWG and partially exploded blocks readable by Dynamo. Currently I am stumped since I cannot do anything with an UnknownElement type. It doesn’t have the ObjectName attribute.

2 Likes