Understanding how Dynamo executes code


I’m trying to understand the bets way to execute Python code in Revit.

note that I’m writing all my code in Python, and so there is only one Dynamo node (a Python script one).

I’ve noticed that Dynamo will not run the code unless it has been changed in some way.

The problem I have is that if I change something in Revit and want to rerun the code to see what happens, I have to amend the code in some way otherwise Dynamo will not execute it.

Generally in these situations, I simply add a blank line and then everything executes as it should, but I’m finding it a pain having to do that.

Is there anyway to get Dynamo to execute code each time ‘Run’ is pressed?

1 Like

Unfortunately not out of the box. And as I understand this has been by design, although many have requested some sort of “Force Evaluation” functionality. (For instance for random generator nodes etc) The way many of the package makers have dealt with this is to feed the python node a boolean toggle and just not use it for anything in the script itself. However Dynamo will recognize when you have changed the boolean toggle and will therefore rerun the node. You can also try the “ForceChildrensEval” node from the Prorubim DS Common package as shown here: Help With Randomizing Placed Family Types? But I haven’t been able to get it to work with a python node… Maybe you’re in better luck! :wink:


OK, thanks, thats a shame, I’m getting repetitive strain injury!

Edit: The Boolean method works quite well - thanks for the tip!

1 Like

Just gave it a quick go and it runs fine:

Tho it will most likely not work if it’s inside a custom node.

1 Like

This doesn’t work for me, the only way I can get Dynamo to rerun the code is to put a boolean node in and click it from true to false or back again so that Dynamo sees something has changed, even though the node does nothing in the script. (I picked up this tip from somewhere).

As Jostein puts it, a ‘Force Evaluation’ function would be perfect.

See the example code below (Sorry I can’t post the file as for some reason this board sees me as a new user).

The code is a script to highlight something in the UI:

 # Dynamo
import clr
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.Revit.UI.Selection import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
selobject		= UnwrapElement(IN[0])	# Object to select

sellist = List[ElementId]()

selob = uidoc.Selection.SetElementIds(sellist)

#Assign your output to the OUT variable.
OUT = [selob]

This is how the graph looks:

You’ll see that on first run it will highlight the Selected model element in the UI, but after that it will not run again unless you change something (as the easiest way is to toggle the boolean node).