Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE script – applyPreset()

  • AE script – applyPreset()

    Posted by Steve Renshaw on October 8, 2009 at 1:07 pm

    Hi,

    I’m writing a script in AE CS4 and I want to apply a preset to a Null layer. I can do this successfully if I assign the preset to a variable, then apply it just after I create the Null layer:

    var controlLayer = myComp.layers.addNull();
    controlLayer.source.name = “Cam_Null_ST”;
    controlLayer.applyPreset(thePreset01);

    However, I need to apply the preset later in the script, and I can’t get it to work. I’m using the following code:

    var mySTLayer = myComp.layer(“Cam_Null_ST”);
    mySTLayer.moveToBeginning();
    mySTLayer.enabled = true;
    mySTLayer.applyPreset(thePreset01);

    I know that I’ve selected the layer correctly because it moves to the top of the stack and gets enabled. However, the preset gets applied either to the last new layer created earlier in the code, or, if no layers are selected, a new solid is created and the preset applied to that! I can’t understand why it doesn’t simply apply the preset to the “Cam_Null_ST” layer that it’s just moved to the top and enabled.

    Any help would be much appreciated.

    Thanks,
    Steve.

    Steve Renshaw replied 16 years, 10 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    October 8, 2009 at 5:45 pm

    That’s strange. Sometimes objects that you’ve stored in variables become invalid because of something else you’ve done, but that usually generates an error message. What happens if you change it to this?

    var mySTLayer = myComp.layer(“Cam_Null_ST”);
    mySTLayer.moveToBeginning();
    mySTLayer.enabled = true;
    mySTLayer = myComp.layer(“Cam_Null_ST”);
    mySTLayer.applyPreset(thePreset01);

    Dan

  • Steve Renshaw

    October 8, 2009 at 6:40 pm

    Hi Dan, thanks for the response. Unfortunately I get the same behaviour. I’ve also tried the following experiment:

    //Add and remove temp null to clear any existing selection

    var tempLayer = myComp.layers.addNull();
    tempLayer.moveToBeginning();
    tempLayer.remove();

    // Move Cam_Null_ST to top of layer stack

    var mySTLayer = myComp.layer(“Cam_Null_ST”);
    mySTLayer.moveToBeginning();
    mySTLayer.enabled = true;

    // Add preset to 1st layer in stack

    var firstLayer = myComp.layer(1);
    firstLayer.applyPreset(thePreset02);

    Again I get the same behaviour – rather than adding the preset to the existing first layer, a new layer solid is created and the preset applied to that. I’ve also tried applying different presets, in case there is something odd in the preset code, but it still creates a new layer.

    Steve.

  • Dan Ebberts

    October 8, 2009 at 9:22 pm

    I’m not sure what’s going on, but this seems to work for me:

    {
    var presetPath = “c:/Program Files/Adobe/Adobe After Effects CS4/Support Files/Presets/thePreset02.ffx”;
    var myComp = app.project.activeItem;
    var mySTLayer = myComp.layers.addNull();
    mySTLayer.moveToBeginning();
    mySTLayer.enabled = true;
    var myPreset = File(presetPath);
    mySTLayer.applyPreset(myPreset);
    }

    Dan

  • Steve Renshaw

    October 9, 2009 at 9:19 am

    Hi Dan,

    Your code works for me too. My problem is not adding the preset when I create the layer, but adding it later in the code. In the following test I’d expect the preset to be added to the layer called ‘Preset_here’, but instead it adds it to the last layer created (Test2).

    // Test script

    var myComp = app.project.activeItem;

    // Create layer that preset should be added to later
    var importantLayer = myComp.layers.addNull();
    importantLayer.startTime = 0;
    importantLayer.source.name = “Preset_here”;

    // Create a few other layers
    var testLayer = myComp.layers.addNull();
    testLayer.startTime = 0;
    testLayer.enabled = false;
    testLayer.source.name = “Test1”;

    var testLayer = myComp.layers.addNull();
    testLayer.startTime = 0;
    testLayer.enabled = false;
    testLayer.source.name = “Test2”;

    // Apply preset to 1st layer created (‘Preset_here’)
    {
    var presetPath = “c:/Program Files/Adobe/Adobe After Effects CS4/Support Files/Presets/SR/light_sweep1.ffx”;
    var myComp = app.project.activeItem;
    var importantLayer = myComp.layer(“Preset_here”);
    importantLayer.moveToBeginning();
    importantLayer.enabled = true;
    var myPreset = File(presetPath);
    importantLayer.applyPreset(myPreset);
    }

  • Dan Ebberts

    October 9, 2009 at 3:26 pm

    It appears that applyPreset() works on the currently selected layer(s). If you add this prior to applying the preset, it seems to work:

    for (var i = 1; i <= myComp.numLayers; i++){ myComp.layer(i).selected = false; } importantLayer.selected = true; Dan

  • Steve Renshaw

    October 9, 2009 at 6:25 pm

    Brilliant, thanks Dan. Not quite how I thought applyPreset() would work, but your code lets me achieve the desired results anyway.

    Thanks again,

    Steve.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy