Hello all,
New Civil3D/dynamo user here. I tried to reference some code that imports Autodesk.AutoCAD.ApplicationServices.Application and the result is the error as shown in the title and image. I have researched a bit and found out something about .NET API. I have also added AcCoreMgd.dll, AcDbMgd.dll and AcMgd.dll as references in the code but the error still persists. What do I need to do or import?
You need to post a copy of your Python code, so people can help you.
Though your import should look similar to the following:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
from System import Array
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
import Autodesk.AutoCAD.DatabaseServices as acaddbs
from Autodesk.AutoCAD.Geometry import *
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
Hello, yes it is rather similar. Please see below for the code
import clr
import sys
import os
import math
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox
import Autodesk.AutoCAD.ApplicationServices.Application as acapp
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
alignmentlst = IN[0]
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument
output = []
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
align = alignmentlst.InternalDBObject
Speed = align.DesignSpeeds
for i in Speed:
output.append({"Station": i.Station, "DesignSpeed": i.Value})
t.Commit()
OUT = output
Issue is with line 21 - from Autodesk.AutoCAD.ApplicationServices import Application as acapp.
You may notice that you’re using from **source library** import **thing** for all other imports. This is pretty much required for access to the AutoCAD API in Python, as the binaries aren’t native and have a BUNCH of reference issues otherwise. I do not recall import **full class name** working in any version. You can maintain the reference name of acapp and still use the ‘from X import Y’ method by using from Autodesk.AutoCAD.ApplicationServices import Application as acapp.
I would replace your top section above the “Alignmentlst” variable to the following and that should hopefully mitigate your issue which seems to be the order things are run.
import clr
import sys
import os
import math
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
import Autodesk.AutoCAD.ApplicationServices.Application as acapp
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
Of course Jacob’s comment is a valid replacement too, though i would watch out if you need other areas of the ApplicationServices that you still import that in too.
import clr
import sys
#import os
import math
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
from System import *
from System.IO import *
#from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox
import Autodesk.AutoCAD.ApplicationServices.Application as acapp
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
alignmentlst = IN[0]
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument
output = []
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
align = alignmentlst.InternalDBObject
Speed = align.DesignSpeeds
for i in Speed:
output.append({"Station": i.Station, "DesignSpeed": i.Value})
t.Commit()
OUT = output