ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Script to add an effect to selected layers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Stuart Elith
Script to add an effect to selected layers
on Apr 8, 2009 at 1:45:14 am

Hi all,

In the general After Effects forum someone suggested that you can create hotkeys for applying effects by creating a script that applies the effect and then assigning that a hotkey. I think it's a great idea, so wanted to try it out.

I haven't done scripting for AE before but have a little bit of general knowledge so thought I might be able to piece it together, but haven't had much luck. Through amalgamating stuff from a few sites I came up with something like this, but it doesn't work...

var effectsGroup = app.project.activeItem.selectedLayers;
myEffect = effectsGroup.Effects.addProperty("ADBE Fast Blur");

I thought that by following the guide from redefinery I could combine the first 2 parts (check if a layer can have effects applied, then apply an effect), but that hasn't worked either.

http://www.redefinery.com/ae/fundamentals/effects/

Thanks for any guidance, I think this should be pretty straightforward but i'm a bit stuck :)

Cheers,
Stuart


Return to posts index

Dan Ebberts
Re: Script to add an effect to selected layers
on Apr 8, 2009 at 2:06:19 am

One problem I see is that selectedLayers is an array. If you only have one layer selected, you would access it this way:

selectedLayers[0]


Dan



Return to posts index

Stuart Elith
Re: Script to add an effect to selected layers
on Apr 9, 2009 at 2:11:15 am

Ahh thanks for that Dan, i probably wouldn't have picked it up!

Well I've got it working after more trial and error... i'm not sure exactly why this particular code works but it does, which is good enough for me!
It can only apply to one layer at a time but that's not a big bother for me either... I thought i worked out how to do it for more but it's not working and I don't care enough to spend a few hours getting annoyed while I work it out!

So for anyone else who's interested :



{
// create an undo group
app.beginUndoGroup("AddEffect");

var curItem = app.project.activeItem;
var selectedLayers = curItem.selectedLayers;


// check if comp is selected
if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert
alert("Please establish a comp as the active item and run the script again");

} else {

// define the layer in the loop we're currently looking at
var curLayer = curItem.selectedLayers[0];

// check if that layer is a footage layer
if (curLayer.matchName == "ADBE AV Layer"){

// add a slider and three keyframes
var slider = curLayer.Effects.addProperty("ADBE Fast Blur");

}
}

// close the undo group
app.endUndoGroup();
}



Most of this code is based upon someone else's from something, I'm sorry to say I don't remember where it was from, so i can't credit the person.


Return to posts index


Hamid Rohi-Bilverdy
Re: Script to add an effect to selected layers
on Jun 14, 2015 at 10:39:53 am

Hi

Sorry for jumping in here so late.
But curItem.selectedLayers[0]; is selected from array, what if you wanted the actual selected layers??

So if I wanted to apply an effect on several layers??


Return to posts index

David Wigforss
Re: Script to add an effect to selected layers
on Aug 30, 2018 at 5:33:47 pm

Since no one answered you....

You need to run thru a loop.


// define the layer in the loop we're currently looking at
for (i=0; i<selectedLayers.length; i++){
var curLayer = curItem.selectedLayers[i];

// add effect
var slider = curLayer.Effects.addProperty("ADBE Fast Blur");
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]