• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update expression value when comp is duplicated.

New Here ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

I have an expression I am using to offset an animation. I am controlling the offset by a slider in a different composition. I want to duplicate this Pre Comp multiple times. the expression references the name of the Pre Comp. Is there a way to make the expression update when duplicated to reference the new increment.

For example: the script points back to "pre comp Photo 1", and when I duplicate it, becoming "pre comp Photo 2", the expression still points back to "pre comp Photo 1"

is there a way to automatically make Photo 1 update to Photo 2 in the script? or am I crazy.

The reason for this is that I have to duplicate this pre comp 100+ times yet I want to control the offset for each one individually.

Views

2.7K

Translate

Translate

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 guidelines

correct answers 1 Correct answer

Mentor , Mar 31, 2017 Mar 31, 2017

Fascinating...

I think it's the "offset = seedRandom(3,true);" part. This is actually wrong.

I would write it:

seedRandom(3,true);

offset = random(0,30);

comp("Comp 1").layer("Null 1").position.valueAtTime(time + offset);

Give it a try.

Votes

Translate

Translate
LEGEND ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

This can't be done automatically, but of course you can write some code that matches the name strings or use a script like the True Comp Duplicator to have it fix your expressions in the process. Generally though, I'm not sure if there would be much sense in having 100 expression sliders to just control some offset. You might just as well use native transform properties in the parent comp to that effect.

Mylenium

Votes

Translate

Translate

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 guidelines
New Here ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

I am using True Comp Duplicator, but for some reason It isn't changing the expression.

The use case is, I am having several objects move on the Z axis. I want them to all do the same animation but I want to individually determine the offset of when the animation starts. using the slider as an "easy" was to set that. Im also trying to use the random expression to just set the offset at random and not have any control over it but I can't figure out oh to get random to pick one value and stick with it. but i am having issues setting the frequency to 1, so it only picks a number once.

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

When it comes to random, you can use posterizeTime(fps) to slow down the randomness. If you just want to pick ONE random value, best practice is to use:

seedRandom(someseed, true);

random(minVal, maxVal);

Read more about random motion at Dan Ebberts page: http://www.motionscript.com/mastering-expressions/random-1.html

Votes

Translate

Translate

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 guidelines
New Here ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

That is what I was trying. Here is the expression I am using.

offset = seedRandom(3,true); random(0,30);

p = comp("Comp 1").layer("Null 1");

t = time + offset;

p.position.valueAtTime(t);

but AE seems to not like it. not sure what I am putting in wrong.

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Is there an error message?

Maybe putting "offset = seedRandom(3,true); random(0,30);" on two lines will do it?

Votes

Translate

Translate

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 guidelines
New Here ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

I have tried ever combination of changing line I can think of even taking out the offset value and just making

t = time + seedRandom(3,true); random(0,30);

when I do that It tells me "Invalid numeric result (divide by zero?)."

Votes

Translate

Translate

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 guidelines
LEGEND ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

seedRandom() must be called outside your equations. It's a reserved method that only pins AE's internal randomization functions to fixed values:

seedRandom(3,true);

offset = random(0,30);

p = comp("Comp 1").layer("Null 1");

t = time + offset;

p.position.valueAtTime(t);

Mylenium

Votes

Translate

Translate

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 guidelines
New Here ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

OKAY! I think I did it. This is the expression that seems to work

seedRandom(1,true)

x = random(1,100);

p = comp("Comp 1").layer("Null 1");

seedRandom(x,true)

t = time + random(0,-30);

p.position.valueAtTime(t);

I got the offset random to work. but then realized I would need the seed number to change as well. so I added another random. and it works. Thanks for helping me down the rabbit hole. I would still like to have control over the offset and not have it be random. but this works as a plan B.

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

LATEST

Great!

To control this, you'll need a lot of either layers or keyframes or lines to code in a script...

Nice weekend,

Martin

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Fascinating...

I think it's the "offset = seedRandom(3,true);" part. This is actually wrong.

I would write it:

seedRandom(3,true);

offset = random(0,30);

comp("Comp 1").layer("Null 1").position.valueAtTime(time + offset);

Give it a try.

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Sadly, expressions aren't able to "see" the project structure, therefore I think this is not possible. You can try to find a way with "index" variable but this will end up having 100+ layers with sliders.

I think the best way would be to put your slider at the pre-comp and using "thisComp" for referring. Then you can duplicate this.

However, these are just general thoughts. Can you give us a more detailed view into your project?

Votes

Translate

Translate

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 guidelines
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

This might be a bit crazy, but if all your pre-comps are in one comp and are displayed one another (not two at a time) and you are willing to set A LOT of keyframes, you might could do this with two sliders only:

One slider for the offset, another as "selector". The selector should be rounded to full numbers with Math.floor() or you will need those "linear in, hold out" - keyframes.
Your script will be something like this:
myindex = thisComp.thisLayer(index); // maybe just "index" will do it too
if (myindex == comp("slidercomp").layer("sliders").effect("slider")("selector")){
myoffset = comp("slidercomp").layer("sliders").effect("slider")("offsetslider")
... // rest of your code
};
Then you can use keyframes on the selector-slider to refer to the pre-comp and set the offset.
Just a thought, never did it by myself.

Votes

Translate

Translate

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 guidelines