Get Region Name of FeatureLine

Hi All,
Using C3D 2025.2

I have a corridor with multiple regions using the same assembly. Some of the feature lines exist in some regions and not in others based on inputs.
->I need to get the region name of each of the associated feature lines.
I see no OOTB nodes to get this so i went to Python and tried the following from here - Extract (auto)Corridor Featurelines - Civil 3D - Dynamo

import clr

clr.AddReference(‘AcMgd’)
clr.AddReference(‘AcDbMgd’)
clr.AddReference(‘AeccDbMgd’)

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

autoFeatureLine = IN[0]
adoc = Application.DocumentManager.MdiActiveDocument

with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
oid = autoFeatureLine.InternalObjectId
obj = t.GetObject(oid, OpenMode.ForRead)
region = obj.CorridorFeaturelineRegionName
t.Commit()
pass
OUT = region

Any ideas?

Thanks
A

Sadly with statements don’t work well in CPython as the parent object doesn’t inherit the right methods. A fix will require restructuring your code to avoid the with statements, and thereby require you manually close each statement.

ok thanks Jacob,
Can you confirm that its possible to unwrap the corridorfeatureline to get the region name? If so how?

If you change the Python version (e.g.Ironpython 2.7) the warning indeed says that dynamonodes.corridorfeatureline doesnt have either internalobjectid or internaldbobject property.

As a workaround you can create the feature lines in civil and use the db objects via object selection. With actual feature lines the script worked for me.

thanks kovacsv, thats interesting and noted as a backup but i have far to many to manually do this every time we run the script. Hoping to get a solution without the need to create the feature lines separately.

Maybe someone more experienced than me can tell you if there are other ways to unwrap the dynamonodes feature lines directly.

Until then, maybe you can try one level lower, use the corridor object and fetch the feature lines inside the python code.

yes thanks again, i’ll give that a go.

its driving me crazy, i though this would be a straight forward thing to do. oh well

To convert from a Dynamo object to a Civil 3D object I always just take the handle from the Dynamo object and then get the object from the handle using the C3D API. Ideally that happens before the ‘with’ statements start.

ok, i have used the Baseline.CorridorFeatureLinesByCode node, how do i get the handle of those AutoFeatureLines?

Have you tried the Object.Handle node?

yes, i cant get it to work with Auto Corridor Feature Lines.

Tip: OUT = dir(obj) where object is the thing you have will usually return the full context of what you can do with a thing. So if you have your Baseline.CorridorFeatureLinesByCode as the variable autoFeatureLine you can run set the very next line to be OUT = dir(autoFeatureLine) and then comment out everything after it. Run that and you should get an indication of how to find the handle if you read over what you can do with the element. Just be sure you only have one feature line in, otherwise you’ll be getting the things you can do with a list.

Hi Jacob, I did as you said but still don’t see handle listed under dir of CorridorFeatureLine.

Do you have any other way to get the associated regions from Baseline.CorridorFeatureLines.ByCode node output (CorridorFeatureLines) ?

Do you have a sample DWG? I am not a Civil 3D user so stuff like building a corridor would take me far longer than it should.

I would like to suggest you use traceback to catch your errors. That way your document will unlock and you get to catch more specific errors. Also no need to Commit if you are not amending I guess.

simply put import traceback at the top

prepare an output e..g err = []

along the way you use

try: 
    "your code goes here"
except:
    err.append(traceback.format_exc()

at the end add your err list e.g. OUT = region, err

Your code however gave me errors, simply returned “All”

Thanks Geert,

That code was originally from @mzjensen and i assume worked then and now you got the result of “All” which is correct.

Did you amend the code at all?
What version of C3D are you using?

I still get errors with that original code.

I can get access to some properties through dir but still no available CorridorFeaturelineRegionName

The original from the post from mzjensen works fine for me indeed.

I’m running on 2024, no packages. That may be different, but I suspect not, since the 2024 documentation is same as 2025…

Note: The properties you are getting with dir are Dynamo Featureline Properties wich is a different class. The Autodesk.Civil.DatabaseServices.AutoCorridorFeatureLine soes not give PolyCurve as a Property.

Note: the original script is taking 1 AutoCorridorFeatureLine, you are giving a list. To report multiple you have to nest your code in a loop:

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

autoFeatureLines = IN[0]
adoc = Application.DocumentManager.MdiActiveDocument

regions = []

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            for fl in autoFeatureLines:
                oid = fl.InternalObjectId
                obj = t.GetObject(oid, OpenMode.ForRead)
                regions.append(obj.CorridorFeaturelineRegionName)
            t.Commit()
            pass
OUT = regions

Agreed, Yes i have since noticed it was Dynamo Featureline from dir. So we can disregard that for now.
I just tried your updated code for multiple regions and I get the same error

TypeError : No Method match given arguments for OnExit…

I tried one and multiple same result. Just tried in C3D 2023 same result also. See below for basic test node layout.

Are you feeding featureline from baseline node?

I strongly suggest you use traceback to catch the real error. “TypeError : No Method match given arguments for OnExit…” Is just a main error whereas with traceback you get logic feedback on whats really going on. So add:"

import clr
import traceback

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

autoFeatureLines = IN[0]
adoc = Application.DocumentManager.MdiActiveDocument

regions = []
err = None

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            try:
                for fl in autoFeatureLines:
                    oid = fl.InternalObjectId
                    obj = t.GetObject(oid, OpenMode.ForRead)
                    regions.append(obj.CorridorFeaturelineRegionName)
                #t.Commit()
            except:
                err = traceback.format_exc()
            

if err:
    OUT = err
else:
    OUT = regions