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

How to control only the WIDTH of a rectangle with slider control using expression

New Here ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

I have a simple rectangle shape layer that I want to control (only the width) with slider control using expression. How do I do that?

Thanks in advance.

TOPICS
Expressions

Views

8.0K

Translate

Translate

Report

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

Community Expert , Sep 29, 2014 Sep 29, 2014

You could try something like this for anchor point:

w = content("Rectangle 1").content("Rectangle Path 1").size[0];

[-w/2,value[1]]

Dan

Votes

Translate

Translate
Community Expert ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

With a Size expression like this:

w = effect("Slider Control")("Slider");

[w,value[1]]

Dan

Votes

Translate

Translate

Report

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 ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

Thanks, Dan for your quick reply.

I tried your expression and it works like a charm.

However, I should have mentioned that I wanted this shape layer to grow and shrink from the left side (with an anchor point at the far left).

I have the anchor point at the far left, but nonetheless with this expression, it grows and shrinks from the middle.

How can I fix that?

Thanks again so much for your help.

Votes

Translate

Translate

Report

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 ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

You could try something like this for anchor point:

w = content("Rectangle 1").content("Rectangle Path 1").size[0];

[-w/2,value[1]]

Dan

Votes

Translate

Translate

Report

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 ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

Is it possible to do this so that it transforms from the actor point at right?

Votes

Translate

Translate

Report

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
Guide ,
Oct 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

Switch off the expression, grab the Pan Behind/ Anchor Point tool, drag the Anchor Point to the Top Right corner.

Switch the expression back on. Now it should scale from the new anchor point?

Votes

Translate

Translate

Report

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 Beginner ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

I got width to work, I cant seem to get height. Please help!

Thanks,

brian

 

 

Votes

Translate

Translate

Report

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

What do you have that's working, and what are you after, exactly?

Votes

Translate

Translate

Report

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 Beginner ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

LATEST

I got it working now! Sorry I am terrible. Thanks for your support!

Votes

Translate

Translate

Report

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 ,
Oct 08, 2018 Oct 08, 2018

Copy link to clipboard

Copied

Is there a way to lock HEIGHT position instead of the WIDTH?

I'm still a bit new with expressions, so I don't know how to flip this expression so the rectangle path in the shape layer would be anchored at the top and a slider would adjust the path going down.

Thanks in advance for the assist.

Votes

Translate

Translate

Report

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
Mentor ,
Oct 09, 2018 Oct 09, 2018

Copy link to clipboard

Copied

Use Dan's expression for the anchor point and change it to:

w = content("Rectangle 1").content("Rectangle Path 1").size[1];

[value[0],-w/2]

w = content("Rectangle 1").content("Rectangle Path 1").size[...]; -> taking the size of the rectangle and store it in the variable w.

...size[] is an array with two values, x and y. To access on of those values, you write size[0] for x and size[1] for y.

[value[0],-w/2] is an array for x and y values, too. value[0] is the x value of the anchorpoint. This is a way to use an expression along with the possibility to change a value by entering it or drag it.

-w/2 takes half of the y-size of the rectangle and moves the y-value of the anchorpoint by this amount, aka to the top of the rectangle. If you change -w/2 to w/2, the anchor point is pinned at the bottom of the rectangle.

It's easier to understand, if you use actual values:

Rectangle is x = 100, y = 200.

Anchorpoint is at x = 0, y = 0 (in the middle of the rectangle)

Coordinates of the top edge are 0,-100

Coordinates of the bottom edge are 0,100.

(Coordinates of the left edge are -50,0.

Coordinates of the right edge are 50,0.)

w = content("Rectangle 1").content("Rectangle Path 1").size[1];

= 200 (y-value of the rectangle)

-w/2

= -200/2

= -100

Coordinates for the anchorpoint are:

[value[0],-w/2]

= [0, -100]

= top edge.

Cheers,

Martin

Votes

Translate

Translate

Report

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 Beginner ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

Similar question, but how do I control the width and height of a rectangle separately with slider control using expression?

Votes

Translate

Translate

Report

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 ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

A Size experssion like this maybe?

w = effect("Width Control")("Slider");
h = effect("Height Control")("Slider");
[w,h]

Votes

Translate

Translate

Report

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 Beginner ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

Copied

Works perfectly! Thank you so much for your help!

Votes

Translate

Translate

Report

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