Log to Dynamo console

Hey guys,

I was wondering if logging to the Dynamo console is possible, and if so, how to implement it. Does anyone have an example?

Judging from this post: Print to console it does not seem possible, but then again this thread is already some years old.

Thanks!
Michael

Hi, Michael,

Have a look here:

4 Likes

Hi Dimitar,

Thanks for pointing me to that post. I missed it. Though I am not yet able to successfully implement it.

Apparantly I am missing the namespace IExtension. Is this something I should reference?

And do I just create an instance of this class and write a string to the Log method?

Thanks!

I can’t exactly tell where the IExtension interface is being inherited from, but you may want to take a look at this example on Github (possibly the Dynamo.Extensions or Dynamo.Interfaces namespace?) which add references to many other libraries which may contain the specific interface you’re looking for.

In C# there is an Autodesk.AutoCAD.Runtime.IExtensionApplication. I assume it is the same in Python because you use the same API.

You’ll only need IExtension if you’re developing an extension for Dynamo
https://dynamods.github.io/DynamoAPI/Dynamo_Extensions/IExtension/

https://developer.dynamobim.org/

So i’m still not having much luck. I added the ExecutionExtension class to my program, removed the ‘IExtension’ reference as I don’t think I need it, made both Log methods ‘public’ so they can be written to from another class and the call them:

ExecutionExtension test = new ExecutionExtension();
test.MessageLogged += test.Log;
test.Log(LogMessage.Info("testmessage"));

But this results in an Stackoverflow exception:

System.StackOverflowException: ‘Exception of type ‘System.StackOverflowException’ was thrown.’

I’m probably calling this in a wrong way. Any ideas on how to do it properly?

Thanks again!

edit: I see for example here that first the message should be created and then the Log method should be called, but when I do that, the MessageLogged is null…

Sorry, Michael, I think I misled you. It seems Dynamo only checks for ILogSource classes when loading extensions and it doesn’t pick up any implementations in ZT assemblies.

As an alternative, you could try to implement a NodeModel assembly and see if that gives you access to the console log.

Hi Dimitar,

Tried this code in a NodeModel solution, but no luck. Exactly the same errors.

I guess there is no way of implementing this right now.

Thanks again! Michael