## Add a Macro via script?

bryanfordney
Fusioneer
Posts: 67
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA
Been thanked: 1 time

### Add a Macro via script?

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

Midgardsormr
Fusionator
Posts: 1020
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 53 times
Contact:

### Re: Add a Macro via script?

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})

bryanfordney
Fusioneer
Posts: 67
Joined: Tue Jan 29, 2019 1:10 pm
Location: Atlanta, GA
Been thanked: 1 time

### Re: Add a Macro via script?

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?

AndrewHazelden
Fusionator
Posts: 1271
Joined: Fri Apr 03, 2015 3:20 pm
Location: West Dover, Nova Scotia, Canada
Been thanked: 29 times
Contact:

### Re: Add a Macro via script?

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: