Select multiple

THANK YOU @keith.sowinski

Really nice, Keith!

Changing the TypedValue with an IN[0] value instead “POLYLINE” you can use the Dynamo Objects Types Node as an input.

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AutoCADNodes')

from System import Array
# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# Import references from Dynamo
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery

adoc = Application.DocumentManager.MdiActiveDocument
ed = adoc.Editor

def select_objects():
	
	global adoc
	global ed
	
	outputQ = []
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:

				#acSSPrompt = ed.GetSelection()
				tv = TypedValue(0, IN[0])
				tva = Array[TypedValue]([tv])
				selFltr = SelectionFilter(tva)
				acSSPrompt = ed.GetSelection(selFltr)
					
				if acSSPrompt.Status == PromptStatus.OK:
					acSSet = acSSPrompt.Value
					hndl = []
					for s in acSSet:
						if s:
							obj = t.GetObject(s.ObjectId, OpenMode.ForRead)
							hndl.append(str(obj.Handle))
							
				t.Commit()
	for h in hndl:
		outputQ.append(SelectionByQuery.GetObjectByObjectHandle(h))
	return outputQ	
OUT = select_objects()
#if IN[0] == True:
	#OUT = select_objects()
#else:
	#OUT = "nothing"

By the way, the Null result is from an AutoCAD 2D Polyline (Spline). The PolylineExtensions.GetGeometry node can only handle SimplePoly Spline types.
Any thoughts how to change the Polyline Spline Cubic into SimplePoly?

1 Like