Force Run Python

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