How to display the result of AST function in the custom NodeModel UI?

ui
dynamo

#1

Hi there,

Currently I am writing a customized UI using WPF. The binding part really confused me.
I understand that we can assign the “associativeNode” to the output port. just wondering is there a way to convert “associativeNode” to “IntNode”? The purpose is that instead of output the result from the port i want to display the computed result on the UI.

Thank you!


#2

see this repo:

I think the dataBridge callback examples will help.


#3

Thank you for your reply !! I have seen this repo before, probably miss the data bridge tag. Will take a look at it… =]


#4

let me be a bit less cryptic then ;).

The databridge project lets you register a function into the AST which will get called which might have a reference to the nodeModel - so you can do something like pass some value into the databridge function which you want to display on the UI and then have your dataBridge function save that value to the nodeModel. You may need to use the Engine.Mirror classes to get the runtime value of those AST nodes.

Then in your view you can bind to that value on the NodeModel.

see: https://github.com/DynamoDS/Dynamo/blob/dec6240ded0c4369617775336b9af60c2aba4103/src/Libraries/CoreNodeModels/ColorRange.cs#L129

this function goes and finds the value which is represented by an AST node at runtime but you must be careful as the result might not be what you expect.


#5

Hi Michael,

For now my code is like this.

  1. the type of “percentage” is AssociativeNode. Is it possible to convert it to “IntNode”?
  2. How can i extract the data from any associativeNode?

var viewPoint = AstFactory.BuildFunctionCall(
new Func<Dictionary<string, object>, string, object>(GeneralMethods.GetValuefromDict),
new List { functionCall, AstFactory.BuildStringNode(“Viewer Position”) });
var percentage = AstFactory.BuildFunctionCall(
new Func<Dictionary<string, object>, string, object>(GeneralMethods.GetValuefromDict),
new List { functionCall, AstFactory.BuildStringNode(“Coverage”) });

        return new[]
        {
            AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), viewPoint),
            AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), percentage),
        };