Return Current Dynamo Workspace's Warnings

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