From: "Chris Zwar" Received: from mail-pg0-f54.google.com ([74.125.83.54] verified) by media-motion.tv (CommuniGate Pro SMTP 6.1.0) with ESMTPS id 6445276 for AE-List@media-motion.tv; Fri, 04 May 2018 09:18:00 +0200 Received: by mail-pg0-f54.google.com with SMTP id z4-v6so14870376pgu.13 for ; Fri, 04 May 2018 00:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chriszwar-com.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=XpkpjbgoiJnMmjlF18n2scGWdLEMVNA+edu1xSecWws=; b=q5WU11Kqt9YsJifz9fmcBokyRNtS7kXlGFt4bBIxBqnTPd2WMs0r0X3T6AAqJLC8fg +ympF2329O3vp+mCA8RAxBC7xJ0mf/LvSGPOztSudTLBE4BvFaARXePGK9hoveCMs1s8 sXtnA2Lp2vKBqN3pAYqbFgkb4iZa2yQoK0KWQch9Qa/ix5jGzaQtATdcS3MrUmtUvm/Z shjhwbMRv2EjEEe0veADk1kmUNT4UZisECQdJ2uLkdkrUceJ0TBNMraLuon9xgSo071l AnVHQbCXG5fkO5JS1d6m1rAVCh8IxHlCFKVzslCRAlomySAYn3bbZPUjFs7TfpOPwIzj SSsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=XpkpjbgoiJnMmjlF18n2scGWdLEMVNA+edu1xSecWws=; b=bcvatf61IPbWYIjvjcRlyU48q1ZfNP8Xg3d0y2NLBbY8kLFnGpol0WLiZGvDnYmKeW /Z8JRad7avVs81hMzQk9l8mHq4l/U6S1aVPN18O+rNEQYqS2UBrsTi+GwVxDKwLm1Msh 65QsqYjsj4VeSDtLDfDLCdrs0B1C4BZuzOo3a8WjtRsY++Z44rLuG5tA6QV13/egliT1 YV7ey+WVgLpbyiu5odWvmDsATyEsbdihe1NHlsg8viiv/PDJb/YsIIMfeO2Rvy7bUnuU WL8iTPvrqtIN1ofTDz2+i+U1goVPw8xlfsV+7WX/XQZFbFROwwM4SvnFJADWjF+6nrIj yKyQ== X-Gm-Message-State: ALQs6tA+cQkZIqZVurxKh6FGaGRqO08jhtVr1w+xfK3lwLLBwjW916Dz ATJkZlz51u0moflxKoFD523b96WXU/s= X-Google-Smtp-Source: AB8JxZrT83EjADSjjjm0vkF6oosvYspMo2InH97f/inZZg/JmX/80EPqjcke7aR6xhUqdGPt0jnpFg== X-Received: by 2002:a17:902:4203:: with SMTP id g3-v6mr25878056pld.315.1525418645686; Fri, 04 May 2018 00:24:05 -0700 (PDT) Return-Path: Received: from [192.168.3.137] (220-244-139-34.static.tpgi.com.au. [220.244.139.34]) by smtp.gmail.com with ESMTPSA id t69sm10097159pfi.177.2018.05.04.00.24.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 May 2018 00:24:05 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_98A3E1AC-B40D-451D-B401-F8ECDD8F0525" Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: [AE] scripting help - getting colour value Date: Fri, 4 May 2018 17:24:01 +1000 References: To: After Effects Mail List In-Reply-To: Message-Id: <0F40BE84-C286-4C66-83F5-96DE2C3CA65A@chriszwar.com> X-Mailer: Apple Mail (2.3445.6.18) --Apple-Mail=_98A3E1AC-B40D-451D-B401-F8ECDD8F0525 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thanks for that, it=E2=80=99s a great help. I wasn=E2=80=99t aware of = the sleep function but it=E2=80=99s got it working most of the time. It = gives me something to look at, although I=E2=80=99m still getting = erratic results with the full script. But erratic results are better = than no results at all, so at least I feel like I=E2=80=99m making = progress! > On 4 May 2018, at 2:13 pm, Zack Lovatt = wrote: >=20 > Ah! Got it. The issue is that AE isn't updating fast enough between = the time you add the expression and when you sample the property value. = I found that by forcing the script to wait for a little bit (150ms = seemed to be the sweet spot in my testing) it would catch it 100% of the = time. >=20 > Here's a revised onClick. Also cleans up some of the redundant logic = (and you never declared 'g' or 'b', so they were global..) >=20 > apply.onClick =3D function() { > clearOutput(); > var myComp =3D app.project.activeItem; > var myLayer =3D myComp.selectedLayers[0]; >=20 > app.beginUndoGroup("Extrapolated Zeugma"); >=20 > myLayer.property("ADBE Effect Parade").addProperty("ADBE Fill"); > myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Link"); > myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Control"); >=20 > var colorControl =3D myLayer.property("ADBE Effect = Parade").property("ADBE Color Control").property("ADBE Color = Control-0001"); > colorControl.expression =3D colourExpression; >=20 > $.sleep(150); >=20 > var controlValue =3D colorControl.value; >=20 > var r =3D controlValue[0]; > var g =3D controlValue[1]; > var b =3D controlValue[2]; >=20 > alert("RGB: " + r + "," + g + "," + b); >=20 > app.endUndoGroup(); > }; >=20 > Zack Lovatt > 424.442.0020 > www.zacklovatt.com > On Thu, May 3, 2018 at 8:13 PM, Chris Zwar > wrote: > Thanks for your interest. Yes your script works fine, and it=E2=80=99s = prompted me to play around a bit more. My full script is a few hundred = lines and I won=E2=80=99t post it all, but I have stripped it down to = the basics and I=E2=80=99ve found where the problem comes from. > In my full script I am applying the Color Link effect and sampling the = colour after it is applied. It=E2=80=99s this effect which is not = working in CC 2017 or CC 2018. As an experiment, I tried applying the = basic fill effect instead, and when I do that the script does work as = expected. >=20 > I=E2=80=99ve pasted a version of the script below. If you leave it = as-is. the color link effect is applied and the sampleImage only returns = 0. If you comment out the color link effect to prevent it being added, = then only the fill effect is applied. Then the sampleImage correctly = returns the values of 1,0,0. >=20 > I would love to know if you can replicate this behaviour - thanks = again. >=20 > -Chris >=20 > { > function ZaksTest(thisObj) { =20 > var ZaksTestData =3D new Object (); > ZaksTestData.strApply=3D"Apply"; > var colourExpression=3D"x=3DthisLayer.width/2;y=3DthisLayer.height/2;\n = c=3DsampleImage([x,y], radius =3D [2, 2], postEffect =3D true, t =3D = time);\n c"; > // Set up the GUI =20 > function ZaksTest_buildUI(thisObj) { > var myPanel =3D (thisObj instanceof Panel) ? thisObj : new = Window ("palette","ZaksTest",undefined, {resizable:true}); > var res =3D=20 > "group { \ > orientation:'column', = alignment:['fill','top'], \ > apply: Group { \ > alignment:['right','top'], \ > applyBtn: Button { text:'" + = ZaksTestData.strApply + "' }, \ > }, \ > }"; =20 > myPanel.grp =3D myPanel.add(res) > var apply=3DmyPanel.grp.apply.applyBtn; > // Apply button - main part =20 > apply.onClick=3Dfunction()=20 > { > var myComp =3D app.project.activeItem; > app.beginUndoGroup("ZaksTest"); > clearOutput(); > var myLayer =3D myComp.selectedLayers[0]; > myLayer.property("ADBE Effect Parade").addProperty("ADBE Fill"); > // comment out the color link effect and the script works. If it's = enabled it doesn't // > myLayer.property("ADBE Effect Parade").addProperty("ADBE Color Link"); > myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Control"); > myLayer.property("ADBE Effect Parade").property("ADBE Color = Control").property("ADBE Color = Control-0001").expression=3DcolourExpression; > var RGB=3D[1,1,1,1]; > var r=3D0;g=3D0;b=3D0; > RGB=3DmyLayer.property("ADBE Effect Parade").property("ADBE Color = Control")(1).value; > r=3DRGB[0]; > g=3DRGB[1]; > b=3DRGB[2]; > alert("RGB: "+r+","+g+","+b); > app.endUndoGroup(); > } > // Set panel resizing > myPanel.layout.layout (true); > myPanel.grp.minimumSize=3DmyPanel.grp.size; > myPanel.layout.resize(); > myPanel.onResizing =3D myPanel.onResize=3D function () = {this.layout.resize()} > return myPanel; > } > var ZaksTestPal =3D ZaksTest_buildUI(thisObj); =20 > if ((ZaksTestPal !=3D null) && (ZaksTestPal instanceof = Window)) > { > ZaksTestPal.center(); > ZaksTestPal.show(); > } > } > ZaksTest(this) ; > } > +---End of message---+ > To unsubscribe send any message to > >=20 --Apple-Mail=_98A3E1AC-B40D-451D-B401-F8ECDD8F0525 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thanks for that, it=E2=80=99s a great help.  I wasn=E2=80=99= t aware of the sleep function but it=E2=80=99s got it working most of = the time.  It gives me something to look at, although I=E2=80=99m = still getting erratic results with the full script.  But erratic = results are better than no results at all, so at least I feel like I=E2=80= =99m making progress!

