Issues with effects and layer order ...

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
mfe
Posts: 3
Joined: July 29th, 2010, 3:04 am

Hi There,

I am working on a script to help me cut some corners in my workflow. Most of the part
went pretty smooth by taking a look at how other scripts are done but with some details
i ran into a couple of problems that i can´t solve on my own.

Heres an example of what the script does:
Button gets pressd: Create a new Adjustment Layer, add effects levels, curves and saturation to it. done

Sounds pretty easy and works fine for the most part.

Here are the problems i have:
1. My new Layer is always created on top of the composition. I want it to be above the layer that
was selected before pressing the button. If no layer is selected its ok for the new Layer to be on top.

2. I want to share this script with other people so i want to check if the selected effect is really
available on the machine where the script is runing before creating the layer. Right now if the effect is
missing the layer is created but its empty (of course).

3. For some Operations, like the mentioned example with the levels etc. I wan to make the effects panel
active after creating the layer so i can smoothly start tweeking the effects without manually chaning to the effects control panel.

If you have any questions or if my explanation is not clear please ask me !

Many questions I know, but I really hope someone can help me out! Would be great ! Thanks in advance!!


Markus
mfe
Posts: 3
Joined: July 29th, 2010, 3:04 am

Hi there,

I figured out a solution for the first part ...
In case anyone is interested, here´s my code:

-----------------------------------------------------
// Selected Composition
var comp = app.project.activeItem;
// Selected Layers
var slctd_layer = comp.selectedLayers;

// Create new Solid and set Adjustment Layer Flag
var new_adjustment = comp.layers.addSolid([1,1,1], "Adjustment Layer", comp.width,comp.height,comp.pixelAspect,comp.duration);
new_adjustment.adjustmentLayer = true;

// Check if at least one Layer is Selected
// if so move the new Layer on top of the selected one
if ( slctd_layer[0] != null){
//alert (slctd_layer[0].index);
new_adjustment.moveBefore(slctd_layer[0]);
}
-----------------------------------------------------

But I still can´t figure out how to activate the "Effects Control Panel". If someone knows what the internal
aftereffects name is that would help I guess.

And I still need a way to check if the used effects are available.
(One workaround I can think of is to let the script do its thing and at the end check if the effect
was applied or not and then delete the layer again ... but that looks not like a good way to me ...)

I still could need some help ....
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

It isn't possible for a script to activate the effect controls panel.

This additional code will try to add an effect to the layer, and will remove the layer if the effect wasn't installed:

Code: Select all

try {	
	var theEffect = new_adjustment.Effects.addProperty("Fast Blur");
} catch(e) {
	new_adjustment.remove();
}
mfe
Posts: 3
Joined: July 29th, 2010, 3:04 am

Thanks Paul!

Works like a charm! I didn't know about the try/ catch construct. Looks
pretty awesome to me.

I also have an update on the Layer Order Problem. My first solution doesn't take
the order of the selection into account. So if more than one layer is selected the
new layer was placed above the first one selected. I hate that kind of awkwardness
in software so i came up with a pretty nasty solution for that problem.

Code: Select all

// Position of the new Layer
// Check if at least one Layer is Selected
// if so move the new Layer on top of the selected one(s)

if ( slctd_layer[0] != null){
   							 
    // Search for the Layer with the lowest index
    i = 0; 	// Set Counter
    lowest_index = slctd_layer[i].index;	// Initilize the placeholder for the index of the lowest layer to the first layer in the array
    top_layer = slctd_layer[i];				// Set the Output to the layer of the placeholder								   								
   								
   // Go through the array of the selected layers
   while (i < slctd_layer.length){			
   									
        // If the placeholder is bigger than the current layer set the placeholder to the value of the current layer
        if (lowest_index > slctd_layer[i].index){
   	    lowest_index = slctd_layer[i].index;
   	    top_layer = slctd_layer[i];
   	}
   	i++;
	}
   // Move the new Layer on top of the layer with the lowest index
   new_solid.moveBefore(top_layer);
}

Again, thanks for yout help Paul!
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

(Answered this on the cow but am cc'ing it here for completeness)

Instead of using a try/catch you can use the canAddProperty() method:

To check if you can apply an effect use the PropertyGroup canAddProperty() method (page 148 of the CS3 scripting guide):

Code: Select all

app.project.item(index).layer(index).propertyGroupSpec.canAddProperty(name)
And there's no way to activate the effects panel through scripting but F3 brings it up quickly :-)

-Lloyd
Post Reply