Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Resize Canvas Script

Contributor ,
Feb 07, 2020 Feb 07, 2020

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

 

TOPICS
Actions and scripting
4.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Feb 07, 2020 Feb 07, 2020

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.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 08, 2020 Feb 08, 2020
Paste this code in function code

 

this.enabled = false;

 

 

EDIT:
Did not notice.
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.
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2020 Feb 09, 2020
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines