Issues with transforming InternalDBObject to InternalObjectId

Hi,

I have a Python script part, that I wrote with the use of InternalDBObject property, but since I went after this unwrapping topic a bit, I want to rewrite it using InternalObjectId property.

Here are the old and new scrip parts (the variable namings are a bit different but not that cause the problem). The old one works well, but when I’m running the new one, an unhandled exception occurs and the whole Dynamo and C3D collapse and I haven’t found out the reason. The center_xy block is good, I get result for that, but when I allow to run the script for left_xy block also, it collapses.

Old:

# nested list from X, Y coordinates in the alignment centerline
centerXY = []
for i in station:
    centerXY.append(alignment.InternalDBObject.PointLocation(i, 0, 0, 0))
            
# nested list from X, Y coordinates parallel to the alignment offsetting it by the samplePointOffset values on the left side
leftXY = []
for i in station:
    j = 0
    while j < len(samplePointOffsetLeft):
        leftXY.append(alignment.InternalDBObject.PointLocation(i, samplePointOffsetLeft[j], 0, 0))
        j += 1

New:

# nested list from x and y coordinates in the alignment centerline
center_xy = []
for i in station:
    center_xy.append(t.GetObject(alignment.InternalObjectId, OpenMode.ForRead).PointLocation(i, 0, 0, 0))
            
# nested list from x and y coordinates parallel to the alignment offsetting it by the samp_pt_offset_left values
left_xy = []
for i in station:
    j = 0
    while j < len(samp_pt_offset_left):
        left_xy.append(t.GetObject(alignment.InternalObjectId, OpenMode.ForRead).PointLocation(i, samplePointOffsetLeft[j], 0, 0))
        j += 1

To be honest, I still not understand well what is the difference of InternalDBObject and InternalObjectId in usage. Maybe I need some more time to think about it :slight_smile:

InternalDBObject is the object itself. In C# I can access the object like this:

Alignment alignmentCD = alignment.InternalDBObject as Alignment;

Now I can access the alignment (from Dynamo) as a Civil 3D object and I have access to the full API for this object.

But it is not open for write, so I can’t manipulate it. Therefore, I need a transaction and the ObjectID of the alignment.

1 Like

Slowly, but I’ve started to understand it.

So if I’m sure, that I will not want to manipulate an object in my script, just want to query some propetrties of it, it doesn’t matter that I use xy.InternalDBObject… or t.GetObject(xy.InternalObjectId, OpenMode.ForRead)…

But in the example above I do exactly that, but the latter method didn’t work.

I do not speak Python, but it has similarities with C#. In C# you must also cast the returned object from the transaction to the type you want:

t.GetObject(alignment.InternalObjectId, OpenMode.ForRead) as Alignment

I think something like that must be done in Python as well. The result of a transaction.GetObject() is a generic database object and that kind of object has no method PointLocation().

I don’t know exactly if it is the same in Python, maybe you can find other example code where transactions are used. Or just try:

center_xy.append((t.GetObject(alignment.InternalObjectId, OpenMode.ForRead) as Alignment).PointLocation(i, 0, 0, 0))

2 Likes

I knew it! A typo caused it :exploding_head:
Anyway, thanks for your efforts, and I’m glad that you are so active at the forums. I already have your programming in .NET book and I will certainly have some questions as soon as I get myself through it.

2 Likes