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

Script to Comp Duration

Engaged ,
Jun 18, 2015 Jun 18, 2015

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.

TOPICS
Scripting
16.0K
Translate
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

Advocate , Jun 18, 2015 Jun 18, 2015

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

...
Translate
Community Expert ,
Jun 18, 2015 Jun 18, 2015

You can go into your composition settings and adjust it to be a longer period of time. Is that what you're asking for?

Translate
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
Engaged ,
Jun 18, 2015 Jun 18, 2015

Yeah, but i need to write a Script.

I try this:

var myComp = app.project.activeItem;

myComp.duration = myLayer.property("Footage").duration

Not work.

Translate
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
Community Expert ,
Jun 18, 2015 Jun 18, 2015

If you just want to buy a script, this should do it: Trim Comp to Contents - aescripts + aeplugins - aescripts.com

Translate
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
Engaged ,
Jun 18, 2015 Jun 18, 2015

Thank you very much, for your attention.

Translate
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
Community Expert ,
Jun 18, 2015 Jun 18, 2015

No problem! For the record, that script was the first solution when I typed After Effects script comp footage length into Google

Translate
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
Engaged ,
Jun 18, 2015 Jun 18, 2015

Okay.

Translate
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 ,
Apr 26, 2019 Apr 26, 2019
LATEST

I was just Googling for a script that does this... of course it would lead me here to you of all people!

Translate
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
Advocate ,
Jun 18, 2015 Jun 18, 2015

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

Translate
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
Engaged ,
Jun 18, 2015 Jun 18, 2015

Oh, Yeah! Brilliant! Good job!

When you say:

"This won't be bullet proof though because a layer can also be reversed"

  • What would a layer reversed?

It is so complex, where and how can I learn to script programming.

  • Can suggest me please?


Thank you so much!

Translate
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
Advocate ,
Jun 18, 2015 Jun 18, 2015

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.

Screen Shot 2015-06-18 at 6.19.17 PM.png

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

Translate
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
Engaged ,
Jun 18, 2015 Jun 18, 2015

Perfect! I understand.

I'll watch your videos, they are incredible. Thanks!

Great opportunity.

Translate
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
Engaged ,
Jun 19, 2015 Jun 19, 2015

If it is not asking too much, I need a last help, please.

  • I have a Shape which have a expression in Anchor Point property, this expression works as keyframes:

linear (t, tMin, tMax, value1, value2)

  • The path of the Main Comp (where it will use the Script) to the Anchor Point of Shape is:
  1. Shape "Bar"
  2. Sub Precomp "Scroll"
  3. Precomp "Lower Third"
  4. Comp "Main"

Flowchart.PNG

  • I need which the Script cut Main comp time duration, in accordance "tMax" value.

Thanks.

Translate
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
Advocate ,
Jun 23, 2015 Jun 23, 2015

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;

Translate
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
Engaged ,
Jun 23, 2015 Jun 23, 2015

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?

Translate
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
Advocate ,
Jun 23, 2015 Jun 23, 2015

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.

Translate
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
Engaged ,
Jun 23, 2015 Jun 23, 2015

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.

Translate
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
Advocate ,
Jun 23, 2015 Jun 23, 2015

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.

Translate
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
Engaged ,
Jun 23, 2015 Jun 23, 2015

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.

Translate
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
Advocate ,
Jun 24, 2015 Jun 24, 2015

You are welcome. Good luck to you.

Translate
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
Engaged ,
Jun 24, 2015 Jun 24, 2015

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.

Translate
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
Engaged ,
Jun 27, 2015 Jun 27, 2015

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.

  • Is there any way to use names instead of index in Script?
  • How to access layers in composition selected instead of the composition on project panel?

Thank you very much!

Translate
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
Engaged ,
Jun 27, 2015 Jun 27, 2015

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. 

Translate
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