In light of the Coronavirus crisis, please help make sure nothing stands in the way of social distancing in the VFX industry.

This petition asks the MPAA to act accordingly:

Sign the petition on

Be safe, everyone.

Comp_SaveCopyAs Event; How to get the filename?

User avatar
Posts: 712
Joined: Thu Aug 07, 2014 1:30 pm
Answers: 1
Been thanked: 9 times

Comp_SaveCopyAs Event; How to get the filename?


Post by Kristof » Fri Feb 07, 2020 7:16 am

Experimenting with Events (thanks again, @AndrewHazelden for the examples shared) and I would like to do something to files saved using a
Comp_SaveCopyAs Event. But how to get the filename entered by the user?

User avatar
Site Admin
Posts: 4247
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 15
Location: Vancouver, Canada
Been thanked: 62 times

Re: Comp_SaveCopyAs Event; How to get the filename?


Post by SecondMan » Mon Feb 10, 2020 6:24 pm

Store it in a variable?

Possibly a bit of a dud answer, but I find it a little hard to be specific - when and where did the user enter the filename and what's the process?

Do you have an example that you can share?

User avatar
Posts: 712
Joined: Thu Aug 07, 2014 1:30 pm
Answers: 1
Been thanked: 9 times

Re: Comp_SaveCopyAs Event; How to get the filename?


Post by Kristof » Tue Feb 11, 2020 2:24 am

So this is what I have right now and includes an explanation of what I'm doing. I'm working on a series that's pure CG, dealing with a lot of episodes and shots. I tend to start with building a production specific master or base comp that has all the logic covered needed for the show. This comp is stored in a specific location and has a shot and episode agnostic name with a "_Template" prefix.
Different versions are being stored on the network and once a version is deemed as ready to be deployed, it will be duplicated as a MASTER comp. Giving you a series of files like this:

_Template_someShow_Comp_MASTER.comp  <--- identical to v012

That master comp will then automatically be picked up and used to create the first template for master shots of an episode (usually you're dealing with a third of an episode's total shot count). So naturally it will resided inside a show/episode/shot related folder and the name will reflect that too:

^--- a copy of the then current MASTER template comp, renamed and loaders / savers / render range taken care of.

Once approved, these will then be picked up by the rest of the crew and tweaked for linked shots. Episode done.

What I'm doing is storing the original template name, version info along with a timestamp and username inside the template comp itself--CustomData on a comp level using SetData.

As long as it is a versioned template comp file, it will update the custom data inside the comp and keep track of it. If it becomes a master template file (either literally a *_MASTER.comp file or an episode master template ), no update of that data will be triggered. All renders coming out of any comp will read that data and inject is as metadata inside the renders coming out of the comp, so you can know what version of a basecomp was the source of such a render. Why? Because sometimes you discover a mistake in your logic that was used to build the uber master comp and you need to track which shots need fixing. You can do that by pulling the metadata and by looking for the related keys and values.

So I need to trigger a function that takes care of that tracking each time a comp is saved, which comes in these flavors by default in Fusion: "Save", "Save Version", "Save As..." and "Save a Copy As..." If any of these actions happen, I want to make sure I'm keeping track of things. No exceptions. All but "Save a Copy As..." work fine using code similar to this (covering "Save" ), stored as a .fu file in the Config folder:
  1. {
  2.     Event {
  3.         -- Add a new event that intercepts the Action
  4.         -- Comp_Save needs to use the "Composition" target to track the currently open .comp document.
  5.         Action = "Comp_Save",
  6.         Targets = {
  7.             Composition = {
  8.                 Execute = [[
  10.                     comp = fusion.CurrentComp
  11.                     if comp:GetAttrs().COMPS_FileName ~= "" then
  12.                         local filename = comp:GetAttrs().COMPS_FileName
  13.                         local name = comp:GetAttrs().COMPS_Name
  14.                         local timestamp = "%Y-%m-%d %H:%M:%S" )
  15.                         local username = os.getenv( "USERNAME" )
  17.                         if string.match( name , "_Template" ) then
  18.                             if string.match( name , "v%d+"  ) then
  19.                                 print("Tracking version of template.")
  20.                                 comp:SetData( "Compositing.Template.Name" , name )
  21.                                 comp:SetData( "Compositing.Template.Timestamp" , timestamp )
  22.                                 comp:SetData( "Compositing.Template.User" , username )
  23.                             end
  24.                         end
  25.                     end
  27.                     -- Run the Action as the last step
  28.                     rets = self:Default( ctx , args )
  30.                 ]]
  31.             },
  32.         },
  33.     },
  34. }

I hope that explains it :)

Added in 5 minutes 38 seconds:
I realize I'm currently not doing anything with filename, but I have that in there, thinking I might also need to check the folders in order to know to track or not. Not necessary now, so I'll probably will take it out in the future.