How to use Autodesk.Civil.DynamoNodes.ObjectByName in Python

I want to implement the functionality shown in the figure using Python, but I get an error, and I don’t know how to solve it.

ss2 = Autodesk.Civil.DynamoNodes.ObjectByName("TinSurface","面组2530")


Hi,

try this


# 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')

# 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 *

clr.AddReference('AutoCADNodes')
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery


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

ss2 = SelectionByQuery.ObjectOfTypeByName("TinSurface","面组2530")

OUT = ss2
6 Likes

This is amazing; although I couldn’t find the entity node of SelectionByQuery.ObjectOfTypeByName here, I was still able to call it successfully in Python. If possible, could you tell me how to learn about such hidden functions?

1 Like

you can explore an assembly :

import sys
import clr

clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags

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

# 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 *

clr.AddReference('AutoCADNodes')
import Autodesk.AutoCAD.DynamoNodes as aDynNodes


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

#name_spaces = aDynNodes.GetTypes()
OUT = dir(aDynNodes), dir(aDynNodes.SelectionByQuery), aDynNodes.SelectionByQuery.ObjectOfTypeByName.__doc__
2 Likes

Thank you very much for your help!