Several ways to select objects According to the type as the result below.
Based on TypeName:
output = []
adoc = Application.DocumentManager.MdiActiveDocument
ed = adoc.Editor
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
rList = []
#Get the Lines on Layer"Ramps". TypeName could be "Dbtext", "Line"
for objectid in btr:
obj1 = t.GetObject(objectid, OpenMode.ForRead)
if obj1.GetType().Name.ToString() == "Line" and obj1.Layer == "Ramps-Side":
rList.append(str(obj1.Handle))
else:
pass
ed.WriteMessage("Done")
Type of the object
adoc = acapp.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
ed = adoc.Editor
# The inputs to this node will be stored as a list in the IN variables.
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
rList = []
#Get the Lines on Layer"Ramps"
for objectid in btr:
obj1 = t.GetObject(objectid, OpenMode.ForRead)
if obj1.GetType()==Line and obj1.Layer == "Ramps-Side":
# or we can use "obj1.GetType() == clr.GetClrType(Line)" to ensure get the same type by .Net types
rList.append(str(obj1.Handle))
else:
pass
Notes:
if obj1.GetType()==Line and obj1.Layer == "Ramps-Side":
rList.append((obj1.GetType() is clr.GetClrType(Line))) #result is true
if obj1.GetType()==Line and obj1.Layer == "Ramps-Side":
rList.append((obj1.GetType() is Line)) #result is false
if obj1.GetType()==Line and obj1.Layer == "Ramps-Side":
rList.append((obj1.GetType() == Line)) #result is True
Select via the class of the object and we donot need to get the object.
adoc = acapp.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
ed = adoc.Editor
# The inputs to this node will be stored as a list in the IN variables.
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
rList = []
#Get the Lines on Layer"Ramps"
for objectid in btr:
obj1 = t.GetObject(objectid, OpenMode.ForRead)
if (obj1.ObjectId.ObjectClass)==(RXClass.GetClass(Line)) and obj1.Layer == "Ramps-Side":
rList.append(str(obj1.Handle))
else:
pass