Copy link to clipboard
Copied
Hi I am creating a very complex project base in data from a Json file.
And I need to link 7 precomps to a specific location on my composition base into 7 nulls I Already locate.
I try to use If/else staments to link each layer to a specific null. But when some of the slides value is greater than the last one the code does't move the layer to the next null position. here is the code for "A" precomp.
A= thisComp.layer("Shape Layer 1").effect("1")("Slider");
B= thisComp.layer("Shape Layer 1").effect("2")("Slider");
C=thisComp.layer("Shape Layer 1").effect("3")("Slider");
D=thisComp.layer("Shape Layer 1").effect("4")("Slider");
E=thisComp.layer("Shape Layer 1").effect("5")("Slider");
F=thisComp.layer("Shape Layer 1").effect("6")("Slider");
G=thisComp.layer("Shape Layer 1").effect("7")("Slider");
if (((A>B&&A>C) && (A>D&&A>E))&& (A>F&&A>G)){thisComp.layer("N_1").transform.position};
else if (((A<B&&A>C) && (A>D&&A>E))&& (A>F&&A>G)){thisComp.layer("N_2").transform.position};
else if (((A<B&&A<C) && (A>D&&A>E))&& (A>F&&A>G)){thisComp.layer("N_3").transform.position};
else if (((A<B&&A<C) && (A<D&&A>E))&& (A>F&&A>G)){thisComp.layer("N_4").transform.position};
else if (((A<B&&A<C) && (A<D&&A<E))&& (A>F&&A>G)){thisComp.layer("N_5").transform.position};
else if (((A<B&&A<C) && (A<D&&A<E))&& (A<F&&A>G)){thisComp.layer("N_6").transform.position};
else if (A<G-1){thisComp.layer("N_7").transform.position};
then I try this other code having the same results this time its populte "B" precomp Position.
A= thisComp.layer("Shape Layer 1").effect("1")("Slider");
B= thisComp.layer("Shape Layer 1").effect("2")("Slider");
C=thisComp.layer("Shape Layer 1").effect("3")("Slider");
D=thisComp.layer("Shape Layer 1").effect("4")("Slider");
E=thisComp.layer("Shape Layer 1").effect("5")("Slider");
F=thisComp.layer("Shape Layer 1").effect("6")("Slider");
G=thisComp.layer("Shape Layer 1").effect("7")("Slider");
if (((B>A&&B>C) && (B>D&&B>E))&& (B>F&&B>G)){thisComp.layer("N_1").transform.position};
else if ((B>C && (B>D&&B>E))&& (B>F&&B>G)){thisComp.layer("N_2").transform.position};
else if (((B>D&&B>E))&& (B>F&&B>G)){thisComp.layer("N_3").transform.position};
else if (((B>E))&& (B>F&&B>G)){thisComp.layer("N_4").transform.position};
else if ((B>F&&B>G)){thisComp.layer("N_5").transform.position};
else if (B>G){thisComp.layer("N_6").transform.position};
else if (B<G-1){thisComp.layer("N_7").transform.position};
Any one know a better way to do this?
Copy link to clipboard
Copied
This looks complicated and wrong without having a closer look. Too much ifs, so much conditions. I would search for better code as soon as I start to create something like "if (a && b && c && d ...)".
I'm sure there is a better way, but I didn't understand completely what you want to do.
You have 7 nulls placed in your comp and want to place 7 comps at the same position, but variable, so the 7 comps can change position to each other?
If so, why not just grabbing the 7 nulls position and use one slider (1 to 7) to set up specific position of each comp.
slider = thisComp.thisLayer.effect("Slider Control")("Slider");
pos1 = thisComp.layer("N_1").transform.position;
// all the other 6
if (slider == 1){pos1}
else if (slider == 2){pos2}
// and so on
// check syntax, i just wrote it from memory
Is this what you wanted? If not, please explain again with more details.
*Martin
Copy link to clipboard
Copied
Im trying to order my comps Bigest to smallest. Every preComp has a lot of data (player name, team, points, etc ) number linked from a Json file.
The sliders values mirror points value of each player.
My Idea was use that value to order my precomps automaticly when a player scale up or down in my score table.
Copy link to clipboard
Copied
Do you have access to the rank? You can make the order completely automatic, if so.
This doesn't sound very hard to make...
You have 7 predefined places, therefore
rank #1 = null1 = x,y of null 1
rank #2 = null2 = x,y of null 2
and so on...
We can grab those positions, as I already wrote.
Now every comp looks up it's rank and take the predefined position.
Something like:
myrank = *rank from json data or calculated*;
pos1 = thisComp.layer("N_1").transform.position;
if (myrank == 1) {myPosition = pos1}; // you can skip "myPosition", this is just for understanding, short version will be as written in my other post up there
myPosition; // you can skip this in short version
If the rank is not present, we can for sure calculate it with the score table.
*Martin
Copy link to clipboard
Copied
That is my problem. How to calculate the Ranking position?
something like this?
when i do this way when N_7 becomes N_6 booth says are N_7. Must be another way.
Copy link to clipboard
Copied
ignore the "-1" in the line 7
Copy link to clipboard
Copied
Don't write you own sorting algorithm unless you have a smarter one.
What data do you have and how would you order the players rank manually?
I assume that there is a "score" data in the json. Something like player1: score 3456, player 2: score 4456 and so on. Higher score, higher rank.
I never worked with json data driven animation, but you already managed to get those data into AE.
The next step is to grab all those scores into an array.
Just saw a tutorial and in this it was only a matter of putting a line of code (the exact data address) into a text layer.
In the example, he wrote "footage("players.json").dataValue([0,0,0])".
To get this and all the others into an array, it should work like this (following the sample from the tutorial) - assuming that your score is always the 2nd data entry (If you show me your code, I can give you better help!):
myarr = [footage("players.json").dataValue([0,0,0]), footage("players.json").dataValue([0,1,0]), footage("players.json").dataValue([0,1,0]), ...];
This should evaluate into something like myarr = [1542,4595,9784, ...]
Now you can SORT those numbers, highest to lowest.
myarr.sort(function(a, b) { return b - a;
});
Result is now myarr = [9784, 4595, 1542, ...]
For performance reasons and "the fine order" I would outsource the sorting to a textlayer. Otherwise, you'll have to repeat the same and same calculation over and over again for all pre-comps, which is unnecessary.
I assume that this is now onto a text layer called "Rank-Text-Layer".
For each pre-comps position property, we will now grab your individual score, look it up in the sorted array and use the index of your score-in-array entry to determine, which null position we should take. Easy!
//grab the array and write it's content to "ranks" - don't nail me on this line - did it before, but am not in front of AE right now
ranks = eval(thisComp.layer("Rank-Text-Layer").text.sourceText.value);
// get the score of this specific player / pre-comp like you did before
myscore = ...
// look up your score in the sorted score array and return the index of it - aka the rank.
// we need to add 1 because arrays start at 0, but ranks at 1
myrank = ranks.indexOf(myscore) + 1;
// grab the positions of the nulls, because we are lazy - make sure that the seven nulls are the first 7 layers in your comp and
// also that they lined up correctly! 1st null in layers stack = 1st rank.
nulls = [];
for (i = 1; i <= 7; i++){
null = thisComp.layer.transform.position;
nulls.push(null);
};
// do the magic: we know the rank of this specific pre-comp. We grabbed the nulls from 1st rank to last,
// so we can use myrank as index of nulls to get the position of the corresponding null
// if the pre-comp is rank 3, it will take the position of 3rd null, which represent 3rd place. If it's rank 5, it is the 5th place and so on
nulls[myrank];
Let me know, if this helps in any way!
*Martin
Copy link to clipboard
Copied
I checked the line in which we grab the array from to text layer to calculate on and this should work:
ranks = eval(thisComp.layer("test").text.sourceText);
ranks.split(",");
Cheers,
Martin
Copy link to clipboard
Copied
Thanks for your big help, I gonna try this. if its works I let you know.
Cheers,
Martin
Copy link to clipboard
Copied
Also let me know if it is not working. I wrote the code from memory in the middle of the night.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now