Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using sourceRectAtTime to determine placement of nulls.

  • Using sourceRectAtTime to determine placement of nulls.

    Posted by Lucy-rae Naylor on February 9, 2020 at 3:25 am

    Hi! I’m very new to scripting and expressions, but can somewhat get through it from all the resource on here..

    I’m trying my hand at my first script and I’m struggling with this:
    My aim is to have two nulls use source rect at time to find the bottom left + bottom right corner of a shape/text layer to use as its initial position value when placed in the comp.

    I have no idea how to write this, hoping someone can point me in the right direction. It’s been driving me crazy for hours!

    Thanks

    Lucy-Rae

    Lucy-rae Naylor replied 6 years, 6 months ago 2 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    February 10, 2020 at 7:05 am

    Try this


    var currentComp = app.project.activeItem;
    var myLayer = currentComp.layer(1);
    var myLayerPos = myLayer.transform.position.value;
    var myLayerRect = myLayer.sourceRectAtTime(0,false);
    var null1 = currentComp.layers.addNull();
    var null2 = currentComp.layers.addNull();
    null1.transform.position.setValue(myLayerPos + [myLayerRect.left, myLayerRect.top+myLayerRect.height]);
    null2.transform.position.setValue(myLayerPos + [myLayerRect.left+myLayerRect.width, myLayerRect.top+myLayerRect.height]);

    Andrei
    My Envato portfolio.

  • Lucy-rae Naylor

    February 10, 2020 at 10:07 am

    Hey Andrei, thanks so much for your response.

    This has almost worked for me, but wondering if there’s a way to target the selected layer rather than index 1.

    I can’t seem to write it correctly..

    Cheers!

    var currentComp = app.project.activeItem;
    var myLayer = currentComp.seletedLayers[0];
    var myLayerPos = myLayer.transform.position.value;
    var myLayerRect = myLayer.sourceRectAtTime(0,false);

    Lucy-Rae

  • Andrei Popa

    February 10, 2020 at 4:56 pm

    Your way of doing it is correct. You just misspelled selectedLayers

    Andrei
    My Envato portfolio.

  • Lucy-rae Naylor

    February 10, 2020 at 9:32 pm

    Ha! Cheers for noticing that, I thought I was going crazy.

    I’ve applied that and it works to a degree. The space between nulls is correct and matches up perfectly although it doesn’t place the nulls at the shape’s bottom left and right corner. Almost as if I’m missing a toComp(value); expression. Do you know how I can rectify this within the script without reverting to in comp expressions (things are parented which break it)?

    Lucy-Rae

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