Photoshop script how to select multi layers by size ( CM or inch)

Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Hi every body how i need to know how to select all photoshop layers by size or diminsion ( CM or inch ) Please

TOPICS
Actions and scripting, SDK

Views

1.0K

Likes

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

Adobe Community Professional , Nov 24, 2021 Nov 24, 2021
How familiar are you with JavaScript and Photoshop Scripting?  Are you capable of adapting a Script that contains the necessary basic operations to your needs?  The below Script should group Layers that have the same bounds dimensions and align them horizontally in the group (see screenshots).  // group layers of the same bounds dimensions; // 2021, use it at your own risk; if (app.documents.length > 0) { var theLayers = collectLayersBounds (); theLayers.sort(sortArrayByIndexedItem...

Likes

Translate

Translate
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Please elaborate. 

Screenshots might help clarify. 

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I have File with multi layers with different Size layer ...

I need when select layer in photo 001 and run script  collect all layer with same size in photo 002

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Sorry, I am not sure I understand. 

 

There are two files involved?

If so how can the second image be identified? 

Will there only ever be two images open at the same time when the Script is invoked? 

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Sorry, I get it now. 

 

Do the layers always have rectanglur content? 

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Thank you for caring

i found more script select layers by name of text contect , but i need script select layer by shape size or layer size .

I hope you understand what I want

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Have your script prompt the user to select the two files that need to be processed. That will make like much easier.

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Thank you for caring

but how do it ?

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

You'll be using layer.bounds although be aware that it doesn't work if a layer is part of a layerset. You can also get layer bounds without effects. You'll need to know what you are looking for, this will likely be more complicated than you think.

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

If the areas are rectangular this might help: 

// 2021, use it at your own risk;
if (app.documents.length > 0) {
    var theLayers = collectLayersBounds ();
    var theBounds = activeDocument.activeLayer.bounds;
    var thisArea = (theBounds[2] - theBounds[0]) * (theBounds[3] - theBounds[1]);
    for (var m = 0; m < theLayers.length; m++) {
        if (theLayers[m][4] == thisArea) {selectLayerByID(theLayers[m][2], true)}
    }
};
////////////////////////////////////
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
      desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};
////// collect layers //////
function collectLayersBounds () {
    // the file;
    var myDocument = app.activeDocument;
    // get number of layers;
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
    // process the layers;
    var theLayers = new Array;
    for (var m = 0; m <= theNumber; m++) {
    try {
    var ref = new ActionReference();
    ref.putIndex( charIDToTypeID( "Lyr " ), m);
    var layerDesc = executeActionGet(ref);
    var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
    var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
    // if group collect values;
    if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
    var theName = layerDesc.getString(stringIDToTypeID('name'));
    var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
    var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
    var theColor = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("color")));
    var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
    var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
    var theArea = (theBounds.getUnitDoubleValue(stringIDToTypeID("right")) - theBounds.getUnitDoubleValue(stringIDToTypeID("left"))) * (theBounds.getUnitDoubleValue(stringIDToTypeID("bottom")) - theBounds.getUnitDoubleValue(stringIDToTypeID("top")));
    theLayers.push([theName, theIndex, theID, theColor, theArea])
    };
    }
    catch (e) {};
    };
    return theLayers
    };

Screenshot 2021-11-23 at 15.32.43.pngScreenshot 2021-11-23 at 15.32.56.png

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Thanks
But this is not what I want
I have attached an explanation of what I want
I want when selecting an element all the elements are selected based on the dimensions knowing that the layers have no name..
Layers may have different names, but they are defined by dimensions

 

01.gif

 

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Trying to explain what you mean at this point seems fairly late. 

 

Have you actually tested the Script?

The Layers are not selected based on the Layer Names but based on the Layer Bounds (edit: actually by the bounds width multiplied by the bounds height). 

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Yes i test script and not work ??

 

 

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Do the layers with the same bounds-area as the active layer not get selected? 

Do you want them to be aligned? If so: To what? 

 

Please post meaningful screenshots. 

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

ok ..

i want them to be aligned

but not all layers , i want aligned same bounds area layer

it possible or not

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

It is possible but it does not at all seem to be what you asked for in the original post. 

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I want to reach the best possible thing
In the first, I wanted to arrange the layers according to the sizes of the internal shapes of the layers, but if this is impossible, I want the closest thing to do what is required

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied


@Mohamed Hameed wrote:

I want to reach the best possible thing
In the first, I wanted to arrange the layers according to the sizes of the internal shapes of the layers, but if this is impossible, I want the closest thing to do what is required


To me it seems you spread various ideas over several posts so please provide one clear and complete description (with screenshots) of what you are trying to achieve. 

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I want to reach the best possible thing
In the first, I wanted to arrange the layers according to the sizes of the internal shapes of the layers, but if this is impossible, I want the closest thing to do what is required

 

What is the best possible thing?  Layer may have to overlap  a document  canvas size is just so larger.  Layer total combined areas can be many times the canvas size. A  layer can even be larger than canvas size.  If you are trying to do sort of layout.  Try to explain what you are working with and what you want to accomplish.

JJMack

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

How do you want to select  a layer? Every layer in a document  could be a shape layer or masked to a shape.  Every layer could have a different  shape, size, and location which may or may overlap  other layer.   Please explain what  you are logically trying to do? selecting layers by shape or size? You Animated gif seems to  have layer randomly moving about.  Is there any logic about what happening in your gif?  What would you script de with a document like this one:

image.png

JJMack

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I have a file with many layers like images
But the pictures have different dimensions
Most of these images are similar in size
I want when selecting an element with a specific dimension
It selects all items of similar size
Is there a problem with this?
I would like the full code please?
Thank you

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I have a file with many layers like images

Do you have a  folder of image  or  A layers image file that has many Image layers and only  rectangle layers? 
But the pictures have different dimensions

Script can add canvas to the maximum canvas size supports and distribute images over the canvas  The maximum canvas size is 300,000 Px  bt 300,000 Px.  

Most of these images are similar in size
I want when selecting an element with a specific dimension

If you have Images in folders  you can sort on  dimensions  and have a Photoshop  process the image in that sequence.
It selects all items of similar size
Is there a problem with this?

If the script  is just to select similar size image layers  and some layers are size A and some size B and Size C  you would  need a way the pass to the script the size layer to be selected.  Once the selection is done you would need to do the moving and distributing of the layers.
I would like the full code please?

The code you need to design the Process to what you want to accomplish then code the process.
Thank you

JJMack

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

no files in folder

I mean on psd file contain mutli layers like your image attach

Likes

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
Explorer ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

I have a file with many layers like images
But the pictures have different dimensions
Most of these images are similar in size
I want when selecting an element with a specific dimension
It selects all items of similar size
Is there a problem with this?
I would like the full code please?Screenshot 2021-11-23 192641.png

Likes

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Moderator please remove this thread, which is duplicate of:

Photoshop script how to select multi layers by size ( CM or inch) 

Likes

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