Return Current Dynamo Workspace's Warnings

Hello,

I was trying to reference this post’s solution and I want to add a little to it. I want to return all of the nodes as they do and then somehow access if the given node is returning a warning. I can then return this as an output to the user in some form later. Trying very hard to find documentation on the Dynamo API…but to no avail.

1 Like

Thats a great topic!

I look for Dynamo API stuff… i cant realy find. i would like do costumnodes…

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('DynamoRevitDS')
import Dynamo

# Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

nodeNames = [[],[]]

for i in currentWorkspace.Nodes:
	nodeNames[0].append(i.Name)
	
for j in currentWorkspace.Nodes:
	nodeNames[1].append(j.Warning)

OUT = nodeNames

Can you see also packageNames ?

KR

Andreas

1 Like

Hello
here an example

import clr
import sys
import System
from System.IO import Directory, File
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('DynamoCoreWpf') 
clr.AddReference('DynamoCore')
clr.AddReference('DynamoRevitDS')
import Dynamo 
from Dynamo.Applications.ViewModel import *
from Dynamo.Graph.Workspaces import *
from Dynamo.Models import *
from Dynamo.ViewModels import *
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

out = []
for i in currentWorkspace.Nodes:
	if "Warning" in i.State.ToString():
		out.append([i.Name, i.ToolTipText])
		
OUT = out
3 Likes

Hello,

Where is this resource of this information? or just powerfull mind? :slight_smile:
f.e. where are these libraries? is there a list?

KR

Andreas

Hi @Draxl_Andreas

this topic may be help you

2 Likes

You will really need to watch the order that things are executed, because you may want this python node to have every possible avenue of nodes connecting into it.

This will mean that it will not run until after everything else has been run.

Also the following may help you: DynamoVisualProgramming.Core 2.14.0.4641 - FuGet Gallery

3 Likes

I’m inclined to mark this as a solution as it returns Exactly what I need! However, it only works under certain circumstances. I think what is happening is that the entire program needs to run for it to return warnings. And so a lot of times the py script returns a null list even though there are warnings because (what I believe) the program has not yet entirely finished so there are no warnings to return. I have to make a small change to script (like adding a node for example) for the script to run completely again and it will show an output correctly.

Not sure if this all makes sense, but as of now cant get it to return warnings consistently. The ultimate goal being to see a watch node output of the warnings in the dynamo player. Even running in the player 2x in a row doesn’t return anything other than null

image

1 Like

I think the only solution will be to run the script via a different context (via RevitDynamoModel class) from an addin or a macro
some examples

1 Like

Thank you! You’ve given me a lot to work with.

@wsayle as @Brendan_Cassidy suggested, you’ll want to force your Python node to execute last. Given that Dynamo gets pretty smart about how to retain output from nodes that have already processed, but not changed, and the subsequent way it bundles up the nodes into a “action sequence” to be run through the Virtual Machine, you’ll need the ensure that the Python node comes last - every time.

Easiest way to do this is connect it into the last node in your graph’s chain of nodes - with a dummy input port.

If you want to work with this node in a live graph, not just with Dynamo Player, you’ll also need to force the Python node to re-execute :slight_smile: To do this, you can have a second dummy input of “DateTime.Now” that is an always-updating node, which then always puts new data into the Python node to force it to reexecute and get around the “Smarts” of delta-compute.

And as a final aside, we are looking into ways to get this information to you inside of Player right now :slight_smile: CC @LilliSmith @nate.peters @craig.long

2 Likes

@solamour thank you for the detailed response! I appreciate you going into some of that detail. Several dynamo users I have spoken to are looking forward to the added features.

I tried what you said and still getting the same issue unfortunately :frowning: The python script is at the end with the DateTime.Now input. However when I run the program again (no delta change) the date and time does not change within the editor. The player doesn’t change the py script update either when ran 2x in a row.

I’m using Revit 2022 and the dynamo version is the following. (could never get it to update for some odd reason)
image

The version shouldn’t matter here - as this workflow hasn’t changed… I wonder why yours isn’t working then :thinking:

Is the output of your DateTime.Now node changing when you run the graph?

What does your Python look like - identical to mine? Is it saying any syntax errors?

Code looks the same I believe!

*
import clr
import sys
import System
from System.IO import Directory, File
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('DynamoCoreWpf') 
clr.AddReference('DynamoCore')
clr.AddReference('DynamoRevitDS')
import Dynamo 
from Dynamo.Applications.ViewModel import *
from Dynamo.Graph.Workspaces import *
from Dynamo.Models import *
from Dynamo.ViewModels import *
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

dummyInput = IN[0]
forceRexecute = IN[1]

out = []
for i in currentWorkspace.Nodes:
	if "Warning" in i.State.ToString():
		out.append([i.Name, i.ToolTipText])
		
