ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Get position of parented layer doesnt work.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Chicken
Get position of parented layer doesnt work.
on Jul 5, 2017 at 10:49:22 am

Hey guys,

i have a setup with some precomps, nulls and slider controls. The precomps are childs of the nulls. The position of the nulls are controlled by some slider controls.
The precomps are searching for there nearest null object and get parented by that null (Dan helped me with the expression for that).
The null objects and the comps are aligned in a grid. The problem is, that evertime i move some nulls (and with that the child layers of the nulls) the child layers begin to jump around because of the "search nearest null and get parented by that" expression. The child layers should stick to there current parent after they
search for there nearest null (parent).

This is my current project file (for better understanding whats going on in my scene):

11495_videowalltest.aep.zip

And the "search nearest null and get parented by that" expression by Dan:

Thank you 😃

Peter

minD = 999999;
closest = null;
for (i = 1; i &lt;= thisComp.numLayers; i++){
if ( i != index && thisComp.layer(i).name.indexOf("Horizontal") > -1){
L = thisComp.layer(i);
p = L.toComp(L.anchorPoint);
d = length(position,p);
if (d &lt; minD){
minD = d;
closest = p;

}
}
}
if (closest != null) closest else value;


Return to posts index

Dan Ebberts
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 3:58:58 pm

I don't completely understand what you're trying to do, but if you want the layer to pick the closest null only at a particular time, you could use the time parameter of toComp(), like this:

p = L.toComp(L.anchorPoint,0);

to pick up the null's location at time = 0, for example.


Dan



Return to posts index

Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 9:48:01 pm

Hey Dan,

did you had the time to check my project file?
There is a slider control called "slider_control_B". The "slider_control_B" is linked to the null objects in row B. When you change the value of the slider control, you can see, that the nulls and also the precomps (parented by the nearest null) are moving. Everything works fine to this point. But when you move the slider control above a certain value ( i think its 50) the precomps starting to jump to other null objects and gets parented by those. And that should not happen.
I can't figure out how to fix this .

I'am sure you have an idea how to get this to work?!

I'am not quite sure if the time solution would help there. The system should be very flexible.

Thank you for all your help Dan ☺


Return to posts index


Dan Ebberts
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 9:56:21 pm

I took a quick look, but couldn't decipher what you're trying to do (not my strong suit).

Dan



Return to posts index

Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 10:05:57 pm

Ok, i must say that everthing is a bit confusing for sure ☺

But basically here is the main thing i want to achive:

A big grid of precomps. Every row in the precomp should be movable in the x axis and also in the y axis. The movement should be controllable by slider controls.

Maybe there is an easier way to get something like this?


Return to posts index

Dan Ebberts
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 10:19:26 pm

If you could strip it down to a tiny project with only a few layers and animate the slider in a way that clearly demonstrates the issue (and maybe annotate it with text layers and marker comments) we might get to the bottom of this.

Dan



Return to posts index


Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 10:21:08 pm

Ok i will do this right now. Give me a few minutes ☺


Return to posts index

Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 10:47:05 pm

ok, i made a new project file. I hope that this explained the problem a little bit better ☺

11496_videowalltest.aep.zip


Return to posts index

Dan Ebberts
Re: Get position of parented layer doesnt work.
on Jul 5, 2017 at 11:16:46 pm

Four expressions are disabled, and nothing happens when I preview.

Dan



Return to posts index


Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 6, 2017 at 12:03:03 am

oh I`am sorry! The file was created in the german version of after effects.
This file should work:

11497_videowalltestenglish.aep.zip

I tested it in the english version of after effects.


Return to posts index

Dan Ebberts
Re: Get position of parented layer doesnt work.
on Jul 6, 2017 at 3:25:36 am

Try it this way:


minD = 999999;
closest = null;
for (i = 1; i <= thisComp.numLayers; i++){
if ( i != index && thisComp.layer(i).name.indexOf("Horizontal") > -1){
p = thisComp.layer(i).position;
d = length(position.valueAtTime(0),thisComp.layer(i).position.valueAtTime(0));
if (d < minD){
minD = d;
closest = p;
}
}
}
if (closest != null) closest else value;



Dan



Return to posts index

Peter Chicken
Re: Get position of parented layer doesnt work.
on Jul 6, 2017 at 2:37:54 pm

Thank you Dan!!! That worked perfectly ! :)


Return to posts index

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