FORUMS: list search recent posts

parenting expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Baker
parenting expression
on Feb 18, 2013 at 7:54:01 pm

i have not found an answer anywhere to my question so i will ask here -

can someone give me an expression that does exactly the same thing that parenting does, [in terms of position]?

i am only concerned with POSITION for the moment ...

i want to apply it to things that you normally cannot parent [like an effect] ... i also want to use this as a building block to build other expressions ....

i want to apply this expression to the position point of an EFFECT - say the effect is "ramp" ... and i would apply this expression to "start of ramp" and parent this point to another layers position [say a layer of text] ... OR i would apply this expression to the emitter position of a particle system

keep in mind what i am asking ... when you parent a layer to another layer that layer does not assume the exact position as the other layer - it moves in RELATION to the other layer .... when one layer moves 10 pixels the other layer maintains its relative position but moves 10 pixels as well

i thank you in advance


Return to posts index

nate mulliken
Re: parenting expression
on Feb 18, 2013 at 8:48:46 pm

Perhaps this may help. not sur eif this is what your looking to do.

I made a comp with a solid. Put on the ramp effect on the solid.
Precomped the solid with the effect, moving everything into the precomp.

Then I made a null next to that precomp. In the null I set a position keyframe so the null moved from top to bottom.

If you drag out the tab of the precomp so you have two timelines open at once you can scroll open the positon of the null and the effect controls for the ramp effect.

Alt click on the start ramp position and pickwhip to the null position.

It'll write an expression that makes the ramp move with the position of the null.


Return to posts index

Dan Ebberts
Re: parenting expression
on Feb 18, 2013 at 10:43:46 pm

I think you're looking for something like this:

myParent = thisComp.layer("Null 1");
myProp = myParent.transform.position;
value + (myProp.value - myProp.valueAtTime(0))

You need to set a reference so the expression can calculate how far the "parent" layer has moved. Usually, the parent's position at time 0 works.

Dan



Return to posts index


John Baker
Re: parenting expression
on Feb 20, 2013 at 3:54:33 pm

thank you - works great


Return to posts index

josh johnson
Re: parenting expression
on Dec 4, 2013 at 7:20:34 pm

Hi there Dan,

I found this thread after a few failed attempts at making an expression that can switch the parent.
So I am messing around with this expression on the position property. I am wondering if this can even work.

What I need is an expression that can hold the altered position value after the layer is "switched".
I am using a slider with hold keyframes to jump through index of my layers.
Currently the "child layer" jumps when I keyframe to the next layer.

I actually have several problems with the current expression but I feel if I can get past this hurdle I will be well on my way.

I hope you can help.
Thanks,
- Josh

picker = Math.round(effect("IndexSelector")("Slider"));

nearSldrKey = effect("IndexSelector")("Slider").nearestKey(time);

sldrSub = nearSldrKey.index-1;
if (nearSldrKey.time >= time){
// catch weird error
if (sldrSub==0){
recentKey = effect("IndexSelector")("Slider").key(nearSldrKey.index);
} else {
recentKey = effect("IndexSelector")("Slider").key(sldrSub);
}
} else {
recentKey = effect("IndexSelector")("Slider").key(nearSldrKey.index);
}

pos = thisComp.layer(picker).transform.position.valueAtTime(recentKey.time-0.001);
prntPos = thisComp.layer(picker).transform.position;
origionalPos = valueAtTime(recentKey.time);
posDiff = origionalPos-pos;
newPos = posDiff+prntPos;

[newPos[0],newPos[1]]




Return to posts index

Dan Ebberts
Re: parenting expression
on Dec 5, 2013 at 1:30:21 am

It's a little complicated. You need to set up a loop that starts at time zero and loops through all past keyframes of the picker slider to figure out where the child was at the beginning (and end) of each keyframed interval. That is, where the layer started initially, where it ended at then end of the segment with the first parent, where it was at the end of the segment with the second parent, etc. until finally, where it should be now, relative to the current parent.

Not too tough, but not trivial.

Dan



Return to posts index


josh johnson
Re: parenting expression
on Dec 5, 2013 at 5:19:40 am

