Page 1 of 1

How to reference the input node in expression

PostPosted: Sun Jun 20, 2021 9:35 pm
by purplemagic
I'm making a macro whose behavior depends on whether the input node has a value set for a control, so I need to access the input node's control other than through the node name.

There is self:Input, but you can only access its properties such as width and height, not its controls.

How do you reference the input node that gives you read access to its controls if the input node's name is unknown?

Re: How to reference the input node in expression

PostPosted: Sun Jun 20, 2021 10:38 pm
by Bryan Ray
In a macro, you can still reference by a node's name. Fusion will auto-update expressions that are pointed to tools inside the macro to match the new names when you make a copy, the same as it does if you copy-paste tools that are expression-linked.

Just don't call your input node "Input." I learned the hard way that node names that match the input or output names of tools (and almost every node has an input called "Input") will break (thanks again, Pieter, for pointing out my mistake!) Fusion think's you're asking for properties of the node's own Input instead of properties of a node named "Input". I usually use the macro's name followed by "_in". So "MyMacro_in" and "MyMacro_effectMask", and so on.

Re: How to reference the input node in expression

PostPosted: Mon Jun 21, 2021 4:06 am
by purplemagic
Bryan Ray wrote:In a macro, you can still reference by a node's name. Fusion will auto-update expressions that are pointed to tools inside the macro to match the new names when you make a copy, the same as it does if you copy-paste tools that are expression-linked.

Sorry, I should have been clearer with my question.

The macro has one input and inside the macro, the node that defines or exports the input needs to look up the input node's controls.

The input node exists outside the macro, so you can't hardcode it inside the macro and if you do, it won't be automatically updated when you connect the input node to the macro in your composite.

Re: How to reference the input node in expression

PostPosted: Mon Jun 21, 2021 5:02 pm
by Bryan Ray
Hrm… I tried a few things, but I didn't come up with a solution. Maybe if you explained what this macro is supposed to do, I (or someone else) could offer more help, or a different approach.

My immediate concern is what if the user connects a tool that simply doesn't have the control you expect to find? The entire macro would fail, and it wouldn't be obvious why.

Re: How to reference the input node in expression

PostPosted: Tue Jun 22, 2021 3:35 am
by purplemagic
Bryan Ray wrote:My immediate concern is what if the user connects a tool that simply doesn't have the control you expect to find? The entire macro would fail, and it wouldn't be obvious why.

The user normally sets the values for the macro's custom controls, but if he doesn't and the input node is an instance of the same macro, then the macro will use the input node's custom controls to derive the values.

Re: How to reference the input node in expression

PostPosted: Tue Jun 22, 2021 5:30 am
by UserNoah
The only possibility that I could think of is using a button that the user has to press that executes a script that runs through the inputs and connects them to the previous nodes inputs.
But that's not really dynamic and there would need to be a separate button to disconnect these inputs. Although you could hide the original button once it ran and replace it with the disconnect button.

The benefit of this could be that if a user doesn't want to use the same controls for both macros chained together he could simply not chain them together.

But maybe it doesn't even need to do all of this. If a user wants to use the same values on both nodes he could simply create an instance.

Obviously I have no idea what exactly you're trying to achieve, so maybe this isn't an option.

Re: How to reference the input node in expression

PostPosted: Tue Jun 22, 2021 2:20 pm
by Bryan Ray
Knowing that you wanted to grab info from another macro makes the situation exponentially more complex; the experiments I was doing before wouldn't even have worked because a macro isn't usually just one tool. I'm fairly sure GetConnectedOutput():GetTool() would only have found the last node inside the macro, which probably doesn't have the controls you'd want to read. I'm not sure how to get a reference to the parent group, even with a full script. I'm sure there's a way, but I've never needed to do it.

Re: How to reference the input node in expression

PostPosted: Tue Jun 22, 2021 11:23 pm
by Andrew Hazelden
Hi purplemagic.

You might want to read through the following thread on WSL:

Entry level project: Developing an advanced Camera Crane Rig.
https://www.steakunderwater.com/wesuckl ... f=6&t=1821

You will see the build log of a new-to-macros-and-expressions user as they slowly create a custom multi-macro linked tool of their own.

Some of the challenges faced on this series of posts sound very similar to some of your own projects needs for realtime node interlinking and attribute probing on the fly.

Re: How to reference the input node in expression

PostPosted: Wed Jun 23, 2021 7:16 pm
by purplemagic
UserNoah wrote:The only possibility that I could think of is using a button that the user has to press that executes a script that runs through the inputs and connects them to the previous nodes inputs.

That would work too, but the use cases for my macro are limited so I decided to keep it simple.


Bryan Ray wrote:I'm fairly sure GetConnectedOutput():GetTool() would only have found the last node inside the macro, which probably doesn't have the controls you'd want to read.

You're right. So I ended up moving the controls to the last node of the macro as a workaround.


Andrew Hazelden wrote:Entry level project: Developing an advanced Camera Crane Rig.
https://www.steakunderwater.com/wesuckl ... f=6&t=1821

Thanks. I was able to get the input node with self:GetSourceTool().



Thank you all for your insight.