I am having a hard time finding an easy to way to grab error messages from dynamo in a copy/paste format. For example, I am running custom python nodes. How can I easily get the text of this output to paste into my AI assistant?
Thanks
Options offhand:
sys.exit(msg) where msg is the exception. This is nice as it makes the warning easy to see on canvas for you and future users. This is kinda like pulling the plug on your Python machine mid execution so you might have an issue or two in more advanced use cases, but you should be fine for Revit automation and such.Whatever MCP you’ve configured to work with your LLM has some major gaps, might be better to use something more directly integrated like the Autodesk Assistant in Dynamo 4.2 or 4.3 (or Revit 2027.3).
sys.stdout, sys.stderr and print appear in the console, unfortunately they are not saved to the log (%APPDATA%\Dynamo\Dynamo [Core|Revit]\<version>\Logs)
Alternate would be to use python logging module and save the log to file and point the agent to its location / directory
Good catch @Mike.Buttery - I forgot that the print fails to actually log.
I wouldn’t go to a separate Python logger though, as the agent won’t be able to read the larger context (i.e. if you have a namespace conflict on a proceeding node). One log to rule them all…or something like that.
These four lines of Python will append to the current Dynamo log just fine though, cribbed from some C# I wrote awhile back.
from Dynamo.Events import ExecutionEvents #import the execution events class into the Python environment
activeLog = ExecutionEvents.ActiveSession.GetParameterValue("Logger") #get the active log
activeLog.Log("Jacob Was Here") #write to the log - you likely want to pass something other than "Jacob was here" as the overload here
OUT = activeLog.LogPath #get the log path so you know where to look for information
Additional logging can be added to each node via view extension as well (pass any info state, warning, or error to the log; pass any null output, etc.).
In the latest versions of Dynamo, you can copy the message details; in your case, just do a raise exception
You can also retrieve this message via the API; here’s a sample implementation (not full code)
import clr
import sys
import System
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()
dynamoRevit = DYNAMOREVIT
engine = dynamoRevit.RevitDynamoModel.EngineController
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
currentWorkspaceNodes = currentWorkspace.Nodes
currentSelectionNodes = currentWorkspace.CurrentSelection
currentNode = next((node for node in currentSelectionNodes if hasattr(node, "Script") ), None)
#
if currentNode is not None :
current_node_name = currentNode.Name
current_code = currentNode.Script
current_py_engine = currentNode.EngineName
warnings_msg = ""
if "Warning" in currentNode.State.ToString():
for info in currentNode.NodeInfos:
warnings_msg += "\n" + info.Message
example with an AI agent