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
  • 894 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) { }
}

 

Stephen Marsh
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.


@Bojan Živković11378569 – Hmm, curious, the following screenshot is before (left) and after (right) in v2024:

 

 

Is your ruler origin point in the upper left? The guides in the screenshot are only to aid visualisation.

 

EDIT: Also tested in v2021 with expected results (Mac).