Integrate Dynamo with Autocad

Integrate Dynamo with Autocad

Yonas89
Collaborator Collaborator
44,067 Views
51 Replies
Message 1 of 52

Integrate Dynamo with Autocad

Yonas89
Collaborator
Collaborator

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.

Accepted solutions (1)
44,068 Views
51 Replies
Replies (51)
Message 21 of 52

Anonymous
Not applicable

KhasanMamaev

 

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?

 

0 Likes
Message 22 of 52

Anonymous
Not applicable
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 
0 Likes
Message 23 of 52

Anonymous
Not applicable

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

0 Likes
Message 24 of 52

Anonymous
Not applicable
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
0 Likes
Message 25 of 52

ppesquera
Participant
Participant

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.Screenshot 2019-07-04 21.53.57.png

0 Likes
Message 26 of 52

Yonas89
Collaborator
Collaborator

@ppesquera,

 

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. 

Message 27 of 52

ppesquera
Participant
Participant

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)
0 Likes
Message 28 of 52

Yonas89
Collaborator
Collaborator

@ppesquera,

 

can you tell me what are you trying to achieve? Maybe you could post your script content?

0 Likes
Message 29 of 52

ppesquera
Participant
Participant

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)
0 Likes
Message 30 of 52

ppesquera
Participant
Participant

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.

0 Likes
Message 31 of 52

FrankHuang
Autodesk
Autodesk

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. 

"https://damassets.autodesk.net/content/dam/autodesk/logos/autodesk-logo-primary-rgb-black-small_forum.png"
Message 32 of 52

Anonymous
Not applicable

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:

  • Start of Function
  • set the currently selected layer to active.
  • select all polylines on the current layer.
  • select first item and get its elevation = x.
  • create hatch from the selected polylines.
  • Change the created hatch elevation to = x.
  •  End of Function
0 Likes
Message 33 of 52

Anonymous
Not applicable

Capture.JPG

0 Likes
Message 34 of 52

Anonymous
Not applicable

Could someone help me with the issue?

0 Likes
Message 35 of 52

Anonymous
Not applicable

Good day. Sorry, can you help me select an existing table in autocad via Dynamo?

0 Likes
Message 36 of 52

Anonymous
Not applicable

to select the table manually or programmatically?

0 Likes
Message 37 of 52

Anonymous
Not applicable

programmatically , so that you can then enter any data in a table cell

0 Likes
Message 38 of 52

Anonymous
Not applicable

KhasanMamaev_0-1594735598213.png

 

Message 39 of 52

Anonymous
Not applicable

alik_mail1_0-1594798014377.png

not work...I'm probably doing something wrong

0 Likes
Message 40 of 52

Anonymous
Not applicable

alik_mail1_0-1594800581585.png

 

I want to add data to this table, to this cell. The table was created earlier

0 Likes