Return-Path: Received: from mail-we0-f171.google.com ([74.125.82.171] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP-TLS id 4946769 for AE-List@media-motion.tv; Fri, 11 Jan 2013 01:33:45 +0100 Received: by mail-we0-f171.google.com with SMTP id u3so569987wey.2 for ; Thu, 10 Jan 2013 16:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:mime-version:content-type:subject:date:in-reply-to :to:references:message-id:x-mailer; bh=bmqm8JIcqQr7JcsTK/8AyD1rpPbXs3YIK0zy5YshMT8=; b=Y0f5M8x51mSjpqCw3/Jxo9Zc534dRggSkCPypQPOwcjz+efzc7IgiT5RXuYnz0j//V K3AdHwHmFnuikYDrng22LWOP+wJisaky6rXYyV+rzcK5D/wBHh9mE3IcDTmMbhSUC3VT nHzRysSCBkKFbnPZvcGpQOgJmzQDFqpnkHBpbdavhuBsZvggEhHFi8xxA6QkyppcHwgd gsKK7Ak7AZpHG4m2njTgLulOtMcdALJUzIlYW5HozKW3PeDVXJiRK01SgoxlHJwPZeLE 0yncZt/ozp1a2GxNVXJRmcRvmB23k0hsVI7gMzT3DpJfQVyK+av9umG4eSWdw0zNFbEG 7gUQ== X-Received: by 10.180.33.202 with SMTP id t10mr12517096wii.3.1357864730249; Thu, 10 Jan 2013 16:38:50 -0800 (PST) Return-Path: Received: from pault-macpro.home (host86-156-252-168.range86-156.btcentralplus.com. [86.156.252.168]) by mx.google.com with ESMTPS id s10sm4853780wiw.4.2013.01.10.16.38.49 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Jan 2013 16:38:49 -0800 (PST) From: Paul Tuersley Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-8--547076647 Subject: Re: [AE] Script Question Date: Fri, 11 Jan 2013 00:38:48 +0000 In-Reply-To: To: "After Effects Mail List" References: Message-Id: X-Mailer: Apple Mail (2.1084) --Apple-Mail-8--547076647 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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 =3D app.project.activeItem.selectedLayers[0]; var RED_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); alert("red is valid =3D " + isValid(RED_Slider)); // adding a new effect will invalidate the RED_Slider variable's = link to the effect property object. var GREEN_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); alert("after adding green slider, red is valid =3D " + = isValid(RED_Slider)); alert("green is valid =3D " + isValid(GREEN_Slider)); if (!isValid(RED_Slider)) { // grab the effect property again RED_Slider =3D = selectedLayer.Effects.property(GREEN_Slider.propertyIndex-1); } alert("now red is valid =3D " + isValid(RED_Slider)); alert("green is still valid =3D " + isValid(GREEN_Slider)); var red =3D RED_Slider(1).value; var green =3D 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. >=20 > Basically I want to add 2 sliders then get the value of those sliders. >=20 > var RED_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); > var red =3D RED_Slider(1).value; >=20 > var GREEN_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); > var green =3D GREEN_Slider(1).value; >=20 > 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. >=20 > So the code below will not work. >=20 > var RED_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); > var GREEN_Slider =3D selectedLayer.Effects.addProperty("Slider = Control"); >=20 > var red =3D RED_Slider(1).value; > var green =3D GREEN_Slider(1).value; >=20 >=20 > It's almost as if when I add the Green Slider, it forgets the Red = Slider. >=20 > Any ideas? >=20 > Cheers. >=20 > Phil >=20 >=20 >=20 >=20 >=20 > Phil Spitler | Creative Technologist | Bonfire Labs | t : = 415.394.8200 m : 415.571.3139 >=20 > Website | Facebook | LinkedIn >=20 --Apple-Mail-8--547076647 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii 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 =3D = app.project.activeItem.selectedLayers[0];

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

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

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

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

Paul

<= div>




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 =3D selectedLayer.Effects.addProperty("Slider = Control");
var red =3D = RED_Slider(1).value;

var = GREEN_Slider =3D selectedLayer.Effects.addProperty("Slider = Control");
var green =3D = 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 =3D = selectedLayer.Effects.addProperty("Slider = Control");
var GREEN_Slider =3D = selectedLayer.Effects.addProperty("Slider = Control");

var red =3D= RED_Slider(1).value;
var green =3D = 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 | 
<= /span>

= --Apple-Mail-8--547076647--