Add a Macro via script?

User avatar
bryanfordney
Fusioneer
Posts: 64
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA

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: 1020
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 1
Location: Los Angeles, CA, USA
Been thanked: 52 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: 64
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA

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: 1264
Joined: Fri Apr 03, 2015 3:20 pm
Answers: 1
Location: West Dover, Nova Scotia, Canada
Been thanked: 29 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: