Add expression to Levels with script

What type of scripts do you need?

Moderator: byronnash

Post Reply
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I have a script that works great but I can't get the expression into the setvalue of the "GAMMA INVERSE" layer to work.
Hopefully someone here can help.

Code: Select all

{
   // This script will create two Adjustment layers in the activeComp.
   // The adjustment layer will have Levels effect and ...
   //
   //
   // note: This script is using matchName so that this script can work with localized build.
   //

   var activeItem = app.project.activeItem;
   if (activeItem == null || !(activeItem instanceof CompItem)){
       alert("Please establish a comp as the active item and run the script again");
   } else {

      // By bracketing the operations with begin/end undo group, we can
      // undo the whole script with one undo operation.
      app.beginUndoGroup("Gamma up and down");

      var activeComp = activeItem;

      var solidName = "GAMMA DOWN";
      var solidW = activeComp.width;
      var solidH = activeComp.height;
      var solidPixelAspectRatio = activeComp.pixelAspect;
      var solidDuration = activeComp.duration;

      var adjLayer = activeComp.layers.addSolid([1, 1, 1], solidName, solidW, solidH, solidPixelAspectRatio, solidDuration);

      // Apply Levels    
         var levels = adjLayer.Effects.addProperty("Levels (Individual Controls)");

      // Set Values
          levels.property(6).setValue(.5);
       
      adjLayer.adjustmentLayer = true;
      //adjLayer.guideLayer = true;
      adjLayer.moveToBeginning();

// Gamma Inverse
var solidName = "GAMMA INVERSE";
      var solidW = activeComp.width;
      var solidH = activeComp.height;
      var solidPixelAspectRatio = activeComp.pixelAspect;
      var solidDuration = activeComp.duration;

      var adjLayer = activeComp.layers.addSolid([1, 1, 1], solidName, solidW, solidH, solidPixelAspectRatio, solidDuration);

      // Apply Levels
         var levels = adjLayer.Effects.addProperty("Levels (Individual Controls)");

      // Set Values
         levels.property(6).setValue(thisComp.layer("GAMMA DOWN")("Effects")("Levels (Individual Controls)")("Gamma"));
       
      adjLayer.adjustmentLayer = true;
          adjLayer.moveToBeginning();
      app.endUndoGroup();
   }
} 
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

What are you trying to set the value to? You need to put the value in the SetValue parenthesis. Currently you have this:

Code: Select all

//Set Values
         levels.property(6).setValue(thisComp.layer("GAMMA DOWN")("Effects")("Levels (Individual Controls)")("Gamma"));

But it should be something like this:

Code: Select all

//Set Values
         levels.property(6).setValue(100);
-Lloyd
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I'm trying to add an expression to invert the gamma of another adjustment layer.

The expression -- when working and set manually -- is this:

1/thisComp.layer("GAMMA DOWN")("Effects")("Levels (Individual Controls)")("Gamma")

It takes the value of the "GAMMA DOWN" layer's gamma and gives the inverse to regain a gamma of 1.0.
Attachments
Screen shot 2011-04-05 at 12.52.03 PM.png
Screen shot 2011-04-05 at 12.52.03 PM.png (42.53 KiB) Viewed 12517 times
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Then just add it as an expression:

Code: Select all

//Set Values
         levels.property(6).expression='1/thisComp.layer("GAMMA DOWN")("Effects")("Levels (Individual Controls)")("Gamma")';
Otherwise you need to calculate the actual value and set that.

-Lloyd
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Yes!
That works!
It's the ".expression=" that I was missing.

Thanks Lloyd. You rock!
Post Reply