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

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

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]