Skip to main content
Participating Frequently
May 17, 2013
Answered

action or script to move selection to specified layer?

  • May 17, 2013
  • 1 reply
  • 3119 views

Hi all,

i have a piece of art on "Layer 1" that i need to shrink and duplicate to "Layer 2". I do this many many times a day so i was hoping someone could help me with a script? The two layers are always named the same. I'm working in CS5.


Thanks a lot!

This topic has been closed for replies.
Correct answer CarlosCanto

here you go

var scale = 50; // 50 means 50%, change this to your needs

var idoc = app.activeDocument;

var ilayer = idoc.layers['Layer 2'];

var sel = idoc.selection;

var selen = sel.length;

for (i=0; i<selen; i++) {

    var pgItem = sel.duplicate();

    pgItem.resize (scale, scale, true, true, true, true, scale, Transformation.CENTER)

    pgItem.move(ilayer, ElementPlacement.PLACEATEND);

}

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
May 17, 2013

here you go

var scale = 50; // 50 means 50%, change this to your needs

var idoc = app.activeDocument;

var ilayer = idoc.layers['Layer 2'];

var sel = idoc.selection;

var selen = sel.length;

for (i=0; i<selen; i++) {

    var pgItem = sel.duplicate();

    pgItem.resize (scale, scale, true, true, true, true, scale, Transformation.CENTER)

    pgItem.move(ilayer, ElementPlacement.PLACEATEND);

}

pixxxelschubser
Community Expert
Community Expert
May 17, 2013

Hello CarlosCanto,

one question:

why you use the move-methode instead:

//...

for (i=0; i<selen; i++) {

    var pgItem = sel.duplicate(ilayer, ElementPlacement.PLACEATEND);

    pgItem.resize (scale, scale, true, true, true, true, scale, Transformation.CENTER)

}

What advantages or disadvantages are there?


regards

CarlosCanto
Community Expert
Community Expert
May 18, 2013

Hi pixxxel, I don't think there's a difference, I typed that without thinking, that was the first thing it came to my head...

...but one thing is true about my writing style, if a line starts to get too long to the point where I have to scroll left and right to see all of it, I try to break it as much as I can to make it fit to my screen, this is not the case, but if it was, I would have...

...changed this

pgItem.resize (scale, scale, true, true, true, true, scale, Transformation.CENTER);

to this...

var refpoint = Transformation.CENTER;

pgItem.resize (scale, scale, true, true, true, true, scale, refpoint);