All of this was originally part of the main post for my Loop It macro and so it references things from that macro. However upon reflecting on it all for a bit I felt that all of the below kinda made the macro post a bit more heavy than it needed to be. And so I extracted the below (non grey) part and present it here as a "stand alone" thingie instead.
TL:DR
The gist of it all is that I found a way to get around one of the fundamental "issues" (or feature if you will.. it's certainly not a bug) with scripts in Fusion.
That issue is that scripts don't update. Which makes things problematic in a world where nodes are used, the names of those nodes can change in the blink of an eye, and some things are only possible to do to those nodes using scripts. Any name change to a node will break any script referring to that node since the name of the node won't be changed in any script. So the script will be referring to a node name that doesn't exist or it exists on the wrong node. This is unlike expressions where name changes to nodes are reflected.
The solution I found is a combination of Button scripts, ExecuteOnChange scripts, expressions and possibly custom settings (not necessarily required in all cases). That might sound like a lot, and glazing over the below chunk of text, it might give the impression that it also is a lot... but it's a fairly basic concept once one get through it all.
Pinky promise.
Anyhooo, on with the show:)
Hacks Creative use of game mechanics
I promised @SecondMan the low down on one of the hacks development choices I did in my Loop It macro and so allow me to present to you:
The Script Node Name hack dance.
The Setup
In the Seam Helpers section there’s a button called “Reset Lerps”. Seems to do nothing special. Click it and the settings above it resets to their default value. This is however pretty special (IMO) due to the following:
- To set a value by clicking a button, a script has to be used. Scripts in Fusion, unlike expressions, are "set in stone”. If a node is referred to by name in a script, and that name of the node changes, it won’t be reflected in the script. The script will still be using the old node name. For example if you make a copy of the macro, all the nodes in it (and the macro name) will be renamed by a number being added to the end of each name. Or if you just rename a node willy-nilly. Any expressions used will be updated with the new names, but no script will. And so you don’t usually want to refer to specific node names in scripts. Speaking of which...
- The controls that the button “resets” are on three different nodes. If all the controls had been on the same node as the button control then no node names would have been needed, the script could simply refer to each control as being on the “tool” (“tool" in scripts being, AFAIK the equivalent of “self” in expressions). But since Center and Pivot are on two different nodes (due to another
hackwork around) and Size, Angle and the Button being on a third node, well, that’s where things gets interesting.
The Rules
- There’s a way when using a script to find a named setting/control in a node (inside a macro/group) that was shared to me by fellow redditor, Fusion scripting wizard and Custom Poly modifier aficionado Glad-Parking3315. To my non coding eyes, the script seemed very technical. It basically searches through every node in a macro until it finds one that matches the name of the setting it looks for (if I understood it correctly). And that’s super cool. But I felt that maybe if I banged my head 50 times at random (Fusion) stuff I might come up with something my monkey brain could understand. And if it could, and if the alternative did the same as the script, then I’d go with what monkey gets. And so some head banging ensued.
- No modifiers. My macros don't do modifiers. That's a 98% true fact. I do have standards.
The Dance
Here’s what happens when clicking the button:
- The button (called "LerpReset") sets the value on the settings that are on the same node as itself (Size and Angle). Since they are on the same node (called "LI_ctrl") as the script itself, no node names are needed.
- The node that has the Center control has a checkbox. This checkbox has an expression that checks the button. It’s literally just
LI_ctrl.LerpReset(and since it’s an expression, if this name changes it’ll get updated here). Which seems like… nothing. And it is nothing. Well. Almost nothing. That "almost" being key here. - The checkbox also has an ExecuteOnChange script attached to it that triggers when anything happens to the control itself. Anything. So when the checkbox looks at the Button and it gets clicked… while in a sense nothing happens, to the ExecuteOnChange “function” something did happen. And so it fires away its script. And that script, being on the same node as the Center control, has no need for any node names to complete its task of resetting the value of the Center control.
- The same thing happens on the node that has the Pivot control. There’s a checkbox on that node with the exact same expression and the exact same ExecuteOnChange script.
All of the above results in the macro being able to be copied and have its node names change and still have the button work. Cool.
For ExecuteOnChange to trigger, the control that is being “changed” (and so triggering the execution) has to be physically visible in the inspector. For example, if instead of the button being the “triggering” device I used a slider/checkbox/whatever and that wasn’t visible, then the ExecuteOnChange doesn’t trigger. As in, if when I click the button it updates a slider and the ExecuteOnChange is looking at the slider… if the slider is on another tab or in a “hidden” nest (and so not visible) then nothing happens. If the slider is visible, then the ExecuteOnChange will trigger. And so having the ExecuteOnChange look at the button, and the button being clicked seen as a “change”, and the button needed to be visible to actually be clicked… well… that’s just perfect.
And there you go. That is, in my opinion, one of my finer Fusion hacks solutions. And if BMD is looking… it’s a feature, not a bug! No need to update anything<3
Other hack techniques used in the macro:
- The Center/Pivot Replacement
hackstrategy - The Widgets
hackexpedition
Honorable mention: The Keyframeable Speed on a TimeSpeed Node hack manoeuvre (the TimeSpeed node got replaced by a TimeStretcher node and so this hack is not part of the macro anymore)