Mailing List AE-List@media-motion.tv — Message #64025
From: Chris Zwar <AE-List@media-motion.tv>
Subject: Re: [AE] scripting help - getting colour value
Date: Fri, 4 May 2018 17:24:01 +1000
To: After Effects Mail List <AE-List@media-motion.tv>
Thanks for that, it’s a great help.  I wasn’t aware of the sleep function but it’s got it working most of the time.  It gives me something to look at, although I’m 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’m 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 = function() {
  clearOutput();
  var myComp = app.project.activeItem;
  var myLayer = 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 = myLayer.property("ADBE Effect Parade").property("ADBE Color Control").property("ADBE Color Control-0001");
  colorControl.expression = colourExpression;

  $.sleep(150);

  var controlValue = colorControl.value;

  var r = controlValue[0];
  var g = controlValue[1];
  var b = 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’s prompted me to play around a bit more.  My full script is a few hundred lines and I won’t post it all, but I have stripped it down to the basics and I’ve 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’s 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’ve 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 = new Object ();
        ZaksTestData.strApply="Apply";
var colourExpression="x=thisLayer.width/2;y=thisLayer.height/2;\n c=sampleImage([x,y], radius = [2, 2], postEffect = true, t = time);\n c";
// Set up the GUI         
        function ZaksTest_buildUI(thisObj) {
            var myPanel = (thisObj instanceof Panel) ? thisObj : new Window ("palette","ZaksTest",undefined, {resizable:true});
var res =
                                "group { \
                                        orientation:'column', alignment:['fill','top'], \
                                apply: Group { \
                                alignment:['right','top'], \
                                applyBtn: Button { text:'" + ZaksTestData.strApply + "' }, \
                                }, \
                            }";           
myPanel.grp = myPanel.add(res)
var apply=myPanel.grp.apply.applyBtn;
// Apply button - main  part                   
apply.onClick=function()
{
var myComp = app.project.activeItem;
app.beginUndoGroup("ZaksTest");
clearOutput();
var myLayer = 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=colourExpression;
var RGB=[1,1,1,1];
var r=0;g=0;b=0;
RGB=myLayer.property("ADBE Effect Parade").property("ADBE Color Control")(1).value;
r=RGB[0];
g=RGB[1];
b=RGB[2];
alert("RGB: "+r+","+g+","+b);
app.endUndoGroup();
}
// Set panel resizing
myPanel.layout.layout (true);
myPanel.grp.minimumSize=myPanel.grp.size;
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize= function () {this.layout.resize()}
           return myPanel;
                                }
var ZaksTestPal = ZaksTest_buildUI(thisObj);         
        if ((ZaksTestPal != 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>


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