Create corridor surface (python)

I don’t know how to code using python (or much of anything else), but I’m trying to use the python node as a way to create corridor surfaces. I’ve tried to use various sample scripts found on this forum as a guide, but I’m coming up short. Can someone please review my code to get me back on track? It will create a single corridor surface, but there are three remaining issues:
CreateCorridorSurface.dyn (6.3 KB)

  1. I cannot get it to create multiple corridor surfaces given a list of names
  2. I’m getting a TypeError: “expected str, got CorridorSurface”
  3. The surface that get’s created is not activated in the Corridor properties.
    image
2 Likes

I resolved all three of these issues, but created a new one. I need the output to be a list of the created surfaces. It’s successfully creating the surfaces, but I get an empty list on the output.

def create_corridor_surfaces(names):
    """
    This method demonstrates how to create corridor surfaces from an existing corridor.
    :param names: List of corridor surface names to create
    :return: A list of corridor surface names
    """
    global adoc
    global ed
    global civdoc
    
    if names is None:
    	return
    	
    if not isinstance(names, list):
    	names = [names]
    	
    result = []
    
    try:
        # Get the active document in the AutoCAD session:
        with adoc.LockDocument():
            with adoc.Database as db:
                with db.TransactionManager.StartTransaction() as t:
                    # Ask the user to select a corridor to create a new corridor surface from
                    opt = PromptEntityOptions('\nSelect a Corridor')
                    opt.SetRejectMessage('\nObject must be Corridor.')
                    opt.AddAllowedClass(Corridor, False)

                    corid = ed.GetEntity(opt).ObjectId

                    cor = t.GetObject(corid, OpenMode.ForRead)

                    # Creates a new surface
                    for n in names:
                    	cor.CorridorSurfaces.Add(n)

                    t.Commit()
    except Exception() as ex:
        MessageBox.Show(ex.message)
    return result
	
	
OUT = create_corridor_surfaces(IN[0])
1 Like

Hi @keith.sowinski

result.append( cor)
return result
1 Like

Thank you. That gives me the output of

Autodesk.Civil.DatabaseServices.Corridor.

I tried
result.append(cor.CorridorSurfaces.Add(n))
and that gives me an output of
Autodesk.Civil.DatabaseServices.CorridorSurface

I thought that would work for me, but I can’t seem to do anything with that output. For instance, The CivilObject.Name node returns and error.

What do you need output?

The surface. Then I hoping to do other things to it like add feature lines to its definition, change it’s style, etc.

This should solve your problem:

2 Likes

Thank you for your help. One more thing I’d like to do with this python node.

Currently, the corridor selection is done with the python script.

               opt = PromptEntityOptions('\nSelect a Corridor')
                opt.SetRejectMessage('\nObject must be Corridor.')
                opt.AddAllowedClass(Corridor, False)

                corid = ed.GetEntity(opt).ObjectId

                cor = t.GetObject(corid, OpenMode.ForRead)

However, I would prefer to select the corridor using the Select Object node. I would prefer to select the corridor this way so it listed in Dynamo player next to the rest of the inputs.
image

How can I massage this python script to select the corridor in this way?

I found this nugget in the developers guide. Seems to be working.

corid = civdoc.CorridorCollection[corridorName]

Hi Keith,
Would you share the last dyn file please?
I made the corrections but I can’t be able to run it. :frowning:

@ozanunsal if you’re interested in a non-Python solution, there are nodes for Corridor surfaces in the Camber package.


4 Likes

Thank you for your time and reply.

I downloaded the package but it throws
“Could not load type ‘ExportableItem’ from assembly ‘AeccDataShortcutMgd, Version=13.4.214.0, Culture=neutral, PublicKeyToken=null’.”

Is this something related with Phyton libraries are not installed or is my Dynamo version old or am I just cooking up? :slight_smile: :innocent:

It is the version of Civil 3D that you are using. If you’re on 2021, please upgrade to 2021.3. If you’re on 2022, please upgrade to 2022.1 or later.