In Photoshop, the current function of the "New group from layers" is to put any selected layers into one folder.
I'd like to have a similar function but slightly different. An example is like this:
1) I have 10 selected layers and I'd like the script create 10 folders, then have the script put each layer in it's own folder. so one layer will have it's own one folder.
2) The folder name will take on the existing layer name. so if I select the layer named "home", the newly created folder name will have this same name.
3) Appends a "@" at the end of each folder name, example "home@"
New Group From Layers
-
Paul MR
New Group From Layers
Please try this...
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var selLayer = getSelectedLayersIdx();
var sLayers = new Array();
for(var z in selLayer){
sLayers.push(getLayerID(Number(selLayer[z])));
}
for(var a in sLayers){
doc.layerSets.add();
doc.activeLayer.name = getLayerNameByID( Number(sLayers[a]) ) +"@";
var To = getLayerID();
moveLayerToLayerSet( Number(sLayers[a]),To);
}
};
function moveLayerToLayerSet( fromID, toID ){
var desc5 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putIdentifier( charIDToTypeID('Lyr '), Number(fromID) );
desc5.putReference( charIDToTypeID('null'), ref4 );
var ref5 = new ActionReference();
ref5.putIndex( charIDToTypeID('Lyr '), getLayerIDX(toID) );
desc5.putReference( charIDToTypeID('T '), ref5 );
desc5.putBoolean( charIDToTypeID('Adjs'), false );
desc5.putInteger( charIDToTypeID('Vrsn'), 5 );
try{
executeAction( charIDToTypeID('move'), desc5, DialogModes.NO );
}catch(e){alert(e);}
};
function getLayerNameByID( id ) {
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));
};
function getLayerIDX(ID){
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID('Lyr '), ID );
try{
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}
};
function getLayerID(IDX){
var ref = new ActionReference();
if(IDX == undefined){
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
}else{
ref.putIndex( charIDToTypeID('Lyr '), IDX );
}
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
var vis = app.activeDocument.activeLayer.visible;
if(vis == true) app.activeDocument.activeLayer.visible = false;
var desc9 = new ActionDescriptor();
var list9 = new ActionList();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list9.putReference( ref9 );
desc9.putList( charIDToTypeID('null'), list9 );
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
app.activeDocument.activeLayer.visible = vis;
}
return selectedLayers;
};
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var selLayer = getSelectedLayersIdx();
var sLayers = new Array();
for(var z in selLayer){
sLayers.push(getLayerID(Number(selLayer[z])));
}
for(var a in sLayers){
doc.layerSets.add();
doc.activeLayer.name = getLayerNameByID( Number(sLayers[a]) ) +"@";
var To = getLayerID();
moveLayerToLayerSet( Number(sLayers[a]),To);
}
};
function moveLayerToLayerSet( fromID, toID ){
var desc5 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putIdentifier( charIDToTypeID('Lyr '), Number(fromID) );
desc5.putReference( charIDToTypeID('null'), ref4 );
var ref5 = new ActionReference();
ref5.putIndex( charIDToTypeID('Lyr '), getLayerIDX(toID) );
desc5.putReference( charIDToTypeID('T '), ref5 );
desc5.putBoolean( charIDToTypeID('Adjs'), false );
desc5.putInteger( charIDToTypeID('Vrsn'), 5 );
try{
executeAction( charIDToTypeID('move'), desc5, DialogModes.NO );
}catch(e){alert(e);}
};
function getLayerNameByID( id ) {
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));
};
function getLayerIDX(ID){
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID('Lyr '), ID );
try{
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}
};
function getLayerID(IDX){
var ref = new ActionReference();
if(IDX == undefined){
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
}else{
ref.putIndex( charIDToTypeID('Lyr '), IDX );
}
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
var vis = app.activeDocument.activeLayer.visible;
if(vis == true) app.activeDocument.activeLayer.visible = false;
var desc9 = new ActionDescriptor();
var list9 = new ActionList();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list9.putReference( ref9 );
desc9.putList( charIDToTypeID('null'), list9 );
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
app.activeDocument.activeLayer.visible = vis;
}
return selectedLayers;
};
-
mycort
New Group From Layers
great start and almost there.......seems like it makes the folders but it does not put the layer in each folder.
-
Paul MR
New Group From Layers
The layer is getting put in the group in my test.
I am using Photoshop CS6 with Windows 7.
What version are you using so that I can try with that version.
I am using Photoshop CS6 with Windows 7.
What version are you using so that I can try with that version.
-
Paul MR
New Group From Layers
Please try this version...
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var selLayer = getSelectedLayersIdx();
var sLayers = new Array();
for(var z in selLayer){
sLayers.push(getLayerID(Number(selLayer[z])));
}
for(var a in sLayers){
var newLayerset = doc.layerSets.add();
doc.activeLayer.name = getLayerNameByID( Number(sLayers[a]) ) +"@";
selectLayerById(Number(sLayers[a]));
doc.activeLayer.move(newLayerset, ElementPlacement.INSIDE);
}
};
function selectLayerById(ID, add) {
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);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
function getLayerNameByID( id ) {
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));
};
function getLayerIDX(ID){
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID('Lyr '), ID );
try{
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}
};
function getLayerID(IDX){
var ref = new ActionReference();
if(IDX == undefined){
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
}else{
ref.putIndex( charIDToTypeID('Lyr '), IDX );
}
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
var vis = app.activeDocument.activeLayer.visible;
if(vis == true) app.activeDocument.activeLayer.visible = false;
var desc9 = new ActionDescriptor();
var list9 = new ActionList();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list9.putReference( ref9 );
desc9.putList( charIDToTypeID('null'), list9 );
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
app.activeDocument.activeLayer.visible = vis;
}
return selectedLayers;
};
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var selLayer = getSelectedLayersIdx();
var sLayers = new Array();
for(var z in selLayer){
sLayers.push(getLayerID(Number(selLayer[z])));
}
for(var a in sLayers){
var newLayerset = doc.layerSets.add();
doc.activeLayer.name = getLayerNameByID( Number(sLayers[a]) ) +"@";
selectLayerById(Number(sLayers[a]));
doc.activeLayer.move(newLayerset, ElementPlacement.INSIDE);
}
};
function selectLayerById(ID, add) {
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);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
function getLayerNameByID( id ) {
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getString(charIDToTypeID( "Nm " ));
};
function getLayerIDX(ID){
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID('Lyr '), ID );
try{
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}
};
function getLayerID(IDX){
var ref = new ActionReference();
if(IDX == undefined){
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
}else{
ref.putIndex( charIDToTypeID('Lyr '), IDX );
}
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
var vis = app.activeDocument.activeLayer.visible;
if(vis == true) app.activeDocument.activeLayer.visible = false;
var desc9 = new ActionDescriptor();
var list9 = new ActionList();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list9.putReference( ref9 );
desc9.putList( charIDToTypeID('null'), list9 );
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
app.activeDocument.activeLayer.visible = vis;
}
return selectedLayers;
};
-
mycort
New Group From Layers
Odd still does not work right. I actually tried this out with another mac computer and it did not work too......
do you want me to run script listener of adding one layer to a new folder? maybe it's written and recorded differently on a mac?
do you want me to run script listener of adding one layer to a new folder? maybe it's written and recorded differently on a mac?
-
Paul MR
New Group From Layers
The second version is using DOM not action manager code.
Both versions work fine on the PC. I will try and dust off an old Mac tomorrow and try it out with Photoshop CS4 as it's only a PPC machine.
Both versions work fine on the PC. I will try and dust off an old Mac tomorrow and try it out with Photoshop CS4 as it's only a PPC machine.
-
mycort
New Group From Layers
after playing with this some, I am able to make it work but under a specific conditions of this.
I found out that if I created a new file with a Background Content set to either White or Background Color(which is a last layer with a lock on it), it seems to work just right.
When I set the new file to Transparent background, then it does not work. Also, if I do have a locked background and I unlock it by double clicking it,then it does not work.
It seems to be dependent on your background content type. Is there a way to make independent on this regardless?
I found out that if I created a new file with a Background Content set to either White or Background Color(which is a last layer with a lock on it), it seems to work just right.
When I set the new file to Transparent background, then it does not work. Also, if I do have a locked background and I unlock it by double clicking it,then it does not work.
It seems to be dependent on your background content type. Is there a way to make independent on this regardless?
-
Paul MR
New Group From Layers
Well I'am stumped. I have tested with and without a background layer on Windows and on a Mac (CS4) and the script is working fine so I have no idea why it doesn't work for you.