# Run a Command, a .scr or a .lisp from dynamo

**URL:** <https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698>\
**Category:** Civil 3D\
**Created:** [November 27, 2019, 2:43pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698 "2019-11-27T14:43:32Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [November 27, 2019, 2:43pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/1 "2019-11-27T14:43:32Z")

</div>

I am working on a dynamo routine to convert a survey drawing to our standards. I got the layer translation all set but i still need to do more cleanup like make all the objects to be by layer and set all the text to be an specific style. Is there a way to run a command within dynamo, a script (.scr) or a lisp?

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [November 27, 2019, 7:11pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/2 "2019-11-27T19:11:56Z")

</div>

You can use Python to open a file. I am not at work at the moment, but if you can’t find anything (tomorrow)i could write you something.

---

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [November 27, 2019, 7:31pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/3 "2019-11-27T19:31:02Z")

</div>

Thank you Daan i appreciate it. I just don’t see were to start because i am not familiar at all with python.

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [November 27, 2019, 9:43pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/4 "2019-11-27T21:43:03Z")

</div>

This is an example you can use to set all the Text and MText to the same style

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/d/4d829a41939902338050ca49ecafa5e4b08a027e.png)  
[SetAllObjectsColorByLayerAndSetAllTextsStyle.dyn](https://forum.dynamobim.com/uploads/short-url/4lykA0jwXqbdRMCidd5tidq5XX4.dyn) (6.0 KB)

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [November 28, 2019, 12:21pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/5 "2019-11-28T12:21:00Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/f/1f38c5ba97f5178a3843c07f1b06113896b1be55.png)

import sys  
path = r’C:\Program Files (x86)\IronPython 2.7\Lib’  
sys.path.append(path)

import os

def playSomething(path):  
from os import startfile  
startfile(path)

OUT = playSomething(IN[0])

I hope you can use this script, this will be able to run almost anything.

---

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [December 2, 2019, 4:49pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/6 "2019-12-02T16:49:56Z")

</div>

Thank you Paolo, the script works very well.

---

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [December 2, 2019, 8:35pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/7 "2019-12-02T20:35:49Z")

</div>

Thank you Dann, i will give it a shot.

---

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [December 11, 2019, 10:18pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/8 "2019-12-11T22:18:46Z")

</div>

Dann, i tried to run a simple .scr file using the python script but i get errors "[runScript.dyn](https://forum.dynamobim.com/uploads/short-url/a61ZGsb31R9p2tSWp5NrSQtwCjF.dyn) (4.8 KB) " ![image002](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/d/6d50b54ed7d80f2038fa11c9e29dc3f1c977a9d7.png)

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [December 12, 2019, 7:47am UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/9 "2019-12-12T07:47:00Z")

</div>

he csanchez use a “StringfromObject” between the “FileFromPath” and the Python Script

---

<div class="post-metadata">

**Author:** ![csanchez](https://avatars.discourse-cdn.com/v4/letter/c/8491ac/32.png) [@csanchez](https://forum.dynamobim.com/u/csanchez)\
**Post date:** [December 12, 2019, 3:39pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/10 "2019-12-12T15:39:26Z")

</div>

Hi Dann, thanks for the reply. I added the “StringfromObject” between the FileFromPath and i still getting the same error. I am attaching the files. (FYI the .scr file is share as .txt becaouse the forum upload won’t let me attached as with the script extension)

 ![runScript_2019-12-12_10-35-55](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/3/33caa82dc147893fe7fc4b799428763fe6e6e764.png) [runScript.dyn](https://forum.dynamobim.com/uploads/short-url/wbPpXLChQYKS87sXBphuYpuUv5S.dyn) (6.0 KB) [Uppercase-all.txt](https://forum.dynamobim.com/uploads/short-url/eSK5TIU4P8npAxLL3KwL32bZuiW.txt) (22 Bytes)

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [December 13, 2019, 7:28am UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/11 "2019-12-13T07:28:52Z")

</div>

Okay i also see that i get that problem, try using this setup, this works for me 🙂  
[New Setup for csanchez 2019-12-13.dyn](https://forum.dynamobim.com/uploads/short-url/gv8MPK3U4R12YkIiE5KkFWYGQ2S.dyn) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![e.winter](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@e.winter](https://forum.dynamobim.com/u/e.winter)\
**Post date:** [April 21, 2022, 1:45pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/12 "2022-04-21T13:45:08Z")

</div>

Solved it: Using the doc.SendStringToExecute method.

Source: [start lisp-Command immediately after sendstringtoexecute - Autodesk Community](https://forums.autodesk.com/t5/net/start-lisp-command-immediately-after-sendstringtoexecute/td-p/6862639)

 ![Load_and_start_lisp](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/d/2dd46987ccaf3af9358a6db1269550939626e168.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr

# 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 *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

def load_and_start_lisp(LispFilePath,LispCommand):

    Lisp2Load="(load " + "\"" + LispFilePath.Replace("\\","\\\\") + "\"" + ") "
    adoc.SendStringToExecute(Lisp2Load,True,False,False)	
    if LispCommand != "":
        adoc.SendStringToExecute(LispCommand.Trim() + " ", True,False,False)
        
	return Lisp2Load
	
# Assign your output to the OUT variable.
OUT = load_and_start_lisp(IN[0],IN[1])

```

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [April 21, 2022, 1:56pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/13 "2022-04-21T13:56:23Z")

</div>

FYI there is a dedicated node in Camber starting in v2.0.0 for this.

> [@How to use civil 3D commands in a Python Script?](https://forum.dynamobim.com/t/how-to-use-civil-3d-commands-in-a-python-script/65779/14):
>
> @andre.demski @Christhian @WrightEngineering FYI [Camber v2.0.0](https://github.com/mzjensen/Camber/releases/tag/v2.0.0) has a node to send commands to the command line. [sendcommand]

---

<div class="post-metadata">

**Author:** ![e.winter](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@e.winter](https://forum.dynamobim.com/u/e.winter)\
**Post date:** [April 21, 2022, 1:57pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/14 "2022-04-21T13:57:41Z")

</div>

I should have known… 😔  
But thanks for the tip! 🤗

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [April 21, 2022, 2:05pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/15 "2022-04-21T14:05:38Z")

</div>

Great work in Python though! 💪

---

<div class="post-metadata">

**Author:** ![hanywillim](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hanywillim/32/155832_2.png) [@hanywillim](https://forum.dynamobim.com/u/hanywillim)\
**Post date:** [March 20, 2023, 10:02pm UTC](https://forum.dynamobim.com/t/run-a-command-a-scr-or-a-lisp-from-dynamo/43698/16 "2023-03-20T22:02:28Z")

</div>

I tried to rin this code on Revit environment but it give me this error:  
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.  
Traceback (most recent call last):  
File “”, line 14, in   
IOError: System.IO.IOException: Could not add reference to assembly AcMgd  
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)  
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object references)  
at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction`4.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)

Any idea to fix it to work on Dynamo for Revit