Thank You! This makes total sense.

But also, ugh. Ok brains here we go.

Thanks for looking at it. I will update as soon as I have something.



Return to posts index

josh johnson
Re: parenting expression
on Dec 11, 2013 at 2:27:44 pm

Thanks again Dan!
It totally worked. This is what I came up with.

Totally useful for me. Buddy thought it was useful as well. Prolly gonna save this out as a preset and post it on my site. I will of course credit you for the help.

- Josh

//// LILSMOKIES PARENT SWAP ////

/* Should you wish to have an expression
before applying the parent expression
plug the result into the orgValue. */

orgValue = position;

// method chooser
chkBox = effect("Select Relative to Original")("Checkbox");
if (chkBox==true) {
Sldr = effect("Select Relative")("Slider");
if (Sldr.numKeys > 0) {
ValueHOLD ();
main (index, orgValue);
} else {
position;
}
} else {
Sldr = effect("Select by Index")("Slider");
if (Sldr.numKeys > 0) {
ValueHOLD ();
main (0, orgValue);
} else {
position;
}
}







function ValueHOLD () {
nearSldrKey = Sldr.nearestKey(time);
sldrSub = nearSldrKey.index-1;
if (nearSldrKey.time > time){
// catch weird error
if (sldrSub==0){
recentKey = Sldr.key(nearSldrKey.index);
} else {
recentKey = Sldr.key(sldrSub);
}
} else {
recentKey = Sldr.key(nearSldrKey.index);
}
return recentKey;
}


function main(childINDX, posVALUE) {
// need to create a loop
// fix first pass

//orgValue = valueAtTime(time);
newPos = posVALUE;
for (i=1;i&lt;=recentKey.index;i++) {
sldrKey = Sldr.key(i);
if (i > 1) {
preSldrKey = Sldr.key(i-1);
prntEnd = thisComp.layer(childINDX+preSldrKey.value).transform.position.valueAtTime(sldrKey.time);
if (thisComp.layer(childINDX+preSldrKey.value).index == thisLayer.index) {
prntEnd = thisComp.layer(childINDX+preSldrKey.value).transform.position.valueAtTime(0);
}
newPos = posDiff+prntEnd;
// previous key first then current key
prntStart = thisComp.layer(childINDX+sldrKey.value).transform.position.valueAtTime(sldrKey.time);
if (thisComp.layer(childINDX+sldrKey.value).index == thisLayer.index) {
prntStart = thisComp.layer(childINDX+sldrKey.value).transform.position.valueAtTime(0);
}
posDiff = newPos-prntStart;
newPos = posDiff+prntStart;
} else if (thisComp.layer(childINDX+sldrKey.value).index == thisLayer.index) {
prntStart = thisComp.layer(childINDX+sldrKey.value).transform.position.valueAtTime(0);
var posDiff = newPos-prntStart;
newPos = posDiff+prntStart;
}else {
prntStart = thisComp.layer(childINDX+sldrKey.value).transform.position.valueAtTime(sldrKey.time);
var posDiff = newPos-prntStart;
newPos = posDiff+prntStart;

}
}

prntPos = thisComp.layer(childINDX+recentKey.value).transform.position;
if (thisComp.layer(childINDX+recentKey.value).index == thisLayer.index) {
prntPos = thisComp.layer(childINDX+recentKey.value).transform.position.valueAtTime(0);
}
activPos = posDiff+prntPos;


if (position.value.length==3) {
return [activPos[0],activPos[1],activPos[2]]
//return [activPos[0],activPos[1],posDiff[0]]
} else {
return [activPos[0],activPos[1]]
}
}




Return to posts index

Tim Hildebrandt
Re: parenting expression
on Sep 2, 2014 at 9:47:08 am

Hello Dan,

with your expression you helped me a lot, this was exactly what I was looking for.

So I have an example animation of one square and one circle.

The square is moving from the left to the right:





Then down a little bit:



Then it goes back and the circle is coming with the square:



If the checkbox is ticked then the circle is moving with the square's position (like in your expression). I just changed the point from when it is starting to move with the quare with a slider control ("Start").



