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)
I cannot get it to create multiple corridor surfaces given a list of names
I’m getting a TypeError: “expected str, got CorridorSurface”
The surface that get’s created is not activated in the Corridor properties.
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])
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.
How can I massage this python script to select the corridor in this way?
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?