Copy link to clipboard
Copied
Is that possible to remove all Group only without any contents ?
ungroup_folder(activeDocument);
function ungroup_folder(f)
{
try {
for (var i = f.layerSets.length-1; i >= 0; i--)
{
ungroup_folder(f.layerSets[i]);
}
if (f.typename == "LayerSet")
{
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new Acti
Copy link to clipboard
Copied
Close to what you need:
File-> Scripts-> Delete All Empy Layers
For groups only, you need to edit the script
UPD. the code is taken from that script
deleteAllEmptyLayerSets(activeDocument)
function deleteAllEmptyLayerSets(o){
try{
var bEmpty = true;
for(var i = o.layerSets.length-1; 0 <= i; i--) {
var layerSet = o.layerSets[i];
if((layerSet.allLocked)||(0!=layerSet.linkedLayers.length)){
continue; // skip locked or linked
}
if(deleteAllEmptyLayerSets(layerSet)){ // empty
layerSet.remove(); // delete
} else bEmpty = false; // not empty
}
if(0 != o.artLayers.length) bEmpty = false; // not empty
}catch(e){
; // do nothing
}
return bEmpty;
}
Copy link to clipboard
Copied
Yes @r-bin , Can You Modify this !
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(sTID("deleteContained"), false);
executeAction(cTID('Dlt '), desc1, DialogModes.NO);
Copy link to clipboard
Copied
ungroup_folder(activeDocument);
function ungroup_folder(f)
{
try {
for (var i = f.layerSets.length-1; i >= 0; i--)
{
ungroup_folder(f.layerSets[i]);
}
if (f.typename == "LayerSet")
{
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
//ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
ref1.putIdentifier(cTID('Lyr '), f.id);
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(sTID("deleteContained"), false);
executeAction(cTID('Dlt '), desc1, DialogModes.NO);
}
}
catch (e) { alert(e); }
}
Copy link to clipboard
Copied
Thanku so much @r-bin I Worked Very Well !
Copy link to clipboard
Copied
"Remove All Group Without any contents" means "to remove only one group that does not contain any layer(Set)s". If you wanted to remove any group and to remain its content you would say: "remove all groups, but keep their content".
The first r-bin scirpt is then correct answer to your question, plus it scans more than one group as bonus. The Goolge translation doesn't work for you. Again we're in endless loop of misunderstandings and guessing. Tell us what is the problem of talking to us in Hindi if again another thread shows your English fails?
Copy link to clipboard
Copied
In Active Document "Remove All Group Without Content" Means I have 5Group Inside Many Layer so i want to remove Group Only, Anyway Answar is right from @r-bin
What is not understanding tell me @Kukurykus , Everything is easily understand which point you can't understand tell me !
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Don't need to google translation because eveything is understanding , If you don't understand tell me which sentence is not clear ?
Copy link to clipboard
Copied
Your own words from Jul 12, 2021:
Next Time I will try to Best Speak English Via Google Translator
By @MXKS
Copy link to clipboard
Copied
r-bin said there's need to edit the script and in no time presented version of edited script which originally removed empty layers, but still in context of your original request.
Copy link to clipboard
Copied
I explained in simple words what "Remove All Group Without Content" means. The meaning you bring now is only that you 'see' in your head, not that the users can straigfuly understand from your words.
If "Remove All Group Without Content" means "I have 5Group Inside Many Layer so i want to remove Group Only" why you didn't say it at start?
Again that is even much harder to say what that does mean. The only what I can understand from "I have 5Group Inside Many Layer so i want to remove Group Only" is "I have some object named '5Group' inside of many layer (which again we have to guess you mean 'many layers', and what has no sense as layer can't contain a group, but can contain for ex. a text ie. '5Group' can be text content in this case) so I want to remove Group Only (that means you want to keep number '5' removing 'Group' suffix).
As you see all of this has no logic for someone who read it.
If 'Everything is easily understand' why first r-bin solution wasn't marked as correct, but he had to ask you for more than 'two words' to eventually post other code than originaly due to your original request?
Copy link to clipboard
Copied
Always You have problem with me @Kukurykus
@r-bin Said the First Answar:-
Close to what you need:
File-> Scripts-> Delete All Empy Layers
For groups only, you need to edit the script
UPD. the code is taken from that script
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can also try this. It seems to delete all empty groups and will delete nested empty groups.
#target photoshop
var doc = activeDocument;
var useList = [];
var layerSets = 0
try{doc.backgroundLayer}
catch(e){layerSets=1}
var layerList = getLayerSetsData();
for (var i=0;i<layerList.length;i++){
if(layerList[i].type == 7){
useList.push(layerList[i].id)};
}
for(var i=0;i<useList.length;i++){
multiSelectByIDs (useList[i]);
if(doc.activeLayer.layers.length == 0){doc.activeLayer.remove()}
}
function getLayerSetsData(){
var lyrSets = [];
while (true)
{
ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), layerSets);
try
{var d1 = executeActionGet(ref)}
catch (err){
break;
};
var c2t = function (s){return app.charIDToTypeID(s);};
var s2t = function (s){return app.stringIDToTypeID(s);};
var lyrSet = {};
lyrSet.type = d1.getInteger(s2t("layerKind"));
lyrSet.name = d1.getString(c2t("Nm "));
lyrSet.id = d1.getInteger(s2t("layerID"));
lyrSets.push(lyrSet);
layerSets++;
};
return lyrSets;
};
function doesIdExists( id ){// function to check if the id exists
var res = true;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), id);
try{var desc = executeActionGet(ref)}catch(err){res = false};
return res;
}
function multiSelectByIDs(ids) {
$.writeln(ids)
if( ids.constructor != Array ) ids = [ ids ];
var layers = new Array();
var id54 = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var id55 = charIDToTypeID( "null" );
var ref9 = new ActionReference();
for (var i = 0; i < ids.length; i++) {
if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
layers[i] = charIDToTypeID( "Lyr " );
ref9.putIdentifier(layers[i], ids[i]);
}
}
desc12.putReference( id55, ref9 );
var id58 = charIDToTypeID( "MkVs" );
desc12.putBoolean( id58, false );
executeAction( id54, desc12, DialogModes.NO );
}
Copy link to clipboard
Copied
No , I will remove Group Only Without any content :-
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(sTID("deleteContained"), false);
executeAction(cTID('Dlt '), desc1, DialogModes.NO);
Copy link to clipboard
Copied
As far as the translation issue, I would post your questions and replies in both your native language and in English. Maybe someone can then better translate. I would also use more screen shots to show want you want.