Skip to main content
Known Participant
September 3, 2021
Answered

Crop with scripts failed,Help please.

  • September 3, 2021
  • 1 reply
  • 379 views

Hi~,

when i use script command 'app.activeDocument.crop(layer.bounds)', error message popout:The command cannot be completed because the affected area is empty or does not overlap the canvas.

before this action, i have set all layers invisible, then:

   layer.visible = true;

   app.activeDocument.activeLayer = layer;

   app.activeDocument.crop(layer.bounds);//this cause error

   _saveImage(ffname);//export layer as png

   layer.visible = false;

 

What should i do?

 

Thanks so much

This topic has been closed for replies.
Correct answer JJMack

Target a layer that has some Pixels.  You document actives layer seems void of pixels. Its bounds is null. The Layer object you targeted " app.activeDocument.activeLayer = layer;" seems to be empty or one the is data for some adjustment or all of the layer pixels are off canvas none are positioned over the canvas.  Crop can not delete the document canvas. Is not a valid operation.

1 reply

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
September 3, 2021

Target a layer that has some Pixels.  You document actives layer seems void of pixels. Its bounds is null. The Layer object you targeted " app.activeDocument.activeLayer = layer;" seems to be empty or one the is data for some adjustment or all of the layer pixels are off canvas none are positioned over the canvas.  Crop can not delete the document canvas. Is not a valid operation.

JJMack
hui5C21Author
Known Participant
September 3, 2021

Thank you so much.

I added condition "layer.bounds[0] < layer.bounds[2] && layer.bounds[1] < layer.bounds[3]" before actons,it works perfect.