On 4 May 2018, at 2:13 pm, Zack = Lovatt <AE-List@media-motion.tv> wrote:

Ah! Got it. The issue is that AE isn't updating fast enough = between the time you add the expression and when you sample the property = value. I found that by forcing the script to wait for a little bit = (150ms seemed to be the sweet spot in my testing) it would catch it 100% = of the time.

Here's = a revised onClick. Also cleans up some of the redundant logic (and you = never declared 'g' or 'b', so they were global..)
apply.onClick =3D function() {
  = clearOutput();
  var myComp =3D = app.project.activeItem;
  var myLayer =3D = myComp.selectedLayers[0];

  = app.beginUndoGroup("Extrapolated Zeugma");

  myLayer.property("ADBE Effect = Parade").addProperty("ADBE Fill");
  myLayer.property("ADBE = Effect Parade").addProperty("ADBE Color Link");
  = myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Control");

  var colorControl =3D = myLayer.property("ADBE Effect Parade").property("ADBE Color = Control").property("ADBE Color Control-0001");
  = colorControl.expression =3D colourExpression;

  $.sleep(150);

  var controlValue =3D = colorControl.value;

  var r =3D = controlValue[0];
  var g =3D controlValue[1];
  var b =3D= controlValue[2];

  alert("RGB: " + r + "," = + g + "," + b);

  = app.endUndoGroup();
};

