Add a Macro via script?

User avatar
bryanfordney
Fusioneer
Posts: 88
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA
Been thanked: 5 times

Add a Macro via script?

#1

Post by bryanfordney » Wed Jul 10, 2019 11:36 am

Is it possible to instantiate a macro into a comp via lua scripting, in the same manner as comp:AddTool?

User avatar
Midgardsormr
Fusionator
Posts: 1211
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 4
Location: Los Angeles, CA, USA
Been thanked: 92 times
Contact:

Re: Add a Macro via script?

#2

Post by Midgardsormr » Wed Jul 10, 2019 11:40 am

I don't know if you can get one out of the Fusion registry like you can with an ordinary tool, but you can use the Actions system to get one, if you know the path to it:

comp:DoAction("AddSetting", {filename = path})

User avatar
bryanfordney
Fusioneer
Posts: 88
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA
Been thanked: 5 times

Re: Add a Macro via script?

#3

Post by bryanfordney » Wed Jul 10, 2019 11:42 am

Ah, thank you.

Now I'm wondering if I can store the contents of a macro in a string, and add it to the comp somehow via scripting, via that string?

User avatar
AndrewHazelden
Fusionator
Posts: 1382
Joined: Fri Apr 03, 2015 3:20 pm
Answers: 4
Location: West Dover, Nova Scotia, Canada
Been thanked: 57 times
Contact:

Re: Add a Macro via script?

#4

Post by AndrewHazelden » Wed Jul 10, 2019 12:04 pm

bryanfordney wrote:
Wed Jul 10, 2019 11:42 am
Ah, thank you.

Now I'm wondering if I can store the contents of a macro in a string, and add it to the comp somehow via scripting, via that string?
Fusion's comp:Paste() + bmd.readstring() functions will let you add a macro to a comp from a string. Paste expects you to have the macro data formatted as a Lua table.

The file reading equivalent to the readstring function is bmd.readfile().

Note: Don't forget to lock and then unlock your foreground composite when adding a macro node that contains Loader/Saver/FBX Mesh/ABC Mesh nodes via a scripted comp:Paste() workflow. When the foreground comp is locked, you will be able to suppress all of the file browser dialogs from appearing during a scripted task.

Check out these posts for a few tips:

User avatar
bryanfordney
Fusioneer
Posts: 88
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA
Been thanked: 5 times

Re: Add a Macro via script?

#5

Post by bryanfordney » Mon Aug 05, 2019 4:51 pm

Regarding adding a macro via the comp.DoAction method (thank you), do you have a suggested way of getting a handle to that tool after running the action?

User avatar
Midgardsormr
Fusionator
Posts: 1211
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 4
Location: Los Angeles, CA, USA
Been thanked: 92 times
Contact:

Re: Add a Macro via script?

#6

Post by Midgardsormr » Mon Aug 05, 2019 5:19 pm

The macro should be selected when it's added, so theoretically you could get it with mytool = comp.ActiveTool. I haven't tested that, though.

User avatar
SirEdric
Fusionator
Posts: 1956
Joined: Tue Aug 05, 2014 10:04 am
Answers: 3
Real name: Eric Westphal
Been thanked: 134 times
Contact:

Re: Add a Macro via script?

#7

Post by SirEdric » Mon Aug 05, 2019 9:34 pm

myTool = comp:DoAction("AddSetting", {filename = path}) should work as well...

User avatar
Midgardsormr
Fusionator
Posts: 1211
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 4
Location: Los Angeles, CA, USA
Been thanked: 92 times
Contact:

Re: Add a Macro via script?

#8

Post by Midgardsormr » Tue Aug 06, 2019 6:45 am

I believe that just returns a Boolean.

edit: Oh, nope. It returns an empty table for some reason.