5 Replies Latest reply on Oct 3, 2010 12:20 PM by StrongBeaver

    Can I get help with a Script?

    StrongBeaver Level 3

      Hello, I have a photoshop script that has been sitting around unable to be used because it's functionality is not quite the way I want it. I was hoping someone could help me, I'm still learning javascript and I don't know Photoshop SDK to do it myself, it's a little complex but not by much

        • 1. Re: Can I get help with a Script?
          jugenjury Level 2

          What is the script and what is it supposed to do that it doesn't?

          • 2. Re: Can I get help with a Script?
            Michael L Hale Level 5

            If the script's author allows the script to be modified it is possible that it can be changed to meet your requirements. But I don't think anyone will be able to help without knowing more details about the script and what you require.

            • 3. Re: Can I get help with a Script?
              JJMack Most Valuable Participant

              StrongBeaver wrote:

              I don't know Photoshop SDK to do it myself,

              You do not use the SDK  when writing a Photoshop script a text editor will do.  If the script you have has not been saved in binary you should be able to edit it and modify it with a text editor.  Using the Adobe ExtendScript Toolkit that ships with the later versions of Photoshop you can edit and debug  Photoshop scripts.

              • 4. Re: Can I get help with a Script?
                StrongBeaver Level 3
                What is the script and what is it supposed to do that it doesn't?

                 

                The script is suppose to save layer groups by the names of the layer groups.

                 

                If the script's author allows the script to be modified it is possible that it can be changed to meet your requirements. But I don't think anyone will be able to help without knowing more details about the script and what you require.


                The script was designed for me specifically but never got completed and I gave up trying to get it completed, but I hope now I can get it complete.

                 

                The original goal of the script was that layer groups would be linked to layer comps, when I added a layer to the layer group the layer comp would reflect this and would update automatically. Quite a while ago someone told me that is not possible, so I decided a different route for the script which is I would like to tie the script to buttons using configurator.  When I click one of the custom buttons which has a specific name, it would export the layer group with the same name of the button. I've tried some of the pre-built script inside photoshop but this script that is unfinished was original thought of by me just not the programming knowledge to complete it. Although it is mostly finished it just needs to be changed around, as well my original idea had keyboard buttons such as 1,2,3,4,5 etc linked so when I triggered <ATL> 1 it would export the layer group which was linked to that keyboard short-cut but I can't do that because all the keyboard short-cuts are mostly if not all used by photoshop. All I have had in the past is someone look at the script, and then they don't know what to do with it, or they don't understand the script !!

                 

                You do not use the SDK  when writing a Photoshop script a text editor will do.  If the script you have has not been saved in binary you should be able to edit it and modify it with a text editor.  Using the Adobe ExtendScript Toolkit that ships with the later versions of Photoshop you can edit and debug  Photoshop scripts.

                 

                That is good to know, but I don't know how to code in photoshop.  Tools such as these help once you know how to control the program with custom tools/scripts.

                • 5. Re: Can I get help with a Script?
                  StrongBeaver Level 3

                  This script was co-created by me and another unknown source.  I have forgotten what it does
                  Hopefully someone can take a look at it and tell me what it does ?

                   

                  Script Code Starts Here:

                  ===========================================================

                  //Script Jan 19th, 2010

                   

                  main();

                   

                  // It calls the other functions to change the visibility of the layer, duplicate it
                  // another document in PSD format and save the document.
                  function main(){
                     
                  if(documents.length > 0 && app.activeDocument.activeLayer.typename == "LayerSet") {
                  // define the layer names;
                  var theArray = ["diffuse", "bump", "specular", "reflection", "refraction"];
                  var savePath = decodeURI(activeDocument.path);
                  var theFileName = app.activeDocument.name;
                  // thanks to xbytor for the regexp;
                  var baseName = theFileName.match(/(.*)\.[^\.]+$/)[1];
                  // work through the array;
                  for (var m = 0; m < theArray.length; m++) {
                  var layerName = theArray[m];
                  // set the active layer to the layer of the name from the array;
                  // works only if the layersets are op level in the document;
                  app.activeDocument.activeLayer = app.activeDocument.layers.getByName(layerName);
                  var theFile = dupLayers();
                  var SaveFile= File(savePath+"/"+baseName+"_"+layerName+".psd");
                  SavePSD(SaveFile, theFile);
                  theFile.close(SaveOptions.DONOTSAVECHANGES);
                  }
                  else {alert ("please open a document and select a layer group")}
                  };

                   

                  //changes the view from visible to hidden and vice-versa
                  function toggleLayerView(name){
                      var actionTaken = charIDToTypeID( "Shw " );
                      var actDescription = new ActionDescriptor();
                      var id22 = charIDToTypeID( "null" );
                          var actList = new ActionList();
                              var actReference = new ActionReference();
                              var objectType = charIDToTypeID( "Lyr " );
                              actReference.putName( objectType, name );
                          actList.putReference( actReference );
                      actDescription.putList( id22, actList );
                      var id24 = charIDToTypeID( "TglO" );
                      actDescription.putBoolean( id24, true );
                  executeAction( actionTaken, actDescription, DialogModes.NO );
                  var al = activeDocument.layers.getByName(name);
                     if(al.typename == 'LayerSet'){
                         for(i=0;i<al.layers.length;i++){
                                  al.layers[i].visible=!al.layers[i].visible;
                             }
                         }

                   

                  }

                   

                  //copies the layers in a new document
                  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+".psd" );
                          var ref74 = new ActionReference();
                          ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                      desc143.putReference( charIDToTypeID('Usng'), ref74 );
                      executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
                  };

                   


                  //selects the layer
                  function selectLayerByName(name) {
                          var desc = new ActionDescriptor();
                          var ref = new ActionReference();
                          ref.putName( charIDToTypeID('Lyr '), name );
                         desc.putReference( charIDToTypeID('null'), ref );
                         desc.putBoolean( charIDToTypeID('MkVs'), false );
                         executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
                  };

                   

                  //saves the file in PSD format
                  function SavePSD(saveFile){
                            psdSaveOptions = new PhotoshopSaveOptions();
                            psdSaveOptions.embedColorProfile = true;
                           psdSaveOptions.alphaChannels = true;
                           activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
                  }

                  =================================================================

                  Script Code Ends Here