OUT = out
*

Run 1

It’s almost like it doesn’t trigger that delta-compute at all…

Run 2

Dynamo Player. A little different - but still no output without editing the script itself and running again.
Run 1
image

Run 2
image

Delta-compute is essentially when Dynamo chooses to run, or not run certain nodes depending on if they would return a different result :slight_smile:

My apologies, I was mistaken. DateTime.Now will update every time you run it, as it queries the system clock, in Periodic mode (Which is also why it will run in Player as the process is similar - essentially start graph from scratch), but not in Manual in Dynamo 2.14.

In order to force your Python node to update, you need to have something change coming into that node. If you try do this with by clicking “+” on the Python node, then running, then clicking “-” again does it work correctly? That is forcing a change in the node.

To force the datetime node to re-run you can use the following python code here (Force Run Python - Revit - Dynamo (dynamobim.com)).

Make sure you add this as a new python node!

If you rename any node(eg your original python node) with “*Force” without the quotes of course, it will force that node to be re-run everytime. Though i would always keep the inputs you currently have within it, so it is keeps your original python node running last.

2 Likes

A workaround, just for the fun :upside_down_face:
playing with Dynamo API Event (EvaluationCompleted)
get_Nodes_errors

Python code

import clr
import re
import time
import sys
import System
from System import EventHandler, Uri

clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *
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 *
	
# access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()


class FormInfo(Form):
	def __init__(self, dynamoRevit):
		self._dynamoRevit = dynamoRevit
		self._model = dynamoRevit.RevitDynamoModel
		self._currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
		self._currentWorkspaceNode = [x.Name for x in self._currentWorkspace.Nodes]
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._label1 = System.Windows.Forms.Label()
		self._buttonCancel = System.Windows.Forms.Button()
		self._richTextBox1 = System.Windows.Forms.RichTextBox()
		self.SuspendLayout()
		self._dynamoRevit.RevitDynamoModel.EvaluationCompleted += EventHandler[EvaluationCompletedEventArgs](self.EventResumeNodes)
		# 
		# label1
		self._label1.Location = System.Drawing.Point(30, 9)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(152, 25)
		self._label1.TabIndex = 0
		self._label1.Text = "List Errors"
		# 
		# buttonCancel
		self._buttonCancel.Location = System.Drawing.Point(150, 550)
		self._buttonCancel.Name = "buttonStop"
		self._buttonCancel.Size = System.Drawing.Size(156, 37)
		self._buttonCancel.TabIndex = 0
		self._buttonCancel.Text = "Quit"
		self._buttonCancel.UseVisualStyleBackColor = True
		self._buttonCancel.Click += self.ButtonCancelClick
		# 
		# richTextBox1
		self._richTextBox1.Location = System.Drawing.Point(30, 37)
		self._richTextBox1.Name = "richTextBox1"
		self._richTextBox1.Size = System.Drawing.Size(400, 500)
		self._richTextBox1.TabIndex = 1
		self._richTextBox1.Text = "NO ERRORS"
		# 
		# FormInfo
		# 
		self.ClientSize = System.Drawing.Size(480, 600)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._richTextBox1)
		self.Controls.Add(self._buttonCancel)
		self.Name = "FormInfo"
		self.Text = "FormInfo"
		self.ResumeLayout(False)
		
	def EventResumeNodes(self, sender, e):
		try:
			self.ResumeNodes()
		except Exception as ex:
			self._richTextBox1.Text = 'ERROR TRACEBACK' + str(ex)
		
	def ResumeNodes(self): 
		lstError = []
		if self.Controls.Count > 0 and all(not x.IsDisposed for x in self.Controls):
			for i in self._currentWorkspace.Nodes:
				if i.State == ElementState.Warning:
					lstError.append("###############################")
					lstError.append("Node : {}".format(i.Name))
					lstError.append("Error : {}".format(i.ToolTipText))
					lstError.append("###############################")
			self._richTextBox1.Text = "\n".join(lstError)

	def ButtonCancelClick(self, sender, e):
		self._model.EvaluationCompleted -= EventHandler[EvaluationCompletedEventArgs](self.EventResumeNodes)
		self.Close()
		self.Dispose()

objInfo = FormInfo(dynamoRevit)
objInfo.Show()
OUT = 0

scriptError_v3.dyn (17.6 KB)

1 Like


Still not working! :unamused:

In other news, I did do the api workaround with a macro that does return the errors. Wish I could get it within player. But I think from now on this thread can be more academic. I really appreciate all of the help! Very informative. :slightly_smiling_face:

2 Likes

Could you provide your script on where you have it up to and I might be able to sort something :slight_smile:

1 Like