Activity › Forums › Adobe After Effects Expressions › Resize a Mask Path or a converted Bezier Path Shape Layer to Comp size
Tagged: Basic
-
Resize a Mask Path or a converted Bezier Path Shape Layer to Comp size
Posted by Nick Mara on September 26, 2020 at 8:10 pmHi Everybody,
I’m experimenting with self-resizing expressions in AfterEffects but I can’t find a way to automatically re-scale a Shape Layer converted to Bezier Path to Composition size.
Here the steps:
1 – Create a Comp 400 x 200 px
2 – Create a Rectangular Shape Layer with a Stroke
3 – Convert the Rectangle to a Bezier Path
After this step I wanted to change the composition size and I also wanted the Path to automatically resizing.
So this is the question:
Is there an expression like
sizeX = thisComp.width;
sizeY = thisComp.height;
[sizeX, sizeY]
working for Paths?
I’ve tried that expression without converting the Shape Layer to Bezier and it works but it’s not what I want.
I’m also interested to know if there’s a way to do the same thing with a Mask Path or not.
I hope someone of you could help me because I’m pretty stuck.
THANKS IN ADVANCE
Nick Mara replied 5 years, 7 months ago 3 Members · 9 Replies -
9 Replies
-
Dan Ebberts
September 26, 2020 at 8:42 pmSee if this path expression works for you:
p = thisProperty;
r = sourceRectAtTime(0,false);
pts = p.points();
newPoints = [];
for (i = 0; i < pts.length; i++){
newPoints.push( [pts[i][0]*thisComp.width/r.width,pts[i][1]*thisComp.height/r.height]);
}
createPath(newPoints,p.inTangents(),p.outTangents(),p.isClosed())
-
Nick Mara
September 27, 2020 at 1:19 amHi Dan,
Thanks for your quick response!!
Unfortunately this solution is not working properly for me.
Once I change the composition size, the mask size remains unchanged and always centered.
If I apply the same expression on a bezier path of a shape layer, the expression it’s not working at all.
So I have another idea but I’m stuck again.
I’ve created Nulls from path so each Null object is now linked to each vertex of the Path.
Check the image I upload, I took a snapshot of the shape layer with the 4 Null objects.
In this case I have a Rectangle path so there are 4 Null objects linked to each point.
Now I think it could be nice to say to each null object to stay in a precise position reacting to the composition size.
For example:
The Top Left point should always react to the composition size and always snap its position to the Top Left corner of the composition itself.
Same thing for the Top Right, Bottom Right and Bottom Left.
Do you think there could be an expression to make a null object automatically snapping on a certain position?
That would be nice because once I change the composition, all the Null objects would snap to the correct position and the path of the shape layer would consequently change.
I hope you can help me again.
Thanks for your help and let me know what you think
-
Filip Vandueren
September 27, 2020 at 10:34 amWhile Dan’s expression works perfectly for me.
Your solution with the Nulls could use these simple expressions for the position of each Null like so:
TopLeft:
[0,0];
TopRight:
[thisComp.width, 0];
BottomRight:
[thisComp.width, thisComp.height];
BottomLeft:
[0, thisComp.height];
-
Nick Mara
September 27, 2020 at 12:24 pmHey Flip,
did Dan’s expression worked properly for you?
So that means that I’m doing something wrong.
I’ve tried to make a brand new composition with a brand new rectangular shape layer and it seems to work well now until I add a Trim Path to animate the End and the Start of the Path.
When the End’s parameter goest to 0 % an error occur and this happens also on the Start parameter when it goes to 100 %.
Watch the video I’ve posted and if there’s a solution for this problem, it would be amazing =)
Video:
https://www.youtube.com/watch?v=FmgrOoaovRM
Please tell me if there’s something I can do to fix that problem.
For the second option with the Null Objects everything is working great so thank you so much for your help !!!
At this point I have another thing I’d love to do:
I need to set the first Vertex of the Path changing from one corner to the other one clockwise creating keyframes and link this keyframes to a slider control.
To do so I would need to set one vertex as first vertex and keyframing it, then move on the second vertex, set it as first vertex and keyframing it and so on.
So in total there would be 4 Keyframes, as many keyframes as the Path Vertices.<font face=”Courier New, Courier, Lucida Sans Typewriter, Lucida Typewriter, monospace”></font>
At this point I need to add an expression to the Path property like:
n = Math.round(thisComp.layer(“NullObject_Name”).effect(“SliderControl_Name”)(“Slider”));
n = clamp(n,1,numKeys)
valueAtTime(key(n).time);
So when changing the slider value from 1 to 4, the path start would perfectly snap clockwise to the 4 different corners one by one.
Is it possible to merge Dan’s expression with this expression somehow?
Or is there a workaround?
I’ve tried to apply the method I explained before on the Offset property.
So I keyframed the Offset property of the Trim Path at 4 different angles ( 0°, 90°,180°,270°) with the expression linking it to a slider control as I said before but it obviously works only with a square shape not with rectangles.
Watch this to see what I would be able to do:
https://www.youtube.com/watch?v=t8OtXayvOYc
As you can see after I’ve created the path I need to input the comp size values into the Rectangle size.
I would like to avoid that passage using Dan’s expression but I would also be able to keyframe the path vertex and add the other piece of expression.
Maybe it’s a bit messy but I hope there’s a way to do that.
Thanks a bunch in advance for your help guys !!!
Some contents or functionalities here are not available due to your cookie preferences!This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.
-
Filip Vandueren
September 27, 2020 at 12:36 pmThe moment your trimPath makes the shape disappear completely, the sourceRect will have a width and height of 0, resulting in division by 0 errors.
The easiest fix is to keyframe the trimpath properties, and to reference the sourceRectAtTime() to a time where you’re sure the whole rectangle is visible. for example r=sourceRectAtTime(10, false);
Or we can do a check if the width/height is 0, and not do the divisions, but then the shape will revert to normal when it’s invisible (which might not be a big deal, but is confusing)
-
Nick Mara
September 27, 2020 at 12:57 pmThanks for your answer.
This is pretty confusing to me.
The issue happens when the Start or the End value is less than 50%.
At 49 % the Shape Path starts to Expand.
Something more is needed.
Something able to constrains the shape size to the comp size even if the End property value goes down to 0% or up to 100 % for the Start property.
Any idea?
-
Filip Vandueren
September 27, 2020 at 1:13 pmThe issue would occur as soon as one of the two dimensions=0.
The stroke width is nott included.
Here’s some messy code for reordering the points to a new FirstVertex (0 based), but you’d have to do the same for inTnagents and outTangents if the shape would be anything else than just harde edges like your example.
newFirstVertex = 2; // attach to slider
p = thisProperty;
r = sourceRectAtTime(0,false);
pts = p.points();
pts=pts.slice(newFirstVertex,pts.length).concat(pts.slice(0,newFirstVertex));
createPath(pts ,[], [], p.isClosed()) -
Filip Vandueren
September 27, 2020 at 1:14 pmAre you keyframing, or just sliding with the values ? When you keyframe just make sure there is a definite point when the rectangle is complete, and use that time, then it ‘ll work. Not when you’re just trying different values without keyframes as you did in your screengrabs
-
Nick Mara
September 27, 2020 at 1:44 pmAt this point I’m pretty lost.
I keyframed the Rectangular Shape Layer setting the first Vertex in 4 different frames.
After that I put this expression into the Path property:
n = Math.round(thisComp.layer(“NullObject_Name”).effect(“SliderControl_Name”)(“Slider”));
n = clamp(n,1,numKeys)
valueAtTime(key(n).time);
I created a null object with a slider control and link that property to it.
So now I’m able to switch the first vertex where the stroke starts via the slider values.
I’ve also tried your expression:
newFirstVertex = 2; // attach to slider
p = thisProperty;
r = sourceRectAtTime(0,false);
pts = p.points();
pts=pts.slice(newFirstVertex,pts.length).concat(pts.slice(0,newFirstVertex));
createPath(pts ,[], [], p.isClosed())But I can’t get it work.
Could you please tell me the steps?
1 – Create a rectangle shape layer
2 – Convert it to Bezier Path
3 – Keyframe the first vertex in different positions
4 – Insert your expression and link it to the slider value
This is what I did but nothing happens when I move the slider cursor.
Reply to this Discussion! Login or Sign Up