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

is it possible to select a random area with scripting?

New Here ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

Sorry if this is basic, is there a way to script the selection of a random area in photoshop?

TOPICS
Actions and scripting

Views

112

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , May 22, 2024 May 22, 2024
quote

Sorry if this is basic, is there a way to script the selection of a random area in photoshop?


By @Mark5C6C

 

I wouldn't say it's basic, but it's possible.

 

I presume that you are referring to both the size and position. I would expect that there should be both a minimum and maximum size for the selection compared to the canvas size. What other criteria, such as the canvas edges, is it OK for the selection to go to the edge of the canvas, or should it always have a "safe zone" where it has to

...

Votes

Translate

Translate
Adobe
Engaged ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

you can use a selection tool for example the square and generate an image inside that box.

 

Votes

Translate

Translate

Report

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
LEGEND ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

Truly random? As in whatever area the script decides randomly?

Votes

Translate

Translate

Report

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 ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

LATEST
quote

Sorry if this is basic, is there a way to script the selection of a random area in photoshop?


By @Mark5C6C

 

I wouldn't say it's basic, but it's possible.

 

I presume that you are referring to both the size and position. I would expect that there should be both a minimum and maximum size for the selection compared to the canvas size. What other criteria, such as the canvas edges, is it OK for the selection to go to the edge of the canvas, or should it always have a "safe zone" where it has to keep away from the canvas edges? Is this a rectangular selection or something else?

 

What is the use case?

 

Edit: This is what ChatGPT regurgitated:

 

// Ensure a document is open
if (app.documents.length > 0) {
    var doc = app.activeDocument;

    // Get the canvas dimensions
    var canvasWidth = doc.width.as("px");
    var canvasHeight = doc.height.as("px");

    // Generate random values for the selection
    var randomWidth = Math.floor(Math.random() * canvasWidth);
    var randomHeight = Math.floor(Math.random() * canvasHeight);
    var randomX = Math.floor(Math.random() * (canvasWidth - randomWidth));
    var randomY = Math.floor(Math.random() * (canvasHeight - randomHeight));

    // Define the selection coordinates
    var selectionCoords = [
        [randomX, randomY],
        [randomX + randomWidth, randomY],
        [randomX + randomWidth, randomY + randomHeight],
        [randomX, randomY + randomHeight]
    ];

    // Make the selection
    doc.selection.select(selectionCoords);

    // Inform the user
    alert("Random selection created at (" + randomX + ", " + randomY + ") with dimensions " + randomWidth + "x" + randomHeight + " pixels.");
} else {
    alert("No document is open. Please open a document and try again.");
}

 

Votes

Translate

Translate

Report

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