Copy link to clipboard
Copied
Hello, please help.
How to add the condition to this script: if the height is from n to n (for example 13000-14000), then ...
function getLayerSizeToCopy(){
var layer = activeDocument.activeLayer; //Grab the currently selected layer
// Calculate length and width based on the rectangular bounds of the selected layer
var length = layer.bounds[2]-layer.bounds[0]; //Grab the length
var width = layer.bounds[3]-layer.bounds[1]; //Grab the width
// Remove pixels from the length/width "200 px" => "200"
length = length.toString().replace(' px', '');
width = width.toString().replace(' px', '');
prompt( "Layer Size: ", length + ", " + width );
}
getLayerSizeToCopy();
I'm not sure what you want to do with the conditional if statement, but here it is in you script, with an alert letting you know if the layer height is between 100 and 1000, and another alert if the response to the prompt is with the range of 100 to 1000:
function getLayerSizeToCopy(){
var layer = activeDocument.activeLayer; //Grab the currently selected layer
// Calculate length and width based on the rectangular bounds of the selected layer
var length = layer.bounds[2]-layer.bound...
Copy link to clipboard
Copied
Length is normally considered width. I normally use height. Also, you changed the measurement values to a string. You should keep them as numbers, like;
var layerHeight = layer.bounds[3].value-layer.bounds[1].value;
For your question try this (I'm using layerHeight:
if(layerHeight>13000&&layerHeight<14000){// code here
}
Copy link to clipboard
Copied
Thank you, redid the script at your prompt, it worked! 🙂
Copy link to clipboard
Copied
I'm not sure what you want to do with the conditional if statement, but here it is in you script, with an alert letting you know if the layer height is between 100 and 1000, and another alert if the response to the prompt is with the range of 100 to 1000:
function getLayerSizeToCopy(){
var layer = activeDocument.activeLayer; //Grab the currently selected layer
// Calculate length and width based on the rectangular bounds of the selected layer
var length = layer.bounds[2]-layer.bounds[0]; //Grab the length
var width = layer.bounds[3]-layer.bounds[1]; //Grab the width
// Remove pixels from the length/width "200 px" => "200"
length = length.toString().replace(' px', '');
width = width.toString().replace(' px', '');
if(width>100&&width<1000){//tells you if the layer size is within the range of 100 to 1000
alert('height is in range')
}
else{alert('height is NOT in range')}
var promptResult = prompt( "Layer Size: ", length + ", " + width );
var promptArray = promptResult.replace(/\s/g, "").split(',');
if(promptArray[1]>100&&promptArray[1]<1000){alert ('The number entered is in range')}//Tells you if the response to the prompt is within the range of 100 to 1000
else{alert('The number entered is out of range.')}
}
getLayerSizeToCopy();
Copy link to clipboard
Copied
As I mentioned before about your use of width and length, which are considered the same thing. You should use these terms:
Copy link to clipboard
Copied
The code was taken from the network, it was also not convenient for me that the value was different, but at first I couldn’t change it. With your help I changed it to the height and removed some values. Everything works great.
Thank you so much!
Copy link to clipboard
Copied
Glad it's working, and good that you changed the values, as it's confusing the way it was originally written.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more