Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Maintaining stroke width, while scaling height and width independently

New Here ,
Feb 16, 2021 Feb 16, 2021

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!

 

 

TOPICS
Expressions
8.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 17, 2021 Feb 17, 2021

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

Translate
LEGEND ,
Feb 16, 2021 Feb 16, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2021 Feb 17, 2021

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2021 Feb 17, 2021

Sorry I forgot to attach this 

SizePosition.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 17, 2021 Feb 17, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2021 Feb 17, 2021

Thank a million! That works perfectly now. Really appreciate the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2023 Dec 20, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

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? 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

Can you post a screen shot of the the error message?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Screenshot 2024-05-23 at 10.55.26 AM.png

Sure, like this~

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Thank you Dan! I guess it doesn't related to the curly bracket since I tried different format.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Thank you again and then, it reported the same as the initial error. I wonder what's reason? 

Screenshot 2024-05-23 at 1.12.26 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

Well now I'm stumped. Is this a 3D layer? Anything else unusual about this layer?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

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:)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

OK, one last thought. Is it possible for you to post a stripped-down version of the project that demonstrates the error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

sure, I did a quick screencap. Hope it helps

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

LOL, sorry to make you confused. Here I attached the file. If you didn't see the error at first, hit the space button and play around. The error reminder will appear soon:)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

I think this actually does what you want and is somewhat simpler:

s = transform.scale[0];
scaleFactor = (s > 0) ? 100/s : 1; 
value*scaleFactor; 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines