Is there a way to get the count of nodes used on the canvas?
Yes. You can open the *.dyn file in a text editor and use “find” to count the number of “guid=” strings. I suggest notepad++
But could one do that with dynamo?
I think so - File.Read and some string nodes. You would have to manually path the location of the .DYN though.
Is this still the only way to count nodes in a given graph or is there a button somewhere in the newer versions?
It’s definitely possible but I’m not sure if Python can do it. Dynamo API should give access to this, I believe the Monocle package uses a lot of this to look at nodes and what’s going on generally in Dynamo itself.
There’s a full list of references on fuget, but couldn’t get a list of node names to work in Python. Might be worth reaching out to John (author of Monocle) for leads here:
Python
If you are in Dynamo for Revit, you can do it right in Python by referencing the DynamoRevitModel:
(Note: other Dynamo supported tools have access to this too, but I don’t work in those as often, so yeah)
Screenshot:
Python Script (CPython3)
# $ignore$ - this enables the node to ignore itself in the counts.
# Importing Reference Modules
# CLR ( Common Language Runtime Module )
import clr
# Adding the DynamoRevitDS.dll module to work with the Dynamo API
clr.AddReference('DynamoRevitDS')
import Dynamo
from collections import defaultdict
# access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
usedNodes = []
thisNode = []
for i in currentWorkspace.Nodes:
# if the node has ignore in the name, don't add to counts
if "ignore" not in i.Name:
if "Python" in i.GetType().ToString():
# if a python script has ignore in the heading, don't add to counts
if "$ignore$" in i.Script:
#don't add to the list because that is this node
thisNode = i
else:
usedNodes.append(i)
else:
usedNodes.append(i)
# grouped by node type
groups = defaultdict(list)
for node in usedNodes:
groups[node.GetType()].append(node)
groupedByType = groups.values()
# get the data
OUT = len(usedNodes), usedNodes, groupedByType
Dynamo Graph
dynamoAPIWithPython.dyn (13.4 KB)
Graph Node Manager (Dynamo 2.15+)
The latest version(s) of Dynamo Core (2.15) have the Graph node manager, which allows export to excel, where you can do more finite node counts.
Screenshot
Monocle
I will definitely consider adding this as a tool. I added this as a feature request here.