A script to link a value on one layer to different ranges of frames from multiple layers?

Explorer ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Greetings,

 

Could anyone provide a script to link a value like Scale on Layer3 to the Scale values of Layer1 for frames 1 to 48 and then link the Layer3 Scale values to frames 49 to 96 of Layer2?

 

Thanks for any help on this 🙂

TOPICS
Expressions , How to , Scripting

Views

180

Likes

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

Adobe Community Professional , Jul 29, 2022 Jul 29, 2022

Nothing jumps out at me, but I think I'd probably set it up more like this (I haven't tested this at all, so it's probably not exactly right):

frames = [102770,102796,102865,102968,103018,103188,103208,103318,103411,103457,103486,103572,103608,103666,103751,103780,103809,103846,104039];
tracks  = ["01",    "01b",   "02",     "03",    "04",     "05",    "06",     "07",    "08",    "09",     "10",    "11",     "12",    "13",    "14",     "15",    "16",    "17",     "18"];
val = value;
f = timeToFr
...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

It will probably be something like this, depending on what you want to happen after frame 96:

if (time < framesToTime(48)){
  thisComp.layer("Layer1").scale;
}else if (time < framesToTime(96)){
  thisComp.layer("Layer2").scale;
}else{
  value;
}

Likes

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
Explorer ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Awesome, thank you very much!!!

Likes

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
Explorer ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hi Dan this is the script I wrote based on what you showed, but it seems to not be working past the track01 values. AE didn't return any errors, it just doesnt' change the value of "Center" beyond frame 102770. Any more help on this will be much appreciated, thanks again.

 

var b=102770 
var c=102796 
var d=102865
var e=102968
var f=103018
var g=103188
var h=103208
var k=103318
var m=103411
var n=103457
var p=103486
var q=103572
var r=103608
var s=103666
var t=103751
var u=103780
var v=103809
var w=103846
var x=104039

if (time < framesToTime(b)){
  thisComp.layer("track01").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(b) && time < framesToTime(c)){
  thisComp.layer("track01b").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(c) && time < framesToTime(d)){
  thisComp.layer("track02").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(d) && time < framesToTime(e)){
  thisComp.layer("track03").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(e) && time < framesToTime(f)){
  thisComp.layer("track04").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(f) && time < framesToTime(g)){
  thisComp.layer("track05").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(g) && time < framesToTime(h)){
  thisComp.layer("track06").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(h) && time < framesToTime(k)){
  thisComp.layer("track07").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(k) && time < framesToTime(m)){
  thisComp.layer("track08").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(m) && time < framesToTime(n)){
  thisComp.layer("track09").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(n) && time < framesToTime(p)){
  thisComp.layer("track10").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(p) && time < framesToTime(q)){
  thisComp.layer("track11").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(q) && time < framesToTime(r)){
  thisComp.layer("track12").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(r) && time < framesToTime(s)){
  thisComp.layer("track13").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(s) && time < framesToTime(t)){
  thisComp.layer("track14").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(t) && time < framesToTime(u)){
  thisComp.layer("track15").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(u) && time < framesToTime(v)){
  thisComp.layer("track16").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(v) && time < framesToTime(w)){
  thisComp.layer("track17").effect("Mocha Pro")("Center");
}else if (time >=framesToTime(w) && time < framesToTime(x)){
  thisComp.layer("track18").effect("Mocha Pro")("Center");
}else{
  value;
}

 

Likes

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
Adobe Community Professional ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Nothing jumps out at me, but I think I'd probably set it up more like this (I haven't tested this at all, so it's probably not exactly right):

frames = [102770,102796,102865,102968,103018,103188,103208,103318,103411,103457,103486,103572,103608,103666,103751,103780,103809,103846,104039];
tracks  = ["01",    "01b",   "02",     "03",    "04",     "05",    "06",     "07",    "08",    "09",     "10",    "11",     "12",    "13",    "14",     "15",    "16",    "17",     "18"];
val = value;
f = timeToFrames(time);
for (i = 0; i < frames.length; i++){
  if (f < frames[i]){
    val = thisComp.layer("track" + tracks[i]).effect("Mocha Pro")("Center");
    break;
  }
}
val

Likes

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
Explorer ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Thanks for the info Dan. I'll give this version a try and follow up with the results. Could you please let me know what these do or mean?

i =0

i++
track[i]

 

Thanks again!

 

Likes

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
Adobe Community Professional ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

i is an integer.  The line:

