Skip to main content
Participant
October 2, 2020
Question

[Script] Duplicate and add same scale value

  • October 2, 2020
  • 1 reply
  • 202 views

How to write a script that duplicate a shape, and adds the same value to the scale.

 

For example let's say I have this shape:

After running the script it will become like this:

It keeps increasing by 20%.

Thank you!

This topic has been closed for replies.

1 reply

Inspiring
October 2, 2020

You can do this really easy with just an expression in the scale.

x = index * 20 + value[1];
[x,x]

You may need to offset the index if the shapes aren't at the top of the layer stack. You can do this manallly, hooking it up to a slider or make a null layer that sits at the top of these layers and use 

-parent.index

If you want to do it via script.

var selectedLayer = app.project.activeItem.selectedLayers[0];
var multiplier = 10;

for (var i = 1; i <= multiplier; i++){
        var dupedLayer = selectedLayer.duplicate();
        amount = dupedLayer.transform.scale.value[0] + 20 * i
        dupedLayer.transform.scale.setValue([amount,amount])
    }

If the shapes have animation on them, then it gets a bit more complicated.