Zack = Lovatt
424.442.0020

On Thu, May 3, 2018 at 8:13 = PM, Chris Zwar <AE-List@media-motion.tv> wrote:
Thanks for your = interest.  Yes your script works fine, and it=E2=80=99s prompted me = to play around a bit more.  My full script is a few hundred lines = and I won=E2=80=99t post it all, but I have stripped it down to the = basics and I=E2=80=99ve found where the problem comes from.
= In my full script I am applying the Color Link effect and sampling the = colour after it is applied.  It=E2=80=99s this effect which is not = working in CC 2017 or CC 2018.  As an experiment, I tried applying = the basic fill effect instead, and when I do that the script does work = as expected.

I=E2=80=99ve pasted a version of the script below. If you leave it = as-is. the color link effect is applied and the sampleImage only returns = 0.  If you comment out the color link effect to prevent it being = added, then only the fill effect is applied.  Then the sampleImage = correctly returns the values of 1,0,0.

I would love to know if you can replicate this behaviour - thanks = again.

-Chris

{
    function ZaksTest(thisObj) {     
var   ZaksTestData =3D new Object ();
        ZaksTestData.strApply=3D"Apply";
var colourExpression=3D"x=3DthisLayer.width/2;y=3DthisLayer.height/2;\n = c=3DsampleImage([x,y], radius =3D [2, 2], postEffect =3D true, t =3D = time);\n c";
// Set up the GUI         
        function ZaksTest_buildUI(thisObj) {
            var myPanel =3D (thisObj = instanceof Panel) ? thisObj : new Window ("palette","ZaksTest",undefined, {resizable:true});
var res =3D
                    =             "group { \
                    =                     = orientation:'column', alignment:['fill','top'], \
                    =             apply: Group { \
                    =             alignment:['right','top'], = \
                    =             applyBtn: Button { text:'" + = ZaksTestData.strApply + "' }, \
                    =             }, \
                    =         }";          =  
myPanel.grp =3D myPanel.add(res)
var apply=3DmyPanel.grp.apply.applyBtn;
// Apply button - main  part          =          
apply.onClick=3Dfunction()
{
var myComp =3D app.project.activeItem;
app.beginUndoGroup("ZaksTest");
clearOutput();
var myLayer =3D myComp.selectedLayers[0];
myLayer.property("ADBE Effect Parade").addProperty("ADBE Fill");
// comment out the color link effect and the script works.  If it's = enabled it doesn't //
myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Link");
myLayer.property("ADBE Effect Parade").addProperty("ADBE Color = Control");
myLayer.property("ADBE Effect Parade").property("ADBE Color = Control").property("ADBE Color Control-0001").expression=3DcolourExpression;
var RGB=3D[1,1,1,1];
var r=3D0;g=3D0;b=3D0;
RGB=3DmyLayer.property("ADBE Effect Parade").property("ADBE Color = Control")(1).value;
r=3DRGB[0];
g=3DRGB[1];
b=3DRGB[2];
alert("RGB: "+r+","+g+","+b);
app.endUndoGroup();
}
// Set panel resizing
myPanel.layout.layout (true);
myPanel.grp.minimumSize=3DmyPanel.grp.size;
= myPanel.layout.resize();
myPanel.onResizing =3D myPanel.onResize=3D function () = {this.layout.resize()}
           return myPanel;
                    =             }
var ZaksTestPal =3D ZaksTest_buildUI(thisObj);      =    
        if ((ZaksTestPal !=3D null) && = (ZaksTestPal instanceof Window))
        {
            ZaksTestPal.center();
            ZaksTestPal.show();
        }
    }
ZaksTest(this) ;
}
+---End of message---+
To unsubscribe send any message to <ae-list-off@media-motion.tv>


= --Apple-Mail=_98A3E1AC-B40D-451D-B401-F8ECDD8F0525--