Force Run Python

Hello all,

@john_pierson shoes an example in the below post of a python node updating as things are changed. Do any of you know how he accomplished this?

I don’t know how he did it. :grin:

Here is the python code. *NOTE: it requires you python node to have the name *Force in it, and it only updates when a node is added or removed right now. Also, this will only work in Dynamo for Revit.

import clr
import datetime
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('DynamoRevitDS')
import Dynamo
#access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

#custom definition to mark the node as changed

def nodesAdded(obj):
    for i in currentWorkspace.Nodes:
        if i.NickName.StartsWith("*Force"):
            i.MarkNodeAsModified(True)
#the handlers for a node being added or removed
currentWorkspace.NodeAdded += nodesAdded
currentWorkspace.NodeRemoved += nodesAdded

#usind the current time for the output as an example
OUT = datetime.datetime.now()

I imagine you can take this further since it is demonstrating how to use the Dynamo API within the current workspace.

11 Likes

Thanks John,

This is perfect. We are trying to track Dynamo script usage in our office and want parts of the graph to rerun if changes were made. This is a great starting place.