for (i = 0; i < frames.length; i++){

is telling After Effects that starting at 0 (i=0), while i is less then the number of items in "frame" (frames.length)  run through everything in the braces ( { )  for i being 0, 1, 2, 3 etc... (that what the i++ means - add 1 to i).

 

With track[i] inside the braces, that means that AE will use the number i to pick the item in the track array:L

 

  • When i = 0, track[i] = "01"
  • i = 1, track[i] = "01b"
  • etc...

 

 

Likes

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
Explorer ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Great thank you very much for the clarification!!

Likes

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
Explorer ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Hi Dan,

Still not having any luck with it, the centerpoint value stop changing at the end of the "track01" and never go onto "track01b". I entered the expression as you had it, but just eliminated the spaces. No errors, it just doesn't progress passed the Mocha Pro "track01" values. Any more thoughts on this will be much appreciated 🙂

 

frames = [102770,102796,102865,102968,103018,103188,103208,103318,103411,103457,103486,103572,103608,103666,103751,103780,103809,103846,104039];
tracks  = ["01","01b","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18"];
val = value;
f = timeToFrames(time);
for (i = 0; i < frames.length; i++){
  if (f < frames[i]){
    val = thisComp.layer("track" + tracks[i]).effect("Mocha Pro")("Center");
    break;
  }
}
val

 

Likes

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
Adobe Community Professional ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Depending on your frame rate, I'd expect it to stay at track01 for an hour or so. How long is your comp?

Likes

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
Explorer ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Hi Dan,

My comp is only 57 seconds long, 24fps. I'm basing my frame number on the timecode that shows up when I put the AE timecode plug-in on an adjustment layer that is giving me back the comp timecode reading.

Likes

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
Adobe Community Professional ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

It's hard to test without having your exact setup, so I'm kind of out in the weeds here, but try changing this:

f = timeToFrames(time);

to this:

f = timeToFrames(time+thisComp.displayStartTime);

 

Likes

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
Explorer ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Thanks for your help Dan, I'll give this a try later today. Also just wondering is there a way I could script a text output to and adjustment layer to also see what frame number and what layer the main Mocha "Center" script is pulling from, to also maybe help in troubleshooting. Thanks again!!

Likes

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
Explorer ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Oh an do the scripts always need to have a frame number as input (e.i. 102770 or can I just input the frame as time, e.g. 1:02:05:21? Does it matter or is it generally just easier to use a frame number when the frame is not some ridiculously high number like 102770, etc? Thanks for any clairofication on this 🙂

Likes

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
Adobe Community Professional ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Expressions are set up to work with time (in seconds). There are functions provided to convert to and from frames and to convert from seconds to time code. But if you want to provide time code as the input, you'll need to create a function to do the conversion.

Likes

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
Adobe Community Professional ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

You could try changing the last line to:

"track" + tracks[i] + " " + f

and applying it to a text layer.

 

Likes

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
Explorer ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Hi Dan, 

This is what I pasted in a text layer, but I'm just getting changing errors telling me "track01" doesn't exist, but then when I click out and click back in it tells me "track13" doesn't exist or some other track when I click out then back in. Please let me know if I needed to copy/paste it into the text layer in another way. Thanks again.

frames = [102770,102796,102865,102968,103018,103188,103208,103318,103411,103457,103486,103572,103608,103666,103751,103780,103809,103846,104039];
tracks  = ["01","01b","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18"];
val = value;
f = timeToFrames(time+thisComp.displayStartTime);
for (i = 0; i < frames.length; i++){
  if (f < frames[i]){
    val = thisComp.layer("track" + tracks[i] + " " + f).effect("Mocha Pro")("Center");
    break;
  }
}
val

Likes

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
Adobe Community Professional ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Fort the text layer, I think I'd try it like this:

frames = [102770,102796,102865,102968,103018,103188,103208,103318,103411,103457,103486,103572,103608,103666,103751,103780,103809,103846,104039];
tracks  = ["01","01b","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18"];
val = value;
f = timeToFrames(time+thisComp.displayStartTime);
for (i = 0; i < frames.length; i++){
  if (f < frames[i]){
    break;
  }
}
"track" + tracks[i] + " " + f

Likes

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
Explorer ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

LATEST

Hi Dan, pleasant update this time. I realized the timecode frame number track I was looking at was set to "Layer" and not "Comp". I noticed the discprepancy when I changed my timeline time display to show frame number. Once I corrected all the frame numbers in the array to correctly match the timeline frame number, the Mocha Pro "Center" x,y was now linking as expected to each range. And I was able to get the text layer confirmation on this once I corrected the frame array. Thanks again for all your help!!!

Likes

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