Copy link to clipboard
Copied
Greetings to all for the most wonderful forum, which serves many of its followers
I am working on a file with more than 500 layers
I want a script that splits layers and puts them into groups based on an input value
For example, I want to set a value for example 50 to choose 50 layers and place them inside a group named with the number of layers
--- Then select all the remaining layers and insert a value for example 30 to choose 30 layers and place them within a group named with the number of layers..... etc.
You can try the following script
deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
_groupLength = Number(_name);
if (!isNaN(_groupLength)) {
if (_groupLength != 0 && _groupLength <= _layers.length) {
for (var i = 0; i < _groupLength; i++) {
selectLayerByID(_layers[i].id, true);
}
groupSelectedLayers(_name);
} else {
aler
...
Copy link to clipboard
Copied
Hello, you can try ActionNodes to create such an action yourself. It's pretty easy.
Copy link to clipboard
Copied
When you say, you set a value 50 to choose 50 layers, what does it means
1. 50 layers alreday selected?
2. you want to select 50 layers. if yes, which 50 layers, first 50 , last 50 or alternative. How you will decide which 50 layers.
If you can show some samples that will be helpful for us to guide you in right direction.
Copy link to clipboard
Copied
To clearly explain what is required
I have a file with for example 500 layers or more and they are all the same size
I want to make groups for the layers, but with different numbers for each group
For example, I want to choose 50 layers and put them in a group named 50 layers
Choose 30 layers and place them in a group named 30 layers
-- As for the selection of layers, the layers are selected from top to bottom..with the exclusion of the layers and groups that have been created
Copy link to clipboard
Copied
You can try the following script
deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
_groupLength = Number(_name);
if (!isNaN(_groupLength)) {
if (_groupLength != 0 && _groupLength <= _layers.length) {
for (var i = 0; i < _groupLength; i++) {
selectLayerByID(_layers[i].id, true);
}
groupSelectedLayers(_name);
} else {
alert('Either you entered 0 or entered number is higher than the number of layers present in the document');
}
} else {
alert('Enter value is not the number')
}
}
function groupSelectedLayers(theName) {
var desc159 = new ActionDescriptor();
var ref114 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idtargetEnum = stringIDToTypeID("targetEnum");
var idnull = stringIDToTypeID("null");
var idname = stringIDToTypeID("name");
ref114.putEnumerated(idlayer, idordinal, idtargetEnum);
desc159.putReference(idnull, ref114);
desc159.putString(idname, "aaa");
executeAction(stringIDToTypeID("groupLayersEvent"), desc159, DialogModes.NO);
var desc63 = new ActionDescriptor();
var ref37 = new ActionReference();
ref37.putEnumerated(idlayer, idordinal, idtargetEnum);
desc63.putReference(idnull, ref37);
var desc64 = new ActionDescriptor();
desc64.putString(idname, theName);
desc63.putObject(stringIDToTypeID("to"), idlayer, desc64);
executeAction(stringIDToTypeID("set"), desc63, DialogModes.NO)
}
function selectLayerByID(index, add) {
add = undefined ? add = false : add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), index);
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);
}
};
function deSelectAllLayers() {
var idselectNoLayers = stringIDToTypeID("selectNoLayers");
var desc26 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref3 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref3.putEnumerated(idLyr, idOrdn, idTrgt);
desc26.putReference(idnull, ref3);
executeAction(idselectNoLayers, desc26, DialogModes.NO);
}
Reference links
Note: The above script will not take care of nested structure of the layers.
Copy link to clipboard
Copied
majesty, grandeur, grandeur
How great you are and how clever you are
Thank you for your interest and for helping me
Copy link to clipboard
Copied
@Charu Rajput – Excellent work!
Copy link to clipboard
Copied
@Stephen_A_Marsh - It is only possible with the support of all of us.