Scale layer down relative to comp

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC

I am working on a script that takes text out of a file and copies it into existing text layers. I'd like to add in a function that scales the text layer down if it is too large for the screen. This is what I have basically.

var proj = app.project;

var myComp = proj.item(1);

var myLayer = myComp.layer(1);

var layerSize = myLayer.width * (myLayer.scale * .01)

while (layerSize >= 300){

var sclIncr = 100;


sclIncr = sclIncr - 2


The problem I have is myLayer.scale doesn't return a value, it returns an array. How can I get one of the values out of the array?

Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

myLayer.scale returns the actual scale property. To test this, put in the line:

You'll get an alert that says: [object Property]. To access the scale value use:

That gives you the 2 or 3 dimensional scale value array. To access a single value
you'd use something like:

With arrays you access a single value by specifying the index, i.e that value's
position in the array, starting with an index of 0. (x is [0], y is [1] and z is [2])

I realise this is a work in progress but there are a few other things I noticed.
The 'while' loop currently either won't run (if layerSize is less than 300) or will
run in an infinite loop (layerSize is greater or equal to 300) as there is nothing
inside the loop that changes the 'layerSize' variable.

It looks like you want to scale the layer down to a certain size, maybe something
like this would work:

if (layerSize > myComp.width) {
var multiplier = myComp.width / layerSize;
myLayer.scale.setValue(myLayer.scale.value * multiplier);

I've used myComp.width, but you could replace them with '300'.

Also, it's generally good practice to put open/close brackets at the start/end of
your script to limit the scope of the variables you define. There's a good
explanation for this on Dan Ebbert's site: ... ted-3.html

Paul T
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC

Thanks for te reply Paul. I am still pretty new at scripting, I have to hack my way through everything.

This site is a great idea, I hope it catches on fast. I think After Effects is much more potent now that you can script it.

Take care...

Posts: 1
Joined: April 9th, 2015, 9:49 pm

There doesn't seem to be anything in the Scripting Guide to suggest this is
Post Reply