Photoshop: Translate() inside suspendHistory() destroys group if doc has an active selection

  • 2
  • Problem
  • Updated 2 months ago
  • (Edited)
What is happening (PS CC 2019):
  1. Script groups active layers
  2. Script uses translate() to nudge the layers
    • The layers are nudged as a group...
    • The group disappears
Requirements for this to happen:
  1. Group is created inside the script.
    • If created before the script is run, it doesn't disappear.
    • Doesn't seem to make any difference if it's inside suspendHistory() or not.
  2. Translate() has to be inside suspendHistory()
  3. Doc has to have an active marquee selection
app.runMenuItem( stringIDToTypeID('groupLayersEvent') ); 
app.activeDocument.suspendHistory("Align to selection", "alignToSelection()");function alignToSelection() {    app.activeDocument.activeLayer.translate( 20, 20 );}
Here's a gif where I run the script and undo twice.



I got around it in my script by deselecting before translate. In my script, all things happen inside the suspendHistory function. I just wanted to make sure it's clear that only translate needs to be inside suspendHistory for this to happen.
Photo of Joonas Pääkkö

Joonas Pääkkö

  • 4 Posts
  • 1 Reply Like

Posted 2 months ago

  • 2
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 864 Posts
  • 214 Reply Likes
I think there is several ways how to move layers. And one of kind has aggregated history. Because if you hold arrow key you don't want to have 100 history steps per each nudge. So it might be aggregated into 1-3 history steps. There is not much actions with this behavior and I think suspend history does not count with it. Maybe you could use regular transformation.
Photo of Joonas Pääkkö

Joonas Pääkkö

  • 4 Posts
  • 1 Reply Like
Well, like I very briefly mentioned at the bottom of the post, it works just fine as long as I make sure to deselect before using translate. This works in my case since I got what I wanted from the marquee selection by the time I use translate. 
(Edited)
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 864 Posts
  • 214 Reply Likes
I believe that you need to do some action responsible for stopping aggregation