Get the name of a node

How can I get the name of a node used?

I want to get its name by string

out of curiosity what do you plan on doing with this bit of information? Have you tried anything?

1 Like

The name is stored in the dyn, so t he simple route would be to read the file as a txt and parse the data you want from there.

2 Likes

I do not want to write it manually as a string. My end goal is to export this data to excel.

This will do it for DynamoRevit:

import clr
# Adding the DynamoRevitDS.dll module to work with the Dynamo API
clr.AddReference('DynamoRevitDS')
import Dynamo 

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

nodeNames = []

for i in currentWorkspace.Nodes:
	nodeNames.append(i.Name)

OUT = nodeNames
11 Likes

Many thanks @john_pierson, I was looking for that and specifically get the name of nodes as input in the Python script, I mean get the name of the nodes feeded into the node script

1 Like

You’ll find your answer over on Dynamo API I’d say:

Edit: sorry only just noticed last reply was 8mth old but high in the threads for some reason. Bug, maybe…

3 Likes

Just out of curiosity, will it be possible to find out which nodes are throwing an error?

You can create a event to track element state of node in Dynamo.Graph.Nodes :

  • Dead,
  • Active,
  • Warning,
  • PersistentWarning,
  • Error,
  • AstBuildBroken,

Revit_f6gKcRoZHL

4 Likes

here another example

2 Likes

@chuongmep @c.poupin Thank you both! :slight_smile:

@c.poupin I try to make a txt file from the errors, any thoughts?

Check out the graph node manager, which is in 2.15. Info here: Dynamo Core 2.15 Release - Dynamo BIM

3 Likes

Thanks @jacob.small , we have a lot of player users.
What I want is to create a file when the script is finisht.

The reason I want this is because then I can offer better support.

But that is an other topic :wink:

you can always look at the implementation of the graph manager to see how it does it.

2 Likes

Thanks for the suggestion

try this

import clr
import sys
import System
from System import EventHandler, Uri
from System.Collections.Generic import List

clr.AddReference('DynamoCoreWpf') 
clr.AddReference('DynamoCore')
clr.AddReference('DynamoRevitDS')
clr.AddReference('DynamoServices')
import Dynamo 
from Dynamo.Graph.Workspaces import *
from Dynamo.Graph.Nodes import *
from Dynamo.Models import *

my_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)

		
def EventResumeNodes(sender, e):
	try:
		ResumeNodes()
	except Exception as ex:
		print('ERROR TRACEBACK' + str(ex))
	
def ResumeNodes(): 
	global dynamoRevit
	global currentWorkspace
	resume_file_path = my_path + "\\resume_nodes_error.txt"
	lstError = []
	for i in currentWorkspace.Nodes:
		if i.State == ElementState.Warning:
			lstError.append("###############################")
			lstError.append("Node : {}".format(i.Name))
			lstError.append("Error : {}".format(i.ToolTipText))
	with open(resume_file_path, 'w') as f:
		for line in lstError:
			f.write("{}\n".format(line))
	dynamoRevit.RevitDynamoModel.EvaluationCompleted -= EventHandler[EvaluationCompletedEventArgs](EventResumeNodes)

dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
dynamoRevit.RevitDynamoModel.EvaluationCompleted += EventHandler[EvaluationCompletedEventArgs](EventResumeNodes)
2 Likes

Can shorter :wink:

import clr
import sys
import System
from System import EventHandler, Uri
from System.Collections.Generic import List

clr.AddReference('DynamoCoreWpf') 
clr.AddReference('DynamoCore')
clr.AddReference('DynamoRevitDS')
clr.AddReference('DynamoServices')
import Dynamo 
from Dynamo.Graph.Workspaces import *
from Dynamo.Graph.Nodes import *
from Dynamo.Models import *

my_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)

		
def EventResumeNodes(sender, e):
	try:
		ResumeNodes()
	except Exception as ex:
		print('ERROR TRACEBACK' + str(ex))
	
def ResumeNodes(): 
	global dynamoRevit
	global currentWorkspace
	resume_file_path = my_path + "\\resume_nodes_error.txt"
	lstError = []
	for i in currentWorkspace.Nodes:
		if i.State == ElementState.Warning:
			lstError.append("###############################")
			lstError.append("Node : {}".format(i.Name))
			lstError.append("Error : {}".format(i.ToolTipText))
	with open(resume_file_path, 'w') as f:
		for line in lstError:
			f.write("{}\n".format(line))
	dynamoRevit.RevitDynamoModel.EvaluationCompleted -= EventResumeNodes

dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
dynamoRevit.RevitDynamoModel.EvaluationCompleted += EventResumeNodes

And solution for any one want create in zero touch node :sweat_smile: :

using Dynamo.Applications;
using Dynamo.Models;
using Dynamo.Graph.Workspaces;
using Dynamo.Graph.Nodes;
public static void GetWarningScript(bool flag =true)
    {
        if (flag)
        {
            DynamoRevit.RevitDynamoModel.EvaluationCompleted += EventResumeNodes;
        }
    }

    private static void EventResumeNodes(object sender, EvaluationCompletedEventArgs e)
    {
        var dynamoRevit = new Dynamo.Applications.DynamoRevit();
        WorkspaceModel currentWorkspace = DynamoRevit.RevitDynamoModel.CurrentWorkspace;
        string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
        string filepath = System.IO.Path.Combine(folderPath, "test.txt");
        if(!File.Exists(filepath)) File.Create(filepath).Close();
        foreach (var node in currentWorkspace.Nodes)
        {
            if (node.State == ElementState.Warning)
            {
                using (StreamWriter streamWriter = new StreamWriter(filepath,true))
                {
                    streamWriter.WriteLine(node.ToolTipText);
                    streamWriter.Close();
                }
            }
        }
        DynamoRevit.RevitDynamoModel.EvaluationCompleted -= EventResumeNodes;
    }
4 Likes