Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

changes to this script

Explorer ,
Sep 18, 2016 Sep 18, 2016

hi,

     How to add save layersets along with Background layer command to this script

  1. #target photoshop 
  2. function main(){ 
  3. if(!documents.length) return; 
  4. var doc = activeDocument; 
  5. var oldPath = activeDocument.path; 
  6. for(var a=0;a<doc.layerSets.length;a++){ 
  7. activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name); 
  8. dupLayers(); 
  9. activeDocument.mergeVisibleLayers(); 
  10. activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true); 
  11. var saveFile= File(oldPath +"/"+doc.layerSets.name +".psd"); 
  12. SavePSD(saveFile); 
  13. app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
  14.     } 
  15. main(); 
  16. function dupLayers() {  
  17.     var desc143 = new ActionDescriptor(); 
  18.         var ref73 = new ActionReference(); 
  19.         ref73.putClass( charIDToTypeID('Dcmn') ); 
  20.     desc143.putReference( charIDToTypeID('null'), ref73 ); 
  21.     desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name ); 
  22.         var ref74 = new ActionReference(); 
  23.         ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
  24.     desc143.putReference( charIDToTypeID('Usng'), ref74 ); 
  25.     executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO ); 
  26. }; 
  27. function SavePSD(saveFile){  
  28. psdSaveOptions = new PhotoshopSaveOptions();  
  29. psdSaveOptions.embedColorProfile = true;  
  30. psdSaveOptions.alphaChannels = true;   
  31. activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);  
TOPICS
Actions and scripting
1.1K
Translate
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 Expert ,
Sep 19, 2016 Sep 19, 2016

Have you tried removing the merge visible layers.

JJMack
Translate
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 ,
Sep 19, 2016 Sep 19, 2016

Yeah I tried that commenting out link but not working it just duplicates only layersets

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

What are you trying to do? Why ae you using that  script in the first place.  Have you looked a the Image processor,  Image processor pro plugin  and the Picture processor scripts?

JJMack
Translate
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 ,
Sep 19, 2016 Sep 19, 2016

I want all my layergroups are duplicated one by one in separate tiff documents.

So that I am using the above one it does it job right now by duplicate the layerset to new document with the layer group name but the problem is is doesn't save those with background.

I had used image processor it doesn't worked for me

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

So your final result, you want a flattened tiff file with each one of your layer sets plus the background layer, correct? If that's the case, I would approach this script (use scriptlistener to record many of the steps) would be to:

1. Have master file open

2. record number of layersets (groups) for a loop.

3. turn off visibility of all layersets.

4. create loop to turn on each layer set in order, have the BG layer visible

5. create a copy of the entire file and use the option to merge visible.

6. Save the copy file and close.

7. Loop continues and turns off visibility of layer set that was just saved and turns on next one. Loop continues.

Translate
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 ,
Sep 19, 2016 Sep 19, 2016

how these many steps can be created using script listener is it possible to create a loop in script listener plugin

Translate
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 ,
Sep 19, 2016 Sep 19, 2016

Merging visible layer i dont want that i want a duplicated layer group and its background from master file.

Translate
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 ,
Sep 19, 2016 Sep 19, 2016
  1. #target photoshop
  2. function main(){
  3. if(!documents.length) return;
  4. var doc = activeDocument;
  5. var oldPath = activeDocument.path;
  6. for(var a=0;a<doc.layerSets.length;a++){
  7. activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name);
  8. dupLayers();
  9. activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
  10. var saveFile= File(oldPath +"/"+doc.layerSets.name +".psd");
  11. SavePSD(saveFile);
  12. app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  13.     }
  14. }
  15. main();
  16. function dupLayers() { 
  17.     var desc143 = new ActionDescriptor();
  18.         var ref73 = new ActionReference();
  19.         ref73.putClass( charIDToTypeID('Dcmn') );
  20.     desc143.putReference( charIDToTypeID('null'), ref73 );
  21.     desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );
  22.         var ref74 = new ActionReference();
  23.         ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
  24.     desc143.putReference( charIDToTypeID('Usng'), ref74 );
  25.     executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
  26. };
  27. function SavePSD(saveFile){ 
  28. psdSaveOptions = new PhotoshopSaveOptions(); 
  29. psdSaveOptions.embedColorProfile = true; 
  30. psdSaveOptions.alphaChannels = true;  
  31. activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
  32. }
Translate
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 ,
Sep 19, 2016 Sep 19, 2016

I mean i use script listener only for doing some functions like photoshop action does

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

Okay, if you want to keep the layers intact, you can do it two different ways:

1. Make a copy of the file but don't use merge visible. Then loop though that copy file and delete all the other layersets and save.

2. Use the copy layers command from the main menu to record copying and moving a layer set to a new file of the same dimension. Copy the background layer also, then save and close.

Translate
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 ,
Sep 19, 2016 Sep 19, 2016

the above script selects the layer groups one by one from top order but its does not select the background while duplicating

thats the main problem please help me on that part

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

You would need to  re-program the main function. For each group It would create a new document with a canvas the size of the background layer  Using duplicate Background Layer into a new document with the name of the Current Document Name + Group Name. Then duplicate the layers within the current group into that document "Current Document Name + Group Name". If you want to preserve layers you would not want to merge visible. You would need to Save and close "Current Document Name + Group Name" As your layered or flattened Tiff.

The new document containing the Background would be created after statement 6 before statement 7  the dupLayers function would need to the dupe the layers into the document "Current Document Name + Group Name" so that action manager code would need to be changed and have the "Current Document Name + Group Name"  be a parameter.  You need to change the save as PSD to save as Tiff.

If the bottom layer is actually a Background layer that layer does not support transparency so the Trim transparency statement is not needed. So you can delete 9 and 10.  Statement 11 need a little update.

JJMack
Translate
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 ,
Sep 19, 2016 Sep 19, 2016

Thanks Mack

Can you tell me some example on that part i am confused what function need to set there

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

You need two duplicate layers on duplicates the background into a new document the other duplicates the layer within a group to a document.  It needs the be the same document.  and doing the dupe will switch to the new document,  So after duping the background you nee to switch back to the previous current  document document so you can duplicate the groups layers.  The current script has one dupe layers and does not name the document.  The two dupe you need need to name the same document. So the action manager functions need to have a parameter to name the target document. The for loop in the current script processes each group one at a time.

Capture.jpg

JJMack
Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

Try this:

#target photoshop

    function main(){

    if(!documents.length) return;

    var doc = activeDocument;

    var oldPath = activeDocument.path;

    var newName

    for(var a=0;a<doc.layerSets.length;a++){

    activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name);   

    dupLayers();

    var docCopy = activeDocument;

    activeDocument = doc

    doc.activeLayer = doc.layers[doc.layers.length-1]

    doc.activeLayer.duplicate(docCopy,ElementPlacement.PLACEATEND);

    activeDocument = docCopy

    activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

    var saveFile= File(oldPath +"/"+doc.layerSets.name +".psd");

    SavePSD(saveFile);

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }

    main();

   

    function dupLayers() {

        var desc143 = new ActionDescriptor();

            var ref73 = new ActionReference();

            ref73.putClass( charIDToTypeID('Dcmn') );

        desc143.putReference( charIDToTypeID('null'), ref73 );

        desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );

            var ref74 = new ActionReference();

            ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

        desc143.putReference( charIDToTypeID('Usng'), ref74 );

        executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );

    };

    function SavePSD(saveFile){

    psdSaveOptions = new PhotoshopSaveOptions();

    psdSaveOptions.embedColorProfile = true;

    psdSaveOptions.alphaChannels = true; 

    activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);

    }

Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016

Works for me but I would have the original doc name also in the new file names.  Perhaps also the value of a for there can be be groups with identical names anf I would do some texsting with nested groups to see how they get done.

Groups within groups remain that way only top level groups have new layered files created. So if want them to be seperate  you would need to make this a recursive process somehow.

JJMack
Translate
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
Community Expert ,
Sep 19, 2016 Sep 19, 2016
LATEST

Yea, that would be a good idea.

Translate
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