Create alignment from polyline using DataShapes selection node

I have an issue where i am selecting an object using the SelectAutoCadObjects_Data node from data shapes to select a poly line which results in an output of a _COMOBJECT rather than a dynamo object.


This is the pthon code used.

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])

Hi @hfinklea, why do you want use Data-Shapes?

You can get selection just with Python.
In Civil3d try this code, “true” as IN[0]:

import sys
import clr

clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AutoCADNodes')


# 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
	
	output = []
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:

				acSSPrompt = ed.GetSelection()
	
				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:
		output.append(SelectionByQuery.GetObjectByObjectHandle(h))
	return output	

if IN[0] == True:
	OUT = select_objects()
else:
	OUT = "nothing"

The code above is not mine. Thanks to the peolple here, who created it.

1 Like