ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Adding a checkbox if inside an already big if else loop.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dimitris St
Adding a checkbox if inside an already big if else loop.
on Jun 4, 2018 at 9:37:31 pm

Hello everyone,
First of all i wanted to say what a huge help this forum has been to my expression learning curve and especially dan (you're a god).
Now i just made my account to join the community and because i got stuck into a really weird loop for me to handle on my own.
So here's the thing i have a pretty big project coming some words about the project so u can get to understand better the problem that comes after.
The project is basically a "Character Creation" of sorts.
I have a comp with many slider controls controlling effects as hair / outfits / hats and so on and some color controls for the colors (duh).
And i have a text layer with a number that actually controls which character i'm editing since i can duplicate the characters with the same effects and change each on individually.
So i use a loop that goes something like this for that to happen it loops through the text layer adds some zeroes depending on the text value and finds the character we're editing.

(First Loop on the expression box)

Everything there works all sliders and so on.
My problem is i'm trying to add a checkbox control for some things.
A checkbox named Keep original that disables the colors (By adding an expression to color effect opacity turning 0 if checkbox is up and 100 if its not you know.)
and another to add weight which actually disables the first body and adds a second one which is kinda bigger.

My problem is i cant seem to find a way to add my if condition inside the loop i wrote up there since i need it cause there will be many characters so i cant really just link it to
a specific one i need it to loop through and find which character im editing and make that one original / fat.

You can see how i tried editing it and adding the checkbox on the second expression posted in the box below.
I tried having the if addweight statement inside the brackets outside and in every position i could think of but still no luck so far.
Any help / tips would be greatly appreciated.

// Loop for character number on all sliders (Works just fine).
try{
characterN=comp("Master Panel").layer("Select Character").text.sourceText;
if (characterN>0 ){
if (characterN&lt;10) charString="Character " +"00"+ characterN.toString();
if (characterN>9 && characterN&lt;100) charString="Character " +"0"+ characterN.toString();
if (characterN>99 && characterN&lt;1000) charString="Character"+ characterN.toString();
state=comp("Master Panel").layer(charString).effect("Outfit")("ADBE Slider Control-0001");
framesToTime(state);
}
else res;
}
catch(err){res};


// The loop im trying to create but got stuck so hard.
try{
characterN=comp("Master Panel").layer("Select Character").text.sourceText;
if (characterN>0 ){
if (characterN&lt;10) charString="Character " +"00"+ characterN.toString();
if (characterN>9 && characterN&lt;100) charString="Character " +"0"+ characterN.toString();
if (characterN>99 && characterN&lt;1000) charString="Character"+ characterN.toString();
AddWeight = comp("Master Panel").layer("charString").effect("Add Weight")("Checkbox")
}
else res;
}
catch(err){res};
if(AddWeight.value)0 else 100;


Return to posts index

Kalleheikki Kannisto
Re: Adding a checkbox if inside an already big if else loop.
on Jun 5, 2018 at 3:37:36 pm

Does removing ".value" from the last line do anything?

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Dimitris St
Re: Adding a checkbox if inside an already big if else loop.
on Jun 5, 2018 at 6:08:55 pm

Hello there and thanks for the reply !

No removing the .value doesnt seem to do anything it still crashes.
The position of the if addweight seems to be wrong as well in the example but its just an example as i said i tried it in any other position past and after any collumns but still no luck. cant get this to actually work.

try{
characterN=comp("Master Panel").layer("Select Character").text.sourceText;
AddWeight = comp("Master Panel").layer("charString").effect("Add Weight")("Checkbox");
if (characterN>0 ){
if (characterN&lt;10) charString="Character " +"00"+ characterN.toString();
if (characterN>9 && characterN&lt;100) charString="Character " +"0"+ characterN.toString();
if (characterN>99 && characterN&lt;1000) charString="Character"+ characterN.toString();
if(AddWeight)0 else 100;
}
else res;
}
catch(err){res};


Return to posts index


Alex Printz
Re: Adding a checkbox if inside an already big if else loop.
on Jun 5, 2018 at 8:46:27 pm

It's hard to tell what would serve you best from your description.

How are your 2nd set of bodies stacked up (the heavier ones)? If you are going to have a 2nd set of frames with larger bodies for all of the characters and you simply time-remap for various assets, simply offset their values by a number larger than your total assets (in this case I have added 500, change that number for as many as you would need).

so in my example, if they are regular, character 145 would have a body frame 145, but if they were fat, they would be 645, etc.

HOWEVER,
If you were referencing specific layers, do a label check instead, and call the 2nd set "heavy_character", then just have a 2nd set of body layers, rather than time remapping, to draw from.

Simply un-comment one of the test examples and see what you'd prefer. When you decide one, add another check for the color as well.

-Alex

=====================

try{
offsetWeight = 500; //offsets the time reference layer;
label = "character ";

characterN=comp("Master Panel").layer("Select Character").text.sourceText;
AddWeight = comp("Master Panel").layer("charString").effect("Add Weight")("Checkbox");

if (characterN > 0 ){
charString = characterN.toString();
while ( charString.length < 3) charString = "0" + charString;

//THIS ONE CHANGES THE CHARACTER FRAME REFERENCE
//if (AddWeight == 1) charString = parseInt(charString) + offsetWeight;

//THIS ONE CHANGES THE CHARACTER LABEL USED IN LAYER REFERENCING
//if (AddWeight == 1) label = "heavy_character ";

charString = label + charString;
state=comp("Master Panel").layer(charString).effect("Outfit")("ADBE Slider Control-0001");
framesToTime(state);
}else{res};
}catch(err){res};


Return to posts index

Dimitris St
Re: Adding a checkbox if inside an already big if else loop.
on Jun 5, 2018 at 9:44:00 pm

Hey there alex and thanks for that awesome reply,
Though indeed you cant understand much of whats happening in my comps with what i said so id try to explain it better.

Think is i have a Character 001 with many slider controls and color controls that actually choose frames of clothes etc.
So when slider control outfit is on 1 the outfit is for example a doctor one.
but i also have layers enabling body parts as hands feet etc so the heavier ones are another layer that contains all the heavy parts.
Thing is when addweight is ticked the normal parts get an opacity of 0 and the heavy ones an opacity of 100.
Which parts are to appear are controlled by the outfit slider already so no need to change that just the opacity thingie.

The whole characterN loop only serves to choose which character we are editing in that case Character 001 or 002 or 003 etc which are all duplicates of Character 001 with different slider values.

So the offset wont really work since im not doing anything with it (as far as i get it that is im not really sure)
and the label call wont work either cause the whole heavier parts aint Character calls but layer calls inside a slider.

Ill try to upload some images for better clarification and a better understanding Thanks for all the effort though.

Character Slider controls etc.



Character Part comps



Clothes etc comps.



Return to posts index

Alex Printz
Re: Adding a checkbox if inside an already big if else loop.
on Jun 6, 2018 at 4:41:43 pm

Ok, If I'm understanding correctly, you are time-remapping asset layers in your subcomp "Character Parts" to choose the shape, and you have separate asset layers to hold the fat and regular shapes.


Something like this should work in the opacity code for the fat asset opacity:
try{
characterN=comp("Master Panel").layer("Select Character").text.sourceText;
if (characterN > 0 ){
charString = characterN.toString();
while ( charString.length < 3) charString = "0" + charString;
charString = "Character " + charString;
comp("Master Panel").layer(charString).effect("Add Weight")("Checkbox") == 1 ? 100 : 0;
}else 0;
}catch(err){50};



and something like this in the regular asset opacity:

try{
characterN=comp("Master Panel").layer("Select Character").text.sourceText;
if (characterN > 0 ){
charString = characterN.toString();
while ( charString.length < 3) charString = "0" + charString;
charString = "Character " + charString;
comp("Master Panel").layer(charString).effect("Add Weight")("Checkbox") == 1 ? 0 : 100;
}else 0;
}catch(err){50};


note that the only difference is the final line inside the If statement is that if the checkbox is checked, the outputs for the layers swaps 100/0 to 0/100.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]