Clear list of targets

Hi,

I have created a script that adds a vast number of targets to specific subasseblies in all regions. The addig part works fine with the C3D Toolkit nodes but I’m stuck with deleting the target list before adding the new one. I try to clear the ObjectIDCollection, but dynamo says there is no such attribute.
What am I missing here? Thanks.


image

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

tinfo = IN[0]

with adoc.LockDocument():
	with adoc.Database as db:

		with db.TransactionManager.StartTransaction() as t:
            # Place your code below
			x = tinfo.TargetIds
			x.Clear()
				
       	t.Commit()

The input object type is Autodesk.Civil.DynamoNodes.SubassemblyTargetInfo, so you’d have to have to get the underlying Autodesk.Civil.DatabaseServices.SubassemblyTargetInfo object via the transaction before any of the API members can be called.

Oh, okay thanks @mzjensen . That makes sense.
Although, I’m trying to get the Autodesk.Civil.DatabaseServices.SubassemblyTargetInfo object without success. I looked up some solution ideas on the forum, but none of them seem to work.
Tried InternalDBObject and InternalObjectID, but it says there are no such attributes.
I have also tried to figure it out from the toolkit dll, but I’m not qualified enough to understand the inheritance from there.

You can get the object ID using InternalObjectID and then get the object from that using Transaction.GetObject.

That is exactly what I was trying to do, but I guess I’m doing something wrong:

# 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

tinfo = IN[0]

with adoc.LockDocument():
	with adoc.Database as db:

		with db.TransactionManager.StartTransaction() as t:
            # Place your code below
			targetinfoId = tinfo.InternalObjectID
			targetinfo = t.GetObject(targetinfoId, OpenMode.ForWrite)
							
       	t.Commit()
        pass

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

Hi

I haven’t tried that
You can use the code on the page with the appropriate change

If that doesn’t work, can you attach an example of a dynamo file?

Thanks

1 Like

Sorry @kovacsv, I misread the steps you’ve taken so far. It looks like the SubassemblyTargetInfo class in the Toolkit doesn’t inherit from CivilObject (or ultimately ObjectBase), so that’s why the InternalObjectId property isn’t available. So I think your Python node will have to start with the Corridor as the input (since you can get its ObjectId) and then work your way down the class hierarchy to access the target info.

1 Like

I was afraid I have to do that, sorting and list management may be a bit tricky for me in Python, thanks anyway.