How to execute a Dynamo graph inside a python script?

Hi! It’s my first post here!

I need to chain run a few different Dynamo graphs from a single python script or combine Dynamo graphs with Python code.

Something like this:


Since pyRevit allows running .dyn scripts from Ribbon I figured it is possible. I’ve tried reading pyRevit source and looking in Internet but without any luck.
Thanks for help!

@Andrzej ,

i recognized that running a dynamo script takes even more time when you have insteat a clean python code.

or follow this



So far I have come up with this:

import clr
from PyRevitLoader import ScriptExecutor
import pyrevit

py_executor = ScriptExecutor()
# this succedes

dyn_executor = ScriptExecutor()
# this does not



Currently I’m stuck with setting up dynamo engine for ScriptExecutor.

1 Like

in my opinion, that amount of daisy chaining will more often than not cause Revit to crap on itself and crash. also, the execution time is going to be slower - since there are more wrappers between the script execution and Revit.
I would advise combining the 2 dynamo scripts into1 and then executing through a pushbutton

1 Like

I have a partial solution:

import clr
from PyRevitLoader import ScriptExecutor
from pyrevit.runtime.types import DynamoBIMEngine, ScriptData, \
    ScriptRuntime, ScriptRuntimeConfigs

scriptdata = ScriptData()
scriptdata.ScriptPath = "d:\\test.dyn"
config = ScriptRuntimeConfigs()
runtime = ScriptRuntime(scriptdata, config)
engine = DynamoBIMEngine()

This will execute a graph. They can be chained. Still, it requires open Dynamo window to work, because otherwise it throws this:


So, I still need my way around EngineManager.

1 Like

We have a policy to go with Dynamo whenever it is possible. The reason is that there aren’t that many Pythoners available at hand to hire and I am the only one currently in my company. Dynamo is usally easier for newcomers.

I still need to programatically chain run Dynamo graphs as it will speed up things greatly.

you could be the first to post in the Jobs category :smile: @Andrzej

1 Like

Let’s just say that I don’t care about the overhead. Secondly Revit craps when code is poorly written.

That’s not a solution for me. Our Dynamo graphs are complex enough already and adding more makes them unmanagable and almost impossible to imporve later on. I have been into Dynamospaghetti world once and I’m not coming back.

1 Like

I will remember to do that.

you can start Dynamo before and see if that helps using this piece of code

from pyrevit import HOST_APP,UI
uiapp = HOST_APP.uiapp

RevitCommandId commandId = UI.RevitCommandId.LookupPostableCommandId(UI.PostableCommand.Dynamo)

1 Like

@Andrzej thank you for posting this, did you solve the issue. I am facing the same issue of running dynamo using pyrevit.