Mailing List AE-List@media-motion.tv ? Message #47335
From: Paul Tuersley <paul.tuersley@gmail.com>
Subject: Re: [AE] Script Question
Date: Fri, 11 Jan 2013 00:38:48 +0000
To: After Effects Mail List <AE-List@media-motion.tv>
I think this is because adding the second effect is invalidating the first variable's link to the effect object. This happens with various objects when adding things through scripting. In this case it wouldn't happen if you were adding effects to different layers, just when adding them to the same layer.

As you found, if you can do everything you need to do before adding another property that will avoid the problem. But if you need to keep accessing those variables you'll need to relink the previous variables afterwards.

Here's some example code that uses the very useful isValid() method to check if an object is still valid. Not really necessary in this case as this is predictable behaviour (once you're aware of the issue) but useful for scripts when the user may be interacting with layers, effects, etc while running a script.

var selectedLayer = app.project.activeItem.selectedLayers[0];

var RED_Slider = selectedLayer.Effects.addProperty("Slider Control");
alert("red is valid = " + isValid(RED_Slider));

// adding a new effect will invalidate the RED_Slider variable's link to the effect property object.
var GREEN_Slider = selectedLayer.Effects.addProperty("Slider Control");
alert("after adding green slider, red is valid = " + isValid(RED_Slider));
alert("green is valid = " + isValid(GREEN_Slider));

if (!isValid(RED_Slider)) {
// grab the effect property again
RED_Slider = selectedLayer.Effects.property(GREEN_Slider.propertyIndex-1);
}
alert("now red is valid = " + isValid(RED_Slider));
alert("green is still valid = " + isValid(GREEN_Slider));

var red = RED_Slider(1).value;
var green = GREEN_Slider(1).value;

Paul






On 10 Jan 2013, at 07:02, Phil Spitler wrote:

I'm having a fun time figuring out a scripting problem and thought I would ask the advice of the script gurus on the list.

Basically I want to add 2 sliders then get the value of those sliders.

var RED_Slider = selectedLayer.Effects.addProperty("Slider Control");
var red = RED_Slider(1).value;

var GREEN_Slider = selectedLayer.Effects.addProperty("Slider Control");
var green = GREEN_Slider(1).value;

If I run the code above, it works great however if I change the order and assign the sliders first then try to get the value, AE gives me an "invalid object" error.

So the code below will not work.

var RED_Slider = selectedLayer.Effects.addProperty("Slider Control");
var GREEN_Slider = selectedLayer.Effects.addProperty("Slider Control");

var red = RED_Slider(1).value;
var green = GREEN_Slider(1).value;


It's almost as if when I add the Green Slider, it forgets the Red Slider.

Any ideas?

Cheers.

Phil





Phil Spitler  |  Creative Technologist   |  Bonfire Labs  |  t : 415.394.8200  m : 415.571.3139

Website | Facebook | LinkedIn


 
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to ListMaster