• Global community
• Language:
• Deutsch
• English
• EspaĆ±ol
• FranĆ§ais
• PortuguĆŖs
• ę„ę¬čŖć³ćć„ććć£
Dedicated community for Japanese speakers
• ķźµ­ ģ»¤ė®¤ėķ°
Dedicated community for Korean speakers
Exit
• After effects Dropdown and slider expression to ch...

# After effects Dropdown and slider expression to change position of a layer

Community Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

I am creating a setup in after effects where I want to change a position according to a slider and dropdown values. Using below expression for the same

mDrop = comp("Character Builder").layer("Body Type").effect("Body Type")("Menu");
s = thisComp.layer("Turn Body & Head").effect("Turn Body")("Slider");
x = transform.position[0];
y = transform.position[1];
[x,y];
if (s == 0 && mDrop == 1) {[x,y]}
else if (s == 1 && mDrop == 1) {[x-110,y-11]}
else if (s == 2 && mDrop == 1) {[x-325,y]}
else if (s == 3 && mDrop == 1) {[x-526,y-94.5]}
else if (s == 4 && mDrop == 1) {[x-598.,y-106.1]}
else if (s == -4 && mDrop == 1) {[x-598.,y-106.1]}
else if (s == -3 && mDrop == 1) {[x-495,y-79]}
else if (s == -2 && mDrop == 1) {[x-299,y]}
else if (s == -1 && mDrop == 1) {[x-71,y-14]}
else if (s == 1 && mDrop == 2) {[x-41.5,y+62.5]}

There will be more dropdown values till 5 and I want to change the postion if mentioned slider and dropdown values matches

TOPICS
Expressions

Views

350

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 Expert , Mar 25, 2024 Mar 25, 2024

Try adding this as the last line and see if it gets rid of the error:

``else value``

10 Replies 10
Community Expert ,
Mar 25, 2024 Mar 25, 2024

Copied

I'm guessing you have a question, correct? From your screen cap, it looks like your expression generates an error. What's the error message?

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 Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

Yes sorry it was a question. Error says "Undefined value used in expression"

I am not good with expressions. Any help will be a life saver.

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 Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

I have added a slider and dropdown controller to control position of a layer,
So if slider and dropdown condition matches, the position will be set to the mentioned x,y values.

But i am not able to make it work.

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 Expert ,
Mar 25, 2024 Mar 25, 2024

Copied

If you click into the expression, it should highlight a particular line where the error is. Can you post an image of that?

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 Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

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 Expert ,
Mar 25, 2024 Mar 25, 2024

Copied

What are the current values of the menu and the slider?

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 Expert ,
Mar 25, 2024 Mar 25, 2024

Copied

Try adding this as the last line and see if it gets rid of the error:

``else value``

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 Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

When Dropdown value is 1 it works fine but when when i select any other dropdown options apart from 1, it shows the error.

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 Expert ,
Mar 25, 2024 Mar 25, 2024

Copied

I get that error if the menu is set to the 2nd item and the slider is set to anything other than 1, because there is no code to handle that situation. The ending line I suggested should keep it from erroring out.

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 Beginner ,
Mar 25, 2024 Mar 25, 2024

Copied

LATEST

Yessss, it worked, I guess I can add more condition to it now. THank you so much. I will try and reply if anything comes up.