ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using sourceRectAtTime to determine placement of nulls.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Lucy-Rae Naylor
Using sourceRectAtTime to determine placement of nulls.
on Feb 9, 2020 at 3:25:53 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


Return to posts index

Andrei Popa
Re: Using sourceRectAtTime to determine placement of nulls.
on Feb 10, 2020 at 7:05:34 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.


Return to posts index

Lucy-Rae Naylor
Re: Using sourceRectAtTime to determine placement of nulls.
on Feb 10, 2020 at 10:07:43 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


Return to posts index


Andrei Popa
Re: Using sourceRectAtTime to determine placement of nulls.
on Feb 10, 2020 at 4:56:25 pm

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

Andrei
My Envato portfolio.


Return to posts index

Lucy-Rae Naylor
Re: Using sourceRectAtTime to determine placement of nulls.
on Feb 10, 2020 at 9:32:44 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]