Skip to main content
Known Participant
October 1, 2023
Answered

any Selection Shape area to rectangular selection shape photoshop Scripts

  • October 1, 2023
  • 1 reply
  • 900 views

Please Can You Help Me ?

Change from any selection shape area to rectangular selection shape photoshop Scripts 

This topic has been closed for replies.
Correct answer Stephen Marsh

Courtesy of @c.pfaffenbichler 

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-automatically-create-a-rectangular-layer-mask-from-an-irregularly-shaped-selection/m-p/4905764

 

/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-automatically-create-a-rectangular-layer-mask-from-an-irregularly-shaped-selection/m-p/4905764 */
// make selection rectangular
// 2013, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    try {
        var theBounds = myDocument.selection.bounds;
        var theArray = [[theBounds[0], theBounds[1]], [theBounds[2], theBounds[1]], [theBounds[2], theBounds[3]], [theBounds[0], theBounds[3]]];
        myDocument.selection.select(theArray, SelectionType.REPLACE, 0, false);
    }
    catch (e) { }
}

 

1 reply

ThihasoeAuthor
Known Participant
October 1, 2023

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
October 2, 2023

Courtesy of @c.pfaffenbichler 

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-automatically-create-a-rectangular-layer-mask-from-an-irregularly-shaped-selection/m-p/4905764

 

/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-automatically-create-a-rectangular-layer-mask-from-an-irregularly-shaped-selection/m-p/4905764 */
// make selection rectangular
// 2013, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    try {
        var theBounds = myDocument.selection.bounds;
        var theArray = [[theBounds[0], theBounds[1]], [theBounds[2], theBounds[1]], [theBounds[2], theBounds[3]], [theBounds[0], theBounds[3]]];
        myDocument.selection.select(theArray, SelectionType.REPLACE, 0, false);
    }
    catch (e) { }
}

 

c.pfaffenbichler
Community Expert
Community Expert
October 2, 2023

I am testing on Windows, running Photoshop 25.0.0. Both scripts do not produce the requested result.

 

The first script is creating a small rectangle in the top-left corner, while the second is creating a huge rectangle off the canvas. Only one part of the selection rectangle is visible in the top-right corner of the image.


quote

I am testing on Windows, running Photoshop 25.0.0. Both scripts do not produce the requested result.

 

The first script is creating a small rectangle in the top-left corner, while the second is creating a huge rectangle off the canvas. Only one part of the selection rectangle is visible in the top-right corner of the image.


By @Bojan Živković11378569

Sound like it might be related the the image resolution. 

Changing the ruler settings to Pixels should help there. (Which could be done via Script and reset via Script, too.)