Dynamo custom node with internal parameter

Hi There,
Can an internal parameter be added to every ZeroTouchNode?
I need to store a value in every node, which will be gathered in a second step to extract some metrics from the graph.
Thanks

I would expect yes, as I have seen Grasshopper do it with the Telemetry package. My best guess is it would need to be built into the package dll and stored in Dynamo temporarily as data it can reference using its own API, complex if possible.

The lazy way is to force a short wait in your package (see the Delay node in Crumple as a basic example), then write that data out to a text format for reading at a predictable location. I’ve used this method before, and usually a 1 second gate is sufficient as txt writing in Python and beyond is almost instant.

Why not push to a log?

What about storing the value as a tag?
Are the tags accessible for a Zero Touch Node?

In grasshopper is easier, every node is a class, so every class inheritance from an abstract with a public string code {get; set;}. Problem solved.

just use a static property or property (like you showed) on your zero touch class?
Or you want to do this to EVERY node? Not just your own?

2 Likes

I would like to have the property only for my nodes.

Let’s say this is my class, with two methods that will come nodes; if I add the property as shown, how can I get that parameter looking into the node?

    public static class MyClass
    {
        [IsVisibleInDynamoLibrary(false)]
        public static string Code { get; set; }

        public static IDictionary ExtractOne(string query, string[] choices)
        {
            Code = "Extract";
            Do Something

        }

        public static IDictionary ExtractTop(string query, string[] choices, int limit = 3)
        {
            Code = "Extract";
            Do Something
        }
    }

I don’t understand what this means, get that property from where?
If you want each node to store a different value - don’t use a static property, just use a property like you had shown.

What context are you trying to get these values from - your second step? What is it?

  • from another node?
  • from a Extension or View Extension?
  • by inspecting the dynamo .json?
    What is your plan?

The plan is:
From a View Extension I capture when a workspace is closed, I search the nodes in the workspace that came from the custom library, and I want to extract the value stored in the property code that will be different for each of them.
The property is not an input and is not an output, is an internal parament.

ah, so thinking about this a bit more there is some complication when using zero touch nodes.

A ZT node is not a class instance, it’s just a function. If the class ends up being instantiated or not really depends on if you return them into the graph as outputs, and that doesn’t really map to the node very well - so I don’t think it’s a great approach.

Like you asked, I don’t think theres really anywhere to get access to the instance, because it may not necessarily have been created.

so a couple more ideas:

  • use a nodeModel node - these are harder to write - but theres some benefits - you can access the nodeModel instance easily from an extension - but even better - public properties of the NodeModel will get serialized automatically into the .dyn file - so you might be able to just avoid using an extension at all - by just reading the saved .dyn json.
  • use a static map in your zero touch node Dictionary<string,string> and then you can easily access it from the extension - the problem with this approach and the suggested log one, is what happens if your ZT node is replicated, embedded in a custom node etc. It’s not clear to me what the key would be though - from the ZT code there is no associated ID etc. I guess you could just use a list and keep adding data to it. It depends what the data is, if you need to know which node it’s attached to etc - and if you can guarantee that each node execution maps to one node. (hard to do)
  • Figure out how to extract all the logic you need outside of the node logic and put it all in the extension, store the data there instead.

Hope those are helpful.

2 Likes

Thanks, @Michael_Kirschner2.
The library is a combination of ZT and implicit nodes; once for the second one is easy to add, as you suggested for the first one; the solution I was considering is pretty much what you indicated on the second point.
I will have a static class with a Dictionary<string, string> that will map the nodes by NodeName`, the extension will extract the name from the node, and use it to extract the value stored in the static class.
Thanks for the help!