Hi! I’m trying to create a simple Python script that enables the user to select a polyline in the current drawing and get its object by using its ID to split it later with dynamo functions.
The only problem is that the GetObject method, both called from the ID and the Transaction, isn’t working as intended and it returns an error.
Am I missing something here? Tried recreating a bunch of examples of this method alone from this forum and none of them seemed to work.
# 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 *
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
def SelectObject():
promptSelectionOptions = PromptSelectionOptions()
promptSelectionOptions.SingleOnly = True
promptSelectionOptions.MessageForAdding = "Selecione a Polyline"
obj = editor.GetSelection(promptSelectionOptions)
objId = obj.Value.GetObjectIds()
return objId
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
objId = SelectObject()
output = objId.GetObject(OpenMode.ForRead)
# Commit before end transaction
t.Commit()
pass
# Assign your output to the OUT variable.
OUT = output