Hi. This planned script will need to handle a variety of different AutoCAD drawing object types. The selection set has DBTEXT, MTEXT, HATCH, POLYLINE and LINE objects. In this example, after verifying the selected object is a LIne, I need to get more Line properties. The StartPoint is not found, result is always 0,0,0 … what did I miss? Thx for your patience.
# 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 *
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
for s in acSSet:
if s:
obj = t.GetObject(s.ObjectId, OpenMode.ForRead)
if type(obj) is Line:
L = Line(t.GetObject(s.ObjectId, OpenMode.ForRead))
output.append(L.StartPoint)
else:
output.append("not")
t.Commit()
return output
if IN[0] == True:
OUT = select_objects()
else:
OUT = "nothing"
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 *
# The inputs to this node will be stored as a list in the IN variables.
adoc = Application.DocumentManager.MdiActiveDocument
editor = 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)
tv = []
errorReport = None
for oid in btr:
bl = t.GetObject(oid, OpenMode.ForRead)
try:
if isinstance(bl, DBText):
tv.append(bl.TextString)
# Catch and report Exception...
except:
import traceback
errorReport = traceback.format_exc()
t.Commit()
# Assign your output to the OUT variable.
if errorReport == None:
OUT = tv#Text Values
else:
OUT = errorReport
THANK YOU … THAMK YOU … THANK YOU … my code is working now!! and that’s with editor > select objects … the key to success was … isinstance … that solved it for me …