Hello,
I am not sure which forum to choose for my question, thus I hope I have chosen the right one. I have read and watched about Dynamo compatibility with Revit and it looks just amazing. However I use Civil 3d in my daily process which is AutoCAD based and though it's challenging to combine Dynamo with AutoCAD, I know it's possible, but I don't know how. I would like to discuss with you guys, maybe you have some experience with it or some thoughts to share. I have found this short video here: https://www.youtube.com/watch?v=oiz76GTN-8Y. Sorry that it's in Russian, don't understand Russian but I get the point that AutoCAD objects could be controlled from Dynamo.
Solved! Go to Solution.
Good day Khasan
Exactly how do you select the item in Autodesk? I have all the required packages and the IronPython script. I also have an AutoCAD file open with a random polyline I drew. How do I prime the code to select that line?
import System app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application") AcDoc = app.ActiveDocument msp = AcDoc.ModelSpace plines = [] for i in msp: if i.ObjectName == 'AcDbPolyline': plines.append(i) OUT = plines
Thanks!
Could you advise what it is I am doing wrong here: I am attempting to read in a curve by three points
restart = IN[0]
if IN[1] != True: off = 1/0
import clr
clr.AddReference('ProtoGeometry')
import Autodesk
from Autodesk.DesignScript.Geometry import *
import System
from System import *
DPoint = Autodesk.DesignScript.Geometry.Point
DCurve = Autodesk.DesignScript.Geometry.Arc
app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
AcDoc = app.ActiveDocument
def ptD(p):
return DPoint.ByCoordinates(p[0],p[1],p[2])
def curveD(p1,p2,p3):
return DCurve.ByStartPointEndPoint(ptD(p1),ptD(p2),ptD(p3))
sset = AcDoc.PickfirstSelectionSet
n = sset.Count
curvs = []
for i in range(n):
if sset.Item(i).EntityName == "AcGeCircArc3d":
stpt = sset.Item(i).StartPoint
midpt = sset.Item(i).pnt;
enpt = sset.Item(i).EndPoint
lns = curveD(stpt,midpt,enpt)
curvs.append(lns)
OUT = curvs
import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import * import System app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application") AcDoc = app.ActiveDocument sset = list(iter(AcDoc.PickfirstSelectionSet)) def ptD(p): return Point.ByCoordinates(p[0],p[1],p[2]) def curveD(p1,p2,p3): return Arc.ByCenterPointStartPointEndPoint(p1,p2,p3) curvs = [] for i in sset: if i.EntityName == "AcDbArc": stpt = ptD(i.StartPoint) cent = ptD(i.Center) enpt = ptD(i.EndPoint) lns = curveD(cent,stpt,enpt) curvs.append(lns) OUT = curvs
I seem to be getting some script errors over here. I'm wondering if it's because Autocad MEP isn't accepting them, or that I'm Using Dynamo 2017 with old packages.
based on the error it's not related with a AutoCAD MEP. Remember that MEP is a vertical product of AutoCAD, so until you manipulate AutoCAD objects such as blocks, lines, layers etc. it is only related to AutoCAD. Your error simply says that in the line 2 the script is trying to divide by 0. I believe a 2nd line in your script looks like this: if IN[1] != True: off = 1/0 . Try to switch ON/OFF node to true. Should work.
oooh... looks like I'm getting an error in line 25.
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. Traceback (most recent call last): File "<string>", line 25, in <module> EnvironmentError: System.Runtime.InteropServices.COMException (0x8001010A): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.Scripting.ComInterop.ComRuntimeHelpers.GetITypeInfoFromIDispatch(IDispatch dispatch, Boolean throwIfMissingExpectedTypeInfo) at Microsoft.Scripting.ComInterop.IDispatchComObject.EnsureScanDefinedMethods() at Microsoft.Scripting.ComInterop.IDispatchComObject.System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(Expression parameter) at System.Dynamic.DynamicMetaObject.Create(Object value, Expression expression) at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel) at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at Microsoft.Scripting.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at DSIronPython.IronPythonEvaluator.EvaluateIronPythonScript(String code, IList bindingNames, IList bindingValues)
can you tell me what are you trying to achieve? Maybe you could post your script content?
I'm really just trying to make the lines appear in Autocad MEP as the file intended.
but I'm hoping this is the correct script provided by the file I just downloaded.
restart = IN[0] if IN[1] != True: off = 1/0 import clr clr.AddReference('ProtoGeometry') import Autodesk from Autodesk.DesignScript.Geometry import * import System from System import * app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application") AcDoc = app.ActiveDocument lines = IN[2] def ptA(p): return Array[float]([p.X, p.Y, p.Z]) for k in lines: stpt = ptA(k.StartPoint) enpt = ptA(k.EndPoint) linn = AcDoc.ModelSpace.AddLine(stpt, enpt)
Please disregard that last message,
I finally got it to work XD. it was as you explained. All I needed to do was turn the On/Off Switch to True.
Thank you for your patience.
Dynamo has been integrated to Autodesk Civil 3D. we have a lot of nodes created for AutoCAD as well. go ahead and check it if needed for your workflow.
I'm trying to integrate dynamo with AutoCAD to do a certain task to creat hatch I hope someone can help me with the coding as I'm new and trying to understand, I think the steps should be as following
- Getting layer names from AutoCAD and store as a list.
- Iterate through the AutoCAD layers to do the following:
Can't find what you're looking for? Ask the community or share your knowledge.