Welcome to WSL!

New to the forum? Please read this and this.

Run Lua code on opening comp

User avatar
eski
Fusioneer
Posts: 85
Joined: Tue Mar 07, 2017 1:39 pm

Run Lua code on opening comp

#1

Post by eski »

I'm making a Comp creator tool that, in simple terms.. scans the incoming footage and gives the user permission to create comps from that. I'm looking for a easy way to populate into the scripts Loaders for all the footage that is in the current shot folder.

Up to now I just had this very easy approach to replace "REPLACE_ME_LOADER_FILENAME", "REPLACE_ME_FIRST_FRAME.. etc strings here and there inside the default comp that I would change on creation but that gets tricky when there are multiple video files coming in.

So my question is, Is there anyway when opening a comp to have it inject code right at the start.
Was hoping for a way like "fusion.exe scriptpath/script.comp scriptpath/injectcode.txt" but that would be to easy right..

User avatar
Chad
Fusionator
Posts: 1615
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 7 times

Re: Run Lua code on opening comp

#2

Post by Chad »

I hesitate to answer... There used to be a function where a script placed in the same folder as the .comp with a certain naming convention would execute when the .comp opened. I would have to dig into what that was and see if it still works in the current version, but maybe someone else who has used this more recently can tell you faster.

User avatar
SecondMan
Site Admin
Posts: 4855
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 31
Location: Vancouver, Canada
Been thanked: 47 times
Contact:

Re: Run Lua code on opening comp

#3

Post by SecondMan »

Correct, from my archives:

Code: Select all

Fusion will run any script automatically which sits in the same folder as the (template) comp and has the same name.
So if you e.g. have TheTemplate.comp and TheTemplate.eyeonscript
living in the same location, the script will be executed each time you load the comp.
I have not tested this since March 2013... :)

User avatar
Cedric
Fusioneer
Posts: 59
Joined: Tue Sep 13, 2016 7:26 am
Answers: 1
Been thanked: 6 times

Re: Run Lua code on opening comp

#4

Post by Cedric »

Hi man

Does your tool need to be run from fusion itself? Because if it would be standalone/external to fusion, you would have the freedom to retrieve the Fusion instance, create a comp and run some code before saving/closing for example. You could then even switch to Python.

Here's a sample I'd use in Python
  1. import BlackmagicFusion
  2.  
  3.  
  4. def get_fusion():
  5.     fusion = BlackmagicFusion.scriptapp("Fusion")
  6.     if not fusion:
  7.         print("please open Fusion 8.0+ and try again")
  8.     return fusion
  9.  
  10.  
  11. def do_smth(comp, input_paths):
  12.     for path in input_paths:
  13.         ld = comp.AddTool("Loader")
  14.         ld.Clip[0] = path
  15.  
  16.  
  17. def main():
  18.     # get fusion instance
  19.     fusion = get_fusion()
  20.     if not fusion:
  21.         return
  22.    
  23.     # create comp
  24.     new_comp = fusion.NewComp()
  25.     new_comp.Lock()  # otherwise the create tool GUI (and other UI interactive windows) will pop up
  26.    
  27.     # run code
  28.     do_smth(comp=new_comp, input_paths=["/home/user/x.1001.exr", "/home/user/y.1001.exr"])
  29.    
  30.     # save comp somewhere and unlock
  31.     new_comp.Save("/home/user/dst_comp_path_v001.comp")
  32.     new_comp.Unlock()
  33.     new_comp.Close()  # optional if you want you can keep it open
  34.  
  35.  
  36. if __name__ == "__main__":
  37.     main()
PS: wrote this code on the spot, didn't test so if there's a syntax error or indent issue, my bad!

Cheers
Cedric

User avatar
eski
Fusioneer
Posts: 85
Joined: Tue Mar 07, 2017 1:39 pm

Re: Run Lua code on opening comp

#5

Post by eski »

SecondMan wrote:Correct, from my archives:

Code: Select all

Fusion will run any script automatically which sits in the same folder as the (template) comp and has the same name.
So if you e.g. have TheTemplate.comp and TheTemplate.eyeonscript
living in the same location, the script will be executed each time you load the comp.
I have not tested this since March 2013... :)

So this actually worked, but only if I changed the extension to .lua .. :)

Cheers guys!

User avatar
SecondMan
Site Admin
Posts: 4855
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 31
Location: Vancouver, Canada
Been thanked: 47 times
Contact:

Re: Run Lua code on opening comp

#6

Post by SecondMan »

Sweet! :)

User avatar
Chad
Fusionator
Posts: 1615
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 7 times

Re: Run Lua code on opening comp

#7

Post by Chad »

Neat!