Copy link to clipboard
Copied
Hi there,
I've created a two concentric boxes, meant to look like a computer/browser window(first image). I'm trying to figure out how to scale the height and width independently, while maintaining stroke width. I've made two rectangle shape layers of the same stroke, and applied the following expression to stroke width of both:
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001;
Now if I scale either of the boxes(or both together with a null) this works fine, and stroke is maintained.
However, the upper/inner box needs to have keep a constant height, and I'd like to be able to resize the larger/outer into a variety of shapes, rather than just the current 16:9 shape.
But if I try and seperate the scale width from height and alter either independantly, the expression doesn't seem to work. (I don't get an error, but the strokes just expand or compress with the scale). Any ideas why? Or would anyone have a alternative workflow or workaround that could do it?
I don't have a particularly great understanding of expressions(just got this from Dan Ebberts), so there might be something obvious that I'm missing here. Hopefully one of you lovely people can help me out!
Still not an issue that would require any expressions. Simply add the stroke at the bottom of the stack of the shape groups at the root level. You know, this stuff can be organized and grouped as you see fit and the stroke can just as well be applied after all transforms.
Mylenium
Copy link to clipboard
Copied
Completely wrong approach. You don't scale the graphic, you animate the sizes of the underlying masks/ shape layer rectangles. this has nothing to do with any expressions. It's simply a bad workflow to start with.
Mylenium
Copy link to clipboard
Copied
Hi Mylenium,
Thanks for that. I had tried that approach, but when I adjust the sizes of the rectangles directly from the shape layer (in this menu - Contents -> Rectangle 1 -> Rectangle Path 1 -> size) they resize from the centre (picture attached), as there is no anchor point option for this approach, meaning that everytime I resize the boxes I will need to reposition them also, which isn't ideal. My approach used scale instead because having an anchor point means I can pin it in the corner for both boxes and they will stay together when it scales. Is there something I'm missing here?
Copy link to clipboard
Copied
Sorry I forgot to attach this
 
Copy link to clipboard
Copied
Still not an issue that would require any expressions. Simply add the stroke at the bottom of the stack of the shape groups at the root level. You know, this stuff can be organized and grouped as you see fit and the stroke can just as well be applied after all transforms.
Mylenium
Copy link to clipboard
Copied
Thank a million! That works perfectly now. Really appreciate the help!
Copy link to clipboard
Copied
Hi 🙂
I hope all is great! Could you explain better what you mean with "add the stroke at the bottom of the stack of the shape groups at the root level" and break down the process?
thanks a lot for your help
Copy link to clipboard
Copied
I keep using this expression but right now, like After effects 2024 report this expression has bug/error although it still works. Anyone could help me to fix this?
Copy link to clipboard
Copied
Can you post a screen shot of the the error message?
Copy link to clipboard
Copied
Sure, like this~
Copy link to clipboard
Copied
I'm not sure what's going on, but you might try it this way:
try{
value / length(toComp([0,0]),toComp([.707,.707]));
}catch(e){
.001;
}
Copy link to clipboard
Copied
Thank you for your quick response, Dan!!!
I just tried it and it reported "Error: syntaxerror unexpected token 'catch' ". Do you have any idea on this?
Copy link to clipboard
Copied
You would get that message if you left out the curly bracket before the catch. Can you post a screen shot of the expression with the error?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It looks like you're combining the two expressions. Replace the first one with this:
try{
value / length(toComp([0,0]),toComp([.707,.707]));
}catch(e){
.001;
}
Copy link to clipboard
Copied
Thank you again and then, it reported the same as the initial error. I wonder what's reason? 
Copy link to clipboard
Copied
Well now I'm stumped. Is this a 3D layer? Anything else unusual about this layer?
Copy link to clipboard
Copied
It's a regualr 2D layer. Haha, it's ok. After Effects reports it has an error but the expression still works. I feel uncomfortable to see an error report in my project file and try to figure out, lol.
I think I have this issue since the version of After Effects 2022 or 2023 came. I will do some search later. If you know the answer oneday, please let me know:)
Copy link to clipboard
Copied
OK, one last thought. Is it possible for you to post a stripped-down version of the project that demonstrates the error?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I meant a .aep project file. Your mp4 shows the expression applied to opacity instead of stroke width but I suspect that's not the issue.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hey Dan, I got an answer from Hector Vera from Creative Cow:
The error message basically means that After Effects was unable to convert the result of the expression into a numeric value that can be used to modify the attribute value of the shape layer.
After Effects most likely is having issues interpreting the length function.
One solution to this error is to replace the length function with a calculation that does not use the length function.
One way to do this is to use the value^2 and 0.5 * 0.5 math operators, instead.
Here’s an updated expression that should work:
value / (value^2 + 0.5^2) || 0.001;
This expression divides the value by the sum of the square of value and 0.5 squared, taking the square root of the result. The result is then multiplied by 0.5. This expression should produce the same result as the original expression, while avoiding the use of the length function.
Hopefully this can help you in some ways.
This expression works and I want to share with you! Really appreciate your help!!!
Copy link to clipboard
Copied
I think the error is happing because the scale goes to zero. If you defend against that, I think it will be fine:
if (scale[0] != 0 && scale[1] != 0){
value / length(toComp([0,0]),toComp([.707,.707]));
}else{
value;
}
Copy link to clipboard
Copied
I think this actually does what you want and is somewhat simpler:
s = transform.scale[0];
scaleFactor = (s > 0) ? 100/s : 1;
value*scaleFactor;
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more