Page 1 of 1

Adding tools to a Merge3D Node via a script?

PostPosted: Tue Jan 21, 2020 7:41 pm
by James Kumorek
In a Lua script, how do I programatically add a new 3D tool I just instantiated to a Merge3D node? Ultimately, I want to create a whole bunch of nodes and after creating it, add it to a Merge3D node as an input. However, I on;y see how to add a tool to a Merge3D node if you know which input you want to attach it to -- not if you're calculating that input dynamically. There's a FindMainInput method where you can query inputs; I was hoping for something like a SetMainInput method that would set them...?

I want to do something like this:

mym = comp:AddTool("Merge3D")
cnt=1
for i=-5,5,1
do
myt = comp:AddTool("Text3D")
myt.StyledText = string.format("%10d", math.random()*10000000000)
mym.SetMainInput(cnt, myt) // <== this is what I don't know how to do...
cnt = cnt + 1
end

Any ideas on how to do this? Help would be much appreciated!

Re: Adding tools to a Merge3D Node via a script?

PostPosted: Tue Jan 21, 2020 11:16 pm
by Bryan Ray
You'd need to list the existing Inputs, then connect to the first one you find that doesn't already have an Output connected to it.

Code: Select all

for i, inp in ipairs(mym:GetInputList()) do      --Enumerate inputs
   if inp:GetAttrs().INPS_DataType == "DataType3D" then   --Only SceneInputs have this DataType

      if inp:GetConnectedOutput() == nil then   -- Not already connected
         inp:ConnectTo(myt.Output)
         break                  -- Stop when we find an input
      end

   end
end


Re: Adding tools to a Merge3D Node via a script?

PostPosted: Wed Jan 22, 2020 11:30 am
by James Kumorek
Perfect - this is awesome! Thank you.

May I trouble you with another question? My specific question is, when I create my Text3D object, I also want to now change the translation value so that each appears in it's own area in 3D space. I can't find anything that explains how to set this property, and I'm not having any luck guessing. So, if I have:

myt = comp:AddTool("Text3D")

what's the syntax for setting the X Offset of the Translation section of the node?

Any more generically, how do I figure this out for any aspect of a node? I've googled and looked through the Scripting reference PDF, and I'm at a complete loss. I'm assuming I'm missing something pretty obvious. Any pointers to resources that explains some of this would be greatly appreciated!

Thanks for taking the time to help.

Re: Adding tools to a Merge3D Node via a script?

PostPosted: Wed Jan 22, 2020 12:02 pm
by James Kumorek
Hey, I actually found a script example that had the basic answer: I need to reference the myt.Transform3DOp.Translate.X to set that attribute.

But, the wider question still stands -- how do you find this out from within Fusion itself or their documentation? I've searched both the tool reference and the scripting reference for Transform3DOp, and it's never mentioned. :(

Re: Adding tools to a Merge3D Node via a script?

PostPosted: Wed Jan 22, 2020 4:37 pm
by Bryan Ray
For any Input, you can just mouseover it in the UI, and the ID will be displayed in the status bar in the lower left corner of the window. Another way is to add a simple expression to the parameter and then click the + button, which will load that Input's name into the expression.

If you want to query a tool for all its inputs (including some that may not be visible in the UI), I like this snippet:

Code: Select all
for i, inp in ipairs(tool:GetInputList()) do print(i..": "..inp:GetAttrs().INPS_ID) end


If you haven't discovered it yet, you'll want to grab the UI Manager Examples collection from Reactor and check out the FusionScript Help Browser, which is an excellent way to discover properties and methods for everything in Fusion's registry.