Activity › Forums › Adobe After Effects Expressions › Use SourceRectAtTime with multiple sources?
-
Use SourceRectAtTime with multiple sources?
Posted by David Cabestany on October 25, 2017 at 5:06 pmCan I resize a rectangular shape layer using a bunch of text layers as the source so each time the text layer changes the box adjusts its size?
Text layer 1 happens from 0 to 1 seconds, text layer 2 from 2 to 3, etc.
I was thinking that it could perhaps be accomplished using markers or sampleImage() but not sure on exactly how.
Any ideas?Dan Ebberts replied 8 years, 8 months ago 2 Members · 10 Replies -
10 Replies
-
Dan Ebberts
October 25, 2017 at 5:41 pmIf I understand, there are a number of ways you could do it. If you know the times it could be like this:
if (time < 1)
sourceLayer = thisComp.layer("Text 1")
else if (time < 2)
sourceLayer = thisComp.layer("Text 2")
.
. // etc.
.
else
sourceLayer = thisComp.layer("Text n");sourceLayer.sourceRectAtTime(time,false).width // etc
You could also do it with markers. Does that help?
Dan
-
David Cabestany
October 25, 2017 at 7:33 pmThanks Dan.
It almost works, when it reaches the last second, which is 18, the expression breaks, so I changed the last statement to:if (time < 18
||
time>18.01
)With that it runs ok so that’s not an issue, however is not really following the edges of the layers, see attached:
I even added a few hundred pixels for x and y but still the box does not reach the edges of all text layers.
Any ideas why that could be? It only happens on some layers, and they all have the same specs as they are duplicates of each other, the only thing that changes is the length.
Thanks
D.if (time < 1
)
sourceLayer = thisComp.layer("servicios")
else
if (time < 2)
sourceLayer = thisComp.layer("servicios 17")
else
if (time < 3)
sourceLayer = thisComp.layer("servicios 15")
else
if (time < 4)
sourceLayer = thisComp.layer("servicios 14")
else
if (time < 5)
sourceLayer = thisComp.layer("servicios 13")
else
if (time < 6)
sourceLayer = thisComp.layer("servicios 12")
else
if (time < 7)
sourceLayer = thisComp.layer("servicios 11")
else
if (time < 8)
sourceLayer = thisComp.layer("servicios 10")
else
if (time < 9)
sourceLayer = thisComp.layer("servicios 9")
else
if (time < 10)
sourceLayer = thisComp.layer("servicios 8")
else
if (time < 11)
sourceLayer = thisComp.layer("servicios 7")
else
if (time < 12)
sourceLayer = thisComp.layer("servicios 6")
else
if (time < 13)
sourceLayer = thisComp.layer("servicios 5")
else
if (time < 14)
sourceLayer = thisComp.layer("servicios 4")
else
if (time < 15)
sourceLayer = thisComp.layer("servicios 3")
else
if (time < 16)
sourceLayer = thisComp.layer("servicios 2")
else
if (time < 17)
sourceLayer = thisComp.layer("servicios 16")
else
if (time < 18
||
time>18.01
)
sourceLayer = thisComp.layer("servicios 18")x=sourceLayer.sourceRectAtTime(time,false).width+150;
y=sourceLayer.sourceRectAtTime(time,true).height+20;
[x,y];
-
Dan Ebberts
October 25, 2017 at 7:55 pmHard to say without seeing it. Are you sure the display order of the layers matches the expression?
Dan
-
David Cabestany
October 25, 2017 at 8:04 pmYes, double checked it right after I noticed the discrepancy.
D. -
Dan Ebberts
October 25, 2017 at 8:20 pmIs there any scaling going in with any of the layers?
BTW-I think that last test could just be:
else
sourceLayer = thisComp.layer(“servicios 18”);Dan
-
David Cabestany
October 25, 2017 at 8:31 pmI changed the layer names to index numbers and the discrepancy in size remained. Very strange.
My guess is this expression is still buggy and is not reading each frame the way it’s supposed to. I’m going to report it to Adobe. -
Dan Ebberts
October 25, 2017 at 8:38 pmI don’t know if it applies here, but if your text layers have been scaled, that won’t be reflected in the sourceRect results.
Dan
-
David Cabestany
October 25, 2017 at 9:01 pmNo, all layers are at 100% and there is no parenting whatsoever.
I ended up scaling down the shape layer, now it works, but only when the layer is at 68.2% of its original size (1920×1080).Anyway, the bulk of the expression works and that’s what matters. Thanks a lot for your help Dan.
-
David Cabestany
November 28, 2017 at 5:29 pmHey Dan, how is it going?
Any chance this expression can be revised to work with comp markers instead of time increments?
-
Dan Ebberts
November 28, 2017 at 7:39 pmOne way would be like this I suppose:
m = thisComp.marker;
if (time < m.key(1).time)
sourceLayer = thisComp.layer("servicios")
else if (time < m.key(2).time)
sourceLayer = thisComp.layer("servicios 17")etc.
But if you were clever, you could put the layer suffix in the marker comment and build the name of the sourceLayer on the fly, without needing all those else ifs.
Dan
Reply to this Discussion! Login or Sign Up
