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
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
...
Copy link to clipboard
Copied
Please elaborate.
Screenshots might help clarify.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Sorry, I get it now.
Do the layers always have rectanglur content?
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
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.
Copy link to clipboard
Copied
Thank you for caring
but how do it ?
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.
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
};
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
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).
Copy link to clipboard
Copied
Yes i test script and not work ??
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.
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
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.
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
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.
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.
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:
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
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
Copy link to clipboard
Copied
no files in folder
I mean on psd file contain mutli layers like your image attach
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?
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)