Counter of Runs in Dynamo Script

Hi guys,

inside my Script I need a counter, that feeds the Data.Export.Excel Node with a Value, that is increased with the amount 1 every time the script run button is hit, so that the collected data is written in Excel in a new Line (startRow). I’m sure there is an easy python solution, but unfortunately Python ist chinese for me.
The script collects element parameters from similar elements in the model and in the according sceme in order to be able to map them if any changes are made in either of them.


You mean like this?
like an increment for each run? a countdown or up?

I don’t think you can store data (within the file itself) between opening and closing the graph. You would have to read and write to a different file. Since you’re already modifying the excel file, I’d start there. You can even read the contents of the sheet before writing to the file and just append the new information instead.

1 Like

So this will increment a specifically named number node every time the python node has not been run. These two conditions are as follows:

  1. If the python node has not ran yet (fresh graph open)
  2. The node is refreshed somehow. (perhaps a phony input)

(In the video below I demo this by using a select model element node to make the node want to run, this can be anything you want)

This workflow isn’t the most perfect, but it is one way to try to do it.

# this is a python script
# it does cool things
# normally people spam this area 
# with blatant advertisements for their companies.
# i chose not to do that.

#import standard python libraries
import clr

#reference loaded dynamo revit module
clr.AddReference('DynamoRevitDS')
import Dynamo 

#reference dynamo core to update node values
clr.AddReference('DynamoCore')
from Dynamo.Graph import UpdateValueParams

#access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
engine = dynamoRevit.RevitDynamoModel.EngineController
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
model = dynamoRevit.RevitDynamoModel

node = []

#find the specific node
for i in currentWorkspace.Nodes:
			if i.Name.Equals("COUNTER"):
				node.append(i)	
	
#get value to update	
value = node[0].GetValue(0,engine).Data + 1
params = UpdateValueParams("Value",value.ToString())

#perform update
OUT = node[0].UpdateValue(params),value

counter.dyn (5.8 KB)

10 Likes

I love the idea :+1: and the header too :heart:

3 Likes

Great reminder that I need to dig into the Dynamo Workspace and available API. Super cool.

3 Likes

Hi Andreas, great idea, but for me unfortunately this doesn’t work. It fills with one click all the1000 Lines with the same data.

Hi John,

thanks a lot - great! :+1: :+1: :+1:

1 Like