Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Help with a script TONIGHT PLEASE

  • Help with a script TONIGHT PLEASE

    Posted by Adam Forbes on November 12, 2009 at 6:58 am

    I need some help fast.

    I have multiple projects and thousands of layers so I need a script that will add this expression to every anchor point and every position of a layer:

    tempx = value[0];
    tempy = value[1];

    tempxwhole = Math.round(tempx);
    tempywhole = Math.round(tempy);
    [tempxwhole, tempywhole]

    It’s a simple expression to round the position to the nearest integer which in turn makes the illustrator file appear more clear.

    What I need is a script that will apply that expression to all layers selected:

    I NEED it ASAP!

    Thanks

    tempx = value[0];
    tempy = value[1];

    tempxwhole = Math.round(tempx);
    tempywhole = Math.round(tempy);
    [tempxwhole, tempywhole]

    Dan Ebberts replied 16 years, 6 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    November 12, 2009 at 4:15 pm

    Try this:

    {
    var expr = ‘tempx = value[0];\r’ +
    ‘tempy = value[1];\r’ +
    ‘tempxwhole = Math.round(tempx);\r’ +
    ‘tempywhole = Math.round(tempy);\r’ +
    ‘[tempxwhole, tempywhole]’;

    var myComp = app.project.activeItem;
    var myLayer;
    for (var i = 1; i <= myComp.numLayers; i++){ myLayer = myComp.layer(i); try{ myLayer.property("anchorPoint").expression = expr; }catch (err){ } myLayer.property("position").expression = expr; } } Dan

  • Adam Forbes

    November 12, 2009 at 4:28 pm

    Dan,

    That’s awesome thanks so much. It doesn’t seem to work for the WHOLE PROJECT. Is there a way to get it to go through every comp in the project instead of just the one I’m in?

    Thanks,

    Adam

  • Dan Ebberts

    November 12, 2009 at 5:39 pm

    {
    var expr = ‘tempx = value[0];\r’ +
    ‘tempy = value[1];\r’ +
    ‘tempxwhole = Math.round(tempx);\r’ +
    ‘tempywhole = Math.round(tempy);\r’ +
    ‘[tempxwhole, tempywhole]’;

    var myComp;
    var myLayer;
    for (var j = 1; j <= app.project.numItems; j ++){ myComp = app.project.item(j); if (myComp instanceof CompItem){ for (var i = 1; i <= myComp.numLayers; i++){ myLayer = myComp.layer(i); try{ myLayer.property("anchorPoint").expression = expr; }catch (err){ } myLayer.property("position").expression = expr; } } } } Dan

  • Adam Forbes

    November 13, 2009 at 11:27 am

    Dan,

    That worked great for a while, then it seems to really get tripped up by hidden layers.

    It says Unable to execute scrpt at line 19. After Effects error. Can not “set Expression” with this property, because the proptery or a parent property is hidden.

    any ideas?

    Thanks,
    Adam

  • Dan Ebberts

    November 13, 2009 at 5:40 pm

    That’s strange. See if this helps:

    {
    var expr = ‘tempx = value[0];\r’ +
    ‘tempy = value[1];\r’ +
    ‘tempxwhole = Math.round(tempx);\r’ +
    ‘tempywhole = Math.round(tempy);\r’ +
    ‘[tempxwhole, tempywhole]’;

    var myComp;
    var myLayer;
    var isHidden;
    var isLocked;
    for (var j = 1; j <= app.project.numItems; j ++){ myComp = app.project.item(j); if (myComp instanceof CompItem){ for (var i = 1; i <= myComp.numLayers; i++){ myLayer = myComp.layer(i); isLocked = myLayer.locked; myLayer.locked = false; isHidden = myLayer.hidden; myLayer.hidden = false; try{ myLayer.property("anchorPoint").expression = expr; }catch (err){ } myLayer.property("position").expression = expr; myLayer.locked = isLocked; myLayer.hidden = isHidden; } } } } Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy