Photoshop: Javascript function artLayer.translate makes 1px size layers randomly disappear

  • 1
  • Problem
  • Updated 4 years ago
  • (Edited)
Photoshop Javascript scripting function artLayer.translate(dx, dy) has an issue that causes 1px high layers to sometimes disappear when moved vertically. You can replicate this with below script and linked PSD-file in at least Windows Photoshop CS6.

var HEIGHT = 5

app.preferences.rulerUnits = Units.PIXELS

var doc = app.activeDocument

for (var i=0; i < doc.artLayers.length; i++) {

var layer = doc.artLayers[i]

doc.activeLayer = layer

doc.resizeCanvas (doc.width, doc.height + HEIGHT, AnchorPosition.BOTTOMCENTER)

layer.translate(0, -HEIGHT*(i+1))

Photo of Matias Kiviniemi

Matias Kiviniemi

  • 8 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Jeffrey Tranberry

Jeffrey Tranberry, Sr. Product Manager, Digital Imaging

  • 15078 Posts
  • 2141 Reply Likes
For a workaround you can move the resizeCanvas to the end like this: works in CS6 and CC 2014:

doc.resizeCanvas (doc.width, doc.height + HEIGHT * i, AnchorPosition.BOTTOMCENTER)