I am creating dynamo scripts using FeatureLine.ByName node to do a variety of tasks.
Currently I have a string node which I manually type the name of the feature line. Then then passes to the FeatureLine.ByName. I would like to make this more interactive for the intended user. When running the script I would like to prompt the user to select the required feature line and the output is the feature line name as a string.
I used co-pilot to assist with the python scripting. However Dynamo returns the error message with the python script: typeerror : instance property must be accessed through class instance [âFile ââ, line 25, in \nâ]
import clr
import sys
# Add references to Civil 3D and AutoCAD libraries
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')
from Autodesk.AutoCAD.ApplicationServices import Application
from Autodesk.AutoCAD.EditorInput import PromptEntityOptions, PromptEntityResult
from Autodesk.Civil.ApplicationServices import CivilApplication
from Autodesk.Civil.DatabaseServices import FeatureLine
# Get the active document
doc = Application.DocumentManager.MdiActiveDocument
ed = doc.Editor
# Prompt the user to select a feature line
opts = PromptEntityOptions("\nSelect a feature line: ")
opts.SetRejectMessage("\nObject must be a feature line.")
opts.AddAllowedClass(FeatureLine, True)
res = ed.GetEntity(opts)
# Check if the user made a valid selection
if res.Status == PromptEntityResult.Status.OK:
with doc.LockDocument():
tr = doc.TransactionManager.StartTransaction()
try:
# Get the selected feature line
feature_line = tr.GetObject(res.ObjectId, OpenMode.ForRead)
# Get the name of the feature line
feature_line_name = feature_line.Name
tr.Commit()
except Exception as e:
tr.Abort()
feature_line_name = str(e)
else:
feature_line_name = "Selection was not successful."
# Output the feature line name
OUT = feature_line_name
Well, I made a few modifications to find the error.
Turns out you did not reference the AcCoreMgd.dll and you used wrong classes at some places.
Also, you used PromptEntityResult.Status which does not exist, instead I used the PromptStatus Enum res.Status == Editorinput.PromptStatus.OK
import clr
import sys
# Add references to Civil 3D and AutoCAD libraries
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
from Autodesk.AutoCAD.ApplicationServices import *
import Autodesk.AutoCAD.EditorInput as Editorinput
from Autodesk.Civil.ApplicationServices import *
import Autodesk.Civil.DatabaseServices as Civil
from Autodesk.AutoCAD.DatabaseServices import *
# Get the active document
doc = Application.DocumentManager.MdiActiveDocument
ed = doc.Editor
# Prompt the user to select a feature line
opts = Editorinput.PromptEntityOptions("\nSelect a feature line: ")
opts.SetRejectMessage("\nObject must be a feature line.")
opts.AddAllowedClass(Civil.FeatureLine, True)
res = ed.GetEntity(opts)
# Check if the user made a valid selection
if res.Status == Editorinput.PromptStatus.OK:
with doc.LockDocument():
with doc.Database as db:
with db.TransactionManager.StartTransaction() as tr:
try:
# Get the selected feature line
feature_line = tr.GetObject(res.ObjectId, OpenMode.ForRead)
# Get the name of the feature line
feature_line_name = feature_line.Name
tr.Commit()
except Exception as e:
tr.Abort()
feature_line_name = str(e)
else:
feature_line_name = "Selection was not successful."
# Output the feature line name
OUT = feature_line_name
Hi Daniel, from my limited understanding of the data-shapes node. It is built for Revit. Yes I can use the some of the nodes. But Revit built packages unfortunately donât work for Civil 3D. Happy to test it out and prove my theory wrong.
Last I checked it works for Revit, Civil3D, Alias, FormIt, Advance Steel⌠The Revit selection nodes wonât work but the rest will, and I believe there are some Civil 3D nodes too.