Skip to main content
Inspiring
May 10, 2021
Answered

How to get the stretch% of a layer with an expression

  • May 10, 2021
  • 2 replies
  • 1172 views

I want to know how to get the stretch% of a layer with an expression
With Script

app.project.item (index) .layer (index) .stretch


It seems that you can read and write with
Writing with an expression will result in an error.
If you know, please let me know.

This topic has been closed for replies.
Correct answer TakashiAoki

How to get the stretch value of the layer with the expression, I solved it myself, so I will post it for the time being.
It's a bit of a hassle, but it's also a way to get the stretch value by placing a marker at the outTime position where there is no direct way to get it.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2 replies

TakashiAokiAuthorCorrect answer
Inspiring
May 19, 2021

How to get the stretch value of the layer with the expression, I solved it myself, so I will post it for the time being.
It's a bit of a hassle, but it's also a way to get the stretch value by placing a marker at the outTime position where there is no direct way to get it.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Known Participant
May 10, 2021

emm.. It's seems like cannot get "stretch" value directly,

I can only get video footage "stretch" value,

var l = thisComp.layer(2);
var stretchValue = l.outPoint / l.source.duration;

 

But this will be error with solid layer、image layer and so on which ".source.duration == 0"....

I can't find any other ways to get strech value...

Mathias Moehl
Community Expert
Community Expert
May 10, 2021

Sounds like a good workaround! You could handle layers with source.duration == 0 in an if/else

 

if(l.source.duration ==0) {
   // layer cannot be stretched
   stretchValue = 1;
}
else {
   stretchValue = l.outPoint /l.source.duration;
}
Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Known Participant
May 10, 2021

Emm.. I think this way will be better:

we can't set `stretchValue = 1` when `source.duration == 0` because designer will change this value within an solid layer.

we should define an variable called `defaultOutPoint`, it's value equals to an layer (such as solid, or image layer) `outPoint` value when stretch set to 100%;

then ,

stretchValue = l.outPoint / defaultOutPoint.

like this:

var l = thisComp.layer(2);
var defauleOutPoint = l.source.duration;

if (defauleOutPoint == 0) {
    // set this value manually
    defauleOutPoint = 3.36;
}

l.outPoint / defauleOutPoint;