Resize Canvas Script
Copy link to clipboard
Copied
I an using a script to increase the canvas size by 211 pixels on the right
The function is called from a button click.
Button Click
$("#btn_Canvas_Size").click(function () {
csInterface.evalScript('Canvas_Bigger()');
});
Function Called from Button
function Canvas_Bigger() {
var srcDoc = app.activeDocument;
// get original width and height
var w = srcDoc.width.value;
var h = srcDoc.height.value;
// Increase canvas size + 211 pixels to the right
// with the anchor in the top left
srcDoc.resizeCanvas(w +211, h, AnchorPosition.TOPLEFT);
}
Question:
I am trying to figure out how to prevent the function from firing on multiple clicks of the button.
I only want the canvas to be resized the once.
Any suggestions please
Ian
Explore related tutorials & articles
Copy link to clipboard
Copied
If an Action or script is run or played with a click of a button a or shortcut. If Photoshop see you used the button or shortcut it will run or play the automation. You would need to be control to when these event happen to throw away these event should they occur. But as soon as you loose control or give up control If photoshop get control and see an event the automation will be started. You must to control you fingers better.
Copy link to clipboard
Copied
this.enabled = false;
The interface is made not by a script but by an extension.
I can’t say anything, because basically I do not use extensions and they are all off.
Copy link to clipboard
Copied
Hi @ian-barber,
maybe a bit awkward, but how about with something like that (depends on your layer structure and workflow)?
Canvas_Bigger ();
function Canvas_Bigger() {
var srcDoc = app.activeDocument;
var nme = srcDoc.layers[srcDoc.layers.length-1].name;
if (nme != "Big Canvas") {
// get original width and height
var w = srcDoc.width.value;
var h = srcDoc.height.value;
// Increase canvas size + 211 pixels to the right
// with the anchor in the top left
srcDoc.resizeCanvas(w /*+211*/, h, AnchorPosition.TOPLEFT);
srcDoc.layers[srcDoc.layers.length-1].name = "Big Canvas";
//alert ("Canvas was changed");
} else {
//alert ("Script was already used");
}
}
Rename (for example) your background layer in the first run and check for the name.