Now I want the circle to stop on that current position where it is now. And this I want to determine with the second slider control ("End").

Has to be something like
if(time>End)
{
STAY AT YOUR CURRENT FCKNG POSITION!!!
}
else
{
I WILL KILL YOU
}


haha

So. The first part is done. How to stop that whole thing?

This is the code I used (translated in english for you):

myParent = thisComp.layer("Square");
myProp = myParent.transform.position;
Box = thisComp.layer("Adjustment Layer 1").effect("Checkbox")("Checkbox");
Start = thisComp.layer("Adjustment Layer 1").effect("Start")("Slider control");
End = thisComp.layer("Adjustment Layer 1").effect("End")("Slider control");

if(time>Start && Box==1)
{
value + (myProp.value - myProp.valueAtTime(Start))
}
else
{
value
}


Return to posts index


Dan Ebberts
Re: parenting expression
on Sep 2, 2014 at 6:09:45 pm

This worked for me:


myParent = thisComp.layer("Square");
myProp = myParent.transform.position;
Box = thisComp.layer("Adjustment Layer 1").effect("Checkbox")("Checkbox");
Start = thisComp.layer("Adjustment Layer 1").effect("Start")("Slider");
End = thisComp.layer("Adjustment Layer 1").effect("End")("Slider");
if(time>Start && time <= End && Box==1) {
value + (myProp.value - myProp.valueAtTime(Start))
}else if (time > End){
value + (myProp.valueAtTime(End) - myProp.valueAtTime(Start))
} else {
value
}


Although, I'm not sure why you need the checkbox with the sliders (or vice versa).



Return to posts index

Tim Hildebrandt
Re: parenting expression
on Sep 2, 2014 at 6:39:50 pm

Thank you a lot. I will test it in few minutes. I want to create a template and the user should get the option to do this. And not with a square and a circle, of course not ;)


Return to posts index

Tim Hildebrandt
Re: parenting expression
on Sep 2, 2014 at 7:10:33 pm

So this works great. Thank you very much :D

One question though. Would it be possible to keyframe it? So that the circle get back to his place. Therefore I would keyframe the start and ending sliders, but anyhow it doesn't work.

And I am quite new to expressions like these so please forgive me for this questions ;)

Greets


Return to posts index

Dan Ebberts
Re: parenting expression
on Sep 2, 2014 at 8:31:17 pm

I don't know if this is what you're after, but it seems like if, after the comp time has passed the End time, you keyframe the End time returning to the Start time, the layer should return to its starting position.

Dan



Return to posts index

Tim Hildebrandt
Re: parenting expression
on Sep 2, 2014 at 9:34:17 pm

THAT'S IT!!!

Thank you so much.

Almost lost my nerves on solving all this alone until I thought, some professional help can't be that wrong :)

Learned very much today! Thank you!


Return to posts index

Ale Elizondo
Re: parenting expression
on Jun 17, 2015 at 7:25:24 pm

Hello Dan!!

I have used a couple of expressions, including the explained expression of here for make a "write on effect" to begin in the second 1, however the brush position is outside of the "myProp" variant, I have analyzed it, but I have not yet understood this. I attached a picture where I show this. Thanks!!




Return to posts index

Dan Ebberts
Re: parenting expression
on Jun 17, 2015 at 7:52:48 pm

One thing I see is that there is a line in your Brush Position expression that doesn't make sense:

if(time>Start && time){

you probably need this instead:

if(time>Start && time <= End){


Dan



Return to posts index

Ale Elizondo
Re: parenting expression
on Jun 18, 2015 at 2:16:03 pm

Perfect that is the solution or the error rather!!!, Thanks Dan


Return to posts index

Gustavo Saliola
Re: parenting expression
on Jul 28, 2015 at 9:59:23 pm

Hi Dan! As usual, all ways gets right here and you, every time is about expressions.

Just need to use the tracking data (x,y) to parent the relative position of 4 (or more) continuous paint strokes. So don't have to manually copy/paste and adjust every single stroke.

Thanks again. You rock!


Return to posts index

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