Run a lisp from Dynamo for Revit

Hi Everybody,
i am trying to run a lisp from dynamo for Revit and i already found a python code to do that on the forum but it meant to work on Civil3D, i tried too much time to modify it but in vain,
Great appreciation for any guide.

https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/12?u=hanywillim

When i used the source code:

When trying to remove Civil3d Assemblies:

Error:
“IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at DSIronPython.IronPythonEvaluator.EvaluateIronPythonScript(String code, IList bindingNames, IList bindingValues)”

You can’t access the AutoCAD or Civil 3D .net APIs from outside the core application. Best to write these to work in native Civil/AutoCAD, and post out the necessarily data or save the DWG after modifying it.

The alternative is to utilize the COM api, which isn’t very stable. LinkDWG package has examples of this.

Hi,
using COM, assuming your lisp is loaded when AutoCAD starts

import sys
import clr
import System
from System import Array
from System import Type, Activator

def openFile(filedwg, pid_version):
	t = Type.GetTypeFromProgID(pid_version)
	app = Activator.CreateInstance(t)
	if filedwg and System.IO.File.Exists(filedwg):
		app.Documents.Open(filedwg)
	app.Visible = True
	return app, app.ActiveDocument
	
pid_version = IN[0]
filedwg = IN[1]
lispName = IN[2]

app, AcDoc = openFile(filedwg, pid_version)
AcDoc.SendCommand(lispName + " ")
4 Likes

It is working like a charm,
I really appreciate your help, God bless you always
Do you have idea to expand the functionality of the code to Run the lisp on many DWGs in a folder and save the modified drawings in a New folder.

Thanks in advance :heart:

By the way the code working even when i enter the Pid AutoCAD version “AutoCAD.Application” without specified any Number after, I don’t know it will affect on not when other of my colleagues use it?

try this

for save and close, you have this methods

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-F0135870-7411-42CB-82E6-87509ADF3DFF

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-ED0D0B02-25FC-4ED2-9DEE-2B0C9AA9416A

Curious… why not just run the code from Dynamo for Civil 3D?

Would likely be more stable and functional in the long term.

1 Like

Hi Jacob,
Sure it will be more stable when using the right tool for the task (Civil3D), but my situation is different because Civil3d is not installed on my PC besides i did not use it before (All i have and know is Revit), but in the nearest chance i will learn it.
Thanks

1 Like