GetObject() method not working as intended

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
1 Like

Why not use the DataShape ui for that?

1 Like

Didn’t know it had selection tools, only knew about inputs. This might be the way for now. Thank you very much for the hint!

Anyway it would be great to know what’s wrong with this method in case I need to use it in the future

Solved it! The method GetObjectIds() is returning an array, so in order to run the method GetObject(), I had to specify the first element of the array.

In case anyone has the same problem something like this code below should 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
            output = t.GetObject(objId[0],OpenMode.ForRead)
            # Commit before end transaction
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = output