A handy little script to add a layer with inverted mask

Discussion regarding all scripting related questions
Please DO NOT post to this thread anything that is not directly related to scripting of Capture One.

A handy little script to add a layer with inverted mask

Postby Eric Nepean » Fri Aug 03, 2018 1:42 am

This Script copies adds a new layer, then copies the mask from the previous topmost adjustment layer to the new layer and inverts it. It handles without error the cases when no variant is selected, the selected variant has no adjustment layer, and the topmost layer is not an adjustment layer.

Code: Select all
tell application "Capture One 11" to tell (get primary variant)
   if (1 = (get count of it)) then
      if (0 < (get count of (get every layer whose kind is adjustment))) then
         set theFirstLayer to get last layer whose kind is adjustment
         set theSecondLayer to make new layer at end
         copy mask theFirstLayer to layer theSecondLayer
         invert mask of theSecondLayer
      else
         make new layer at end
      end if
   end if
end tell


Thanks to NN245802UL for the idea,
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 445
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: A handy little script to add a layer with inverted mask

Postby SeanMurp » Tue Aug 07, 2018 6:09 pm

Thanks for sharing Eric. That gets me thinking a bit on how our team uses their adjustment layers. Have you played with copying masks to different images? Is that easily done? We do that a lot but I haven't put much time into researching its scripting capabilities.

On a side note, we don't often need to invert a mask on a different layer but do interact with layers programmatically. Here is a basic one we use for making an adjustment (shadow recovery in this case) to all images...plus I did my own naming of the layers since I wanted them more descriptive and didn't like the layer numbering. :D

Code: Select all
tell application "Capture One 11"
   repeat with thisVariant in (get selected variants)
      set newLayerIndex to 1 + (count of every layer of thisVariant)
      set theNewLayer to make new layer of thisVariant with properties {name:"Shadow Recovery " & newLayerIndex}
      tell theNewLayer to fill mask
   end repeat
end tell
SeanMurp
 
Posts: 78
Joined: Wed Nov 02, 2016 4:30 am

Re: A handy little script to add a layer with inverted mask

Postby Eric Nepean » Wed Aug 08, 2018 5:29 am

SeanMurp wrote:Thanks for sharing Eric. That gets me thinking a bit on how our team uses their adjustment layers. Have you played with copying masks to different images? Is that easily done? We do that a lot but I haven't put much time into researching its scripting capabilities.

I haven't tried it but I note that when I execute the the Applescript:
get every layer of primary variant
I get the responses:
layer "Background" of variant 10 of collection 1 of collection 13 of document "Incoming"
layer 2 of variant 10 of collection 1 of collection 13 of document "Incoming"

Note that the reference to the layer also includes the variant, collection and document. Therefore this should work:
Code: Select all
tell application "Capture One 11"
set sourceLayer to layer 2 of Variant 1
set targetLayer to layer 3 of Variant 2
copy mask sourceLayer to layer targetLayer     
end tell

On a side note, we don't often need to invert a mask on a different layer but do interact with layers programmatically. Here is a basic one we use for making an adjustment (shadow recovery in this case) to all images...plus I did my own naming of the layers since I wanted them more descriptive and didn't like the layer numbering. :D

I would do the same.
Note that in the fill mask command, your target is only defined by "theNewLayer" - the layer reference must include all the information about document, collection and variant.
Code: Select all
tell application "Capture One 11"
   repeat with thisVariant in (get selected variants)
      set newLayerIndex to 1 + (count of every layer of thisVariant)
      set theNewLayer to make new layer of thisVariant with properties {name:"Shadow Recovery " & newLayerIndex}
      tell theNewLayer to fill mask
   end repeat
end tell


I'bve started structuring my code along these lines - this eliminates an unnecessary variable, and the line continuation character ¬ still breaks the code into readable chunks
Code: Select all
tell application "Capture One 11"
   repeat with thisVariant in (get selected variants)
      set theNewLayer to make new layer of thisVariant with properties¬
        {name:"Shadow Recovery " & (get 1 + (count of every layer of thisVariant))}
      tell theNewLayer to fill mask
   end repeat
end tell
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 445
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest