Skip to main content
olivu1568674
Known Participant
August 8, 2018
Answered

Is there any way to translate the whole content of the document uisng JSX script?

  • August 8, 2018
  • 2 replies
  • 2024 views

We can move layer or a group as follows:

app.activeDocument.activeLayer.translate(100,100);

Is there any way to move whole content like above( Without iterating layer by layer )?

This topic has been closed for replies.
Correct answer Kukurykus

Select layer(Set)s and use this code:

function sTT(v) {return stringIDToTypeID(v)}

function mve() {

     (ref1 = new ActionReference()).putEnumerated

     (sTT('layer'), sTT('ordinal'), sTT('targetEnum'));

     (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

     dsc2 = new ActionDescriptor(); (function(v) {

          for(i = 0; i < (arr = ['horizontal', 'vertical']).length; i++) {

               dsc2.putUnitDouble(sTT(arr), sTT('pixelsUnit'), v)

          }

     })(arguments)

     dsc1.putObject(sTT('to'), sTT('offset'), dsc2)

     executeAction(sTT('move'), dsc1)

}

mve(100, 100)

2 replies

JJMack
Community Expert
Community Expert
August 8, 2018

Image size will also change all layers sizes.

JJMack
olivu1568674
Known Participant
August 14, 2018

Thank you.

I want to move the layers. Not to resize.

JJMack
Community Expert
Community Expert
August 14, 2018

If you want to move all layer at once. if the document has a background layer you would first need to convert it to a normal layer target all layer then move all with a single transform the only moves the targeted layers does not resize.  Part of what was the background layer will be outside the document canvas area. Layers other then Photoshop's special Background layer can be any size and position anywhere relative to the document canvas.   Photoshop Background is a special case.  It is the bottom layer in the layers stack  it Transparency is locked  the layers opacity and fill  100% the layer is canvas size and can not be moved.

You can target a layer group and move its layers  with a single translate.     You can target any number of layers throughout  the layer stack and move the all targeted layers at once with a single translate. You can target all  layer  except the background and move them with a single translate.

JJMack
Kukurykus
KukurykusCorrect answer
Legend
August 8, 2018

Select layer(Set)s and use this code:

function sTT(v) {return stringIDToTypeID(v)}

function mve() {

     (ref1 = new ActionReference()).putEnumerated

     (sTT('layer'), sTT('ordinal'), sTT('targetEnum'));

     (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

     dsc2 = new ActionDescriptor(); (function(v) {

          for(i = 0; i < (arr = ['horizontal', 'vertical']).length; i++) {

               dsc2.putUnitDouble(sTT(arr), sTT('pixelsUnit'), v)

          }

     })(arguments)

     dsc1.putObject(sTT('to'), sTT('offset'), dsc2)

     executeAction(sTT('move'), dsc1)

}

mve(100, 100)

olivu1568674
Known Participant
August 14, 2018

Thanks a lot.
Is there any way to select multiple layers, if we got references to layers?

Kukurykus
Legend
August 14, 2018

What kind of references? btw if my code is answer for your question, mark it as correct solution