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

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?

2 Likes

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.

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

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


SetAllObjectsColorByLayerAndSetAllTextsStyle.dyn (6.0 KB)

10 Likes

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.

1 Like

Thank you Paolo, the script works very well.

Thank you Dann, i will give it a shot.

Dann, i tried to run a simple .scr file using the python script but i get errors "runScript.dyn (4.8 KB) "image002

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

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.dyn (6.0 KB) Uppercase-all.txt (22 Bytes)

Okay i also see that i get that problem, try using this setup, this works for me :slight_smile:
New Setup for csanchez 2019-12-13.dyn (3.4 KB)

Solved it: Using the doc.SendStringToExecute method.

Source: start lisp-Command immediately after sendstringtoexecute - Autodesk Community

# 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])
1 Like

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

2 Likes

I should have known… :pensive:
But thanks for the tip! :hugs:

1 Like

Great work in Python though! :muscle:

1 Like

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.ActionCallInstruction2.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.DynamicInstruction4.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