Copy link to clipboard
Copied
I have "Main Comp" with 30 seconds of time, and inside have:
A footage called "Forest"
I want to replace Footage which can vary of time, being greater, like 59 seconds for example, so I need wich the "Main Comp", also adjusts according to Footage time duration. "Main Comp" staying with 59 seconds.
Thanks.
I try this:
var myComp = app.project.activeItem;
myComp.duration = myLayer.property("Footage").duration
That didn't work because layer objects do not have a duration attribute. The math has to be done manually. Normally you take the layer outPoint minus the inPoint to get the layer duration.
...var myComp = app.project.activeItem;
var myLayer = myComp.layer(1); //Assumes layer 1 is your choice
myComp.duration = (myLayer.outPoint - myLayer.inPoint); //Assumes the layer is normal and not reve
Copy link to clipboard
Copied
You can go into your composition settings and adjust it to be a longer period of time. Is that what you're asking for?
Copy link to clipboard
Copied
Yeah, but i need to write a Script.
I try this:
var myComp = app.project.activeItem;
myComp.duration = myLayer.property("Footage").duration
Not work.
Copy link to clipboard
Copied
If you just want to buy a script, this should do it: Trim Comp to Contents - aescripts + aeplugins - aescripts.com
Copy link to clipboard
Copied
Thank you very much, for your attention.
Copy link to clipboard
Copied
No problem! For the record, that script was the first solution when I typed After Effects script comp footage length into Google
Copy link to clipboard
Copied
Okay. ![]()
Copy link to clipboard
Copied
I was just Googling for a script that does this... of course it would lead me here to you of all people!
Copy link to clipboard
Copied
I try this:
var myComp = app.project.activeItem;
myComp.duration = myLayer.property("Footage").duration
That didn't work because layer objects do not have a duration attribute. The math has to be done manually. Normally you take the layer outPoint minus the inPoint to get the layer duration.
var myComp = app.project.activeItem;
var myLayer = myComp.layer(1); //Assumes layer 1 is your choice
myComp.duration = (myLayer.outPoint - myLayer.inPoint); //Assumes the layer is normal and not reversed
This won't be bullet proof though because a layer can also be reversed, which places the inPoint after the outPoint, so you would need to flip the order. You would say inPoint minus the outPoint.
var myComp = app.project.activeItem;
var myLayer = myComp.layer(1); //Assumes layer 1 is your choice
myComp.duration = (myLayer.inPoint - myLayer.outPoint); //Assumes the layer is reversed
Copy link to clipboard
Copied
Oh, Yeah! Brilliant! Good job!
When you say:
"This won't be bullet proof though because a layer can also be reversed"
It is so complex, where and how can I learn to script programming.
Thank you so much!
Copy link to clipboard
Copied
What would a layer reversed?
A composition layer can be stretched in the negative direction to run backwards in the timeline. You can see a reversed layer easily by looking for a hashed red line on the lower part of the layer in the timeline (the yellow layer in the photo). Layers that have been reversed now have their coded inPoint located on the opposite end.

It is so complex, where and how can I learn to script programming.
Can suggest me please?
I put together a large video training series about ExtendScript awhile back that may be helpful overall in learning After Effects scripting.
Pro Video Coalition - After Effects ExtendScript Training Complete Series by David Torno
Copy link to clipboard
Copied
Perfect! I understand. ![]()
I'll watch your videos, they are incredible. Thanks! ![]()
Great opportunity. ![]()
Copy link to clipboard
Copied
If it is not asking too much, I need a last help, please.
linear (t, tMin, tMax, value1, value2)
Thanks.
Copy link to clipboard
Copied
Accessing another comp via expressions uses the comp method. You supply the name of the comp to this method. The name needs to be unique though as it cannot tell which comp you want if there are more than one with the same name. I believe it chooses the top most one in the project panel.
comp("TheCompNameYouWant").duration;
Copy link to clipboard
Copied
Good, now I know access a Comp; but, how to represent a expression value of a property layer, to use as value, putting in Script?
Copy link to clipboard
Copied
This is just a quick example of expression value access. This assumes that item 1 in the project is a composition and layer 1 within that comp has an Opacity property
.valueAtTime() method allows access to values throughout your timeline on a layer property. It requires two arguments, first being the time to evaluate in the timeline and the second is if the value should include any expression that may be applied.
app.project.item(1).layer(1).property("Opacity").valueAtTime(1,false); //"false" gets value including expression evaluation, "true" excludes expression evaluation.
Copy link to clipboard
Copied
Ok, I understand.
linear (t, tMin, tMax, value1, value2) I have this expression in Anchor Point.
I want to use only the "tMax" value of expreesion (which is in Anhcor Point property of a layer), in Script.
But I did not know how to represent this property expression "tMax" part, in Script.
The Script is based in expression value of Anchor Point property of a layer.
Thanks.
Copy link to clipboard
Copied
I want to use only the "tMax" value of expreesion (which is in property of layer), in Script.
Ah, ok, I think I know what you are after. To reuse my example from above...
app.project.item(1).layer(1).property("Opacity").expression
".expression" will get you the actual written expression in text form. Now you would need to parse that text looking for the tMax value entry. If the tMax entry was simply a number then it will be easier to retrieve, but if the value was created through code (thisComp, or comp("name"), etc...), then it's WAY more difficult to determine since you would need to apply that code to a text layer's source text property (a new layer you need to create then delete when you're done) to then read the result. Very involved.
Copy link to clipboard
Copied
Okay! I will try now. Your help has been very important for me begin to understand how to work with Scripts.
I am very grateful for that. ![]()
Copy link to clipboard
Copied
You are welcome. Good luck to you.
Copy link to clipboard
Copied
I am able to access other comp now, by index layer number, I will try do reference by comp name.
I try: comp("TheCompNameIWant")
But no got it.
Copy link to clipboard
Copied
Hey! I'm Happy!
After many tries. I finally got it! With your tips, I make a Clone of "tMax" value, simulating within the script.
var myComp = app.project.activeItem;
var tMax;
var l;
if(app.project.item(7).layer(5)("Transform")("Opacity").value==100){
l=270;
}else{
l=0;
}
var scale = app.project.item(12).layer(2)("Contents")(1)("Transform")("Scale").valueAtTime(1,false)[0];
var size = app.project.item(12).layer(2)("Contents")(1)("Contents")(1)("Size").valueAtTime(1,false)[0];
var p = app.project.item(8).layer(2)("Effects")(15)("Slider").value;
var s = scale*size/100;
var w=app.project.item(7).width-l;
if(s>w){
tMax=(s+l)/p;
}else{
tMax=20;
}
myComp.duration = tMax;
Just could not do refers to the layers within the active.Item; (composition selected);
Only with layers in numerical order (index) in the project panel.
Thank you very much! ![]()
Copy link to clipboard
Copied
var myComp = app.project.activeItem;
var myLayer = myComp.layer("Footage").source.layer("Video");
myComp.duration = (myLayer.outPoint - myLayer.inPoint);
I said:
- Is there any way to use names instead of index in Script?
Oh yeah! I got use names in Script!
I said too:
- How to access layers in composition selected instead of the composition on project panel?
Also I got through "activeItem" and ".source".
Your videos are very helpful, I was able quick to learn in a week. Thanks. ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more