11 Replies Latest reply on Nov 25, 2016 3:29 PM by iamwickedtall

    Can't rename layers Photoshop

    iamwickedtall Level 1

      I'm getting inconsistent errors with the below script. It's saying that the program could not complete the requested action.

       

      app.activeDocument.layers[0].name = "test";
      

       

      Strangely, I just found out how to view the error log, and to be clear I was capturing the right error, I deleted the whole log contents, and now the script runs fine. Does anyone have an explanation for this? Or otherwise know what might be causing the issue?

        • 1. Re: Can't rename layers Photoshop
          iamwickedtall Level 1

          Experienced the same error again, nothing gets written to the log file, and it doesn't properly name the layers.

          • 2. Re: Can't rename layers Photoshop
            JJMack Most Valuable Participant

            I have tried hard to reproduce your problem on my Dell Windows 10 system. I had created documents with all sort of layers, Smart object, normal layers, Adjustment layers etc. Layer groups and nested groups.  Visible layers. Locked layers, Visibility turn off on layers etc. I created a script to rename all layers to test. I have not been able to reproduce your problem.

             

            Here is the script I wrote.

             

            #target photoshop // this command only works in Photoshop CS2 and higher

            app.bringToFront();

             

            if (!documents.length) { alert('There are no documents open.', 'No Document');}

            else {processArtLayers(activeDocument);}

             

            function processArtLayers(obj) {

                for( var i = obj.artLayers.length-1; 0 <= i; i--) {obj.artLayers[i].name = "test"; } // Rename layer

                for( var i = obj.layerSets.length-1; 0 <= i; i--) {processArtLayers(obj.layerSets[i]); } // Process Layer Set Layers

            }

            1 person found this helpful
            • 3. Re: Can't rename layers Photoshop
              Chuck Uebele Adobe Community Professional & MVP

              If you attempt to rename a background layer, you might get that error.

              • 4. Re: Can't rename layers Photoshop
                JJMack Most Valuable Participant

                No problem renaming the background layer. Photoshop make it a normal layer and renames the layer. I tested CS2. CS6. CC, CC 2014, cc2015 and CC 2015.5. The script I wrote rename every layer in a document "test" including the background layer.. The rename never failed  Background layer were made normal layer and layers with their visibility off were turned visible.

                • 5. Re: Can't rename layers Photoshop
                  Level 1

                  JJ MACK

                  you could rename only selected layers

                  and not all.

                  1 person found this helpful
                  • 6. Re: Can't rename layers Photoshop
                    iamwickedtall Level 1

                    Thanks JJ! I am not sure what's happening here, especially since these are occurring inside a try so they shouldn't side.:: weird part is, I tried one, and additionally later on and it was fine, thoughts on structure etc are welcome.

                    • 7. Re: Can't rename layers Photoshop
                      iamwickedtall Level 1

                      That's a first, just searched the adobe forums, and found my own question RE the same issue. I still am not sure what causes this, but I was able to find out a couple things. I can replicate it easiest by using the action below, maybe since I created it in an old version, and running the below, isn't formatting the exact same. In fact if I disable the first 4 steps, it doesn't cause an issue.
                      Screen Shot 2016-11-21 at 8.39.20 PM.png

                      I was however able to figure out a scripting work around, it seems if I create and delete a layer before running this, it negates whatever error is occurring.

                       

                      var decoyLayer = activeDocument.artLayers.add();
                      decoyLayer.remove();
                      app.activeDocument.layers[0].name = "test";
                      

                       

                      This is definitely a bug, but this workaround is fairly painless. Other option that I didn't seem to run into issues with was renaming the selected layer after running my action.

                      1 person found this helpful
                      • 8. Re: Can't rename layers Photoshop
                        JJMack Most Valuable Participant

                        When you post an action like that we have have no way to know how you recorded it or what it does because the action steps you show are collapsed. We can not see what options and setting you used.  Actions often have dependencies they can only be used on document the have what they depend on.

                         

                        In  the future when you  post an action expand it fully or save all your actions as a text file then extract the action you are having a Problem with and post its text.  There are thing that can not be done in an action that are easy to do in a script.  However, scripting is hard its actual programming, but Actions can record using a script.

                         

                        If you want to record an action that will convert the bottom layer to a normal if the bottom layer is a background layer you can not do the with an action without using a little scripting. Even using a conditional action that can test if the current layer is a background layer because you can select the background layer by name.  If the bottom layer is not a background layer a select background step would throw and error.  Recording the shortcut Alt+,  may also fall to select the bottom background layer.  For the Relatives addressing layers shortcut only target visible layers and it is possible that a layer document with a background layer has the background layer's  visibility off.  Actions that need to deal with the bottom layer can be hard to create particularity if you want to batch the action.

                         

                        It is easy to deal with the bottom layer in a script.  In my crafting action Package I make it easy for an action crater also.  In that package I include a dozen scripts an action creator can use in actions so they can do things the is not possible without using scripting. Without needing to code the script. Two deal with the bottom layer.

                         

                        One is "convert background".  An action would use that script to convert the background layer to a normal layer.  If the document bottom layer is a background layer the script will convert it to a normal layer and it will become the current target.  If the bottom layer is not a background layer it will become the current target.  So after using the script the document bottom layer will be a normal layer and be the current target.

                         

                        The second script is "selec tBackground" when an action uses that script the script will look at the bottom layer. If the bottom layer is not a background layer the script will add a normal layer to the bottom of the layer stack and make it a background layer.  When the script ends the background layer will be the current Photoshop target.

                         

                        Actions can fail for many reasons there may be not current target layer when an action is played an one layer is expected to be targeted  or a active selection is expected and there is none. Or a layer X is select by name in the action and the document has no layer x.  A common error messaged you will see is function or command not available or supported in this version of Photoshop.

                         

                        Crafting Actions Package UPDATED Aug 10, 2014 Added Conditional Action steps to Action Palette Tips.
                        Contains

                        Example
                        Download

                        • 9. Re: Can't rename layers Photoshop
                          iamwickedtall Level 1

                          Thanks again! As I mentioned, I found that it was somewhere within the first 4 steps of the action that were causing the issue for me, not the remaining collapsed steps which is why I did not expand. I tested each of those 4 individually, and found that and found consistently, after running "Deselect Layers current layer" throws the error every time, when trying to run the rename script. I even tested simply running as "Deselect Layers" in the menu, and it still threw the error. Each time I tested I would duplicate a clean file, (sometimes running the rename script to be sure it worked), run the action or menu item, and it throws the error every time, without the addition of my workaround. I tested a newly recorded 4 steps as well, which is negated anyway as I mentioned you can just run it from the menu to invoke the error. I tested on single and multiple layer files.

                           

                          It seems that deselect layers can't be the last layer command run before trying to name the layer, or it will throw an error. Additional steps can even be run manually in photoshop, adding/deleting a layer, select all layers, are the 2 I tested thus far. As you mentioned I did not run into any errors running the script on a single layer background.

                           

                          I also found, even with "Make Layer Visibility Changes Undoable" selected, visibility steps run through actions do not get recorded to history. I did not find any correlation between this and the error thrown, but did explore just in case.

                           

                          Although I've been experiencing this error on a few different OS, hardware and software combinations, my versioning is as follows:

                           

                          macOS Sierra 10.12.1
                          Adobe Photoshop CC 2015.5.1

                          • 10. Re: Can't rename layers Photoshop
                            JJMack Most Valuable Participant

                            Yes the first step in your action is select all cruent layers.  What would happen if no layer was currently targeted.  What your script does is add a layer which would make the new layer the current layer. Then you delete the added layer which would cause the layer in the stack under what was the delete layer to become the current layer.  Your action would than work.

                             

                            I have even had problems in scripts when a user use menu File>Scripts>MyScript.  When the script was used without there being a layer targeted the script would generate an error.  I had to put the  Main function in a try catch,  The catch would  target the top layer then use the Main function than Main would work as designed.

                             

                            Is not having a current layer a bug and Photoshop design problem, a user error.  You be the judge.  All four of your first four step need there to be at lease one current layer.

                             

                            The Problem may well be the first step from what I see select all layers(Atl_Ctrl+A) select all layers but the background layer.  If there is only a background layer in the background layer can not be hidden and is the current target layer.  In the select menu the item Select all layers current layer (alt+Crl+A) is grayed out and Photoshop does nothing if  use Atl+ctrt+A

                             

                            If you had two layer a background layer and a layer above it with it visibility off step one would target the hidden layer what would step 2 do hide current layer do when the layer is all ready hidden.

                             

                            You action's first for steps seems to work for all document but the most simple one a document with just a background layer like a jpeg file would have.

                             

                            The only time I have used Select All Layers is to follow it with show current layer.  It is the only way I know how to target hidden layers  without selecting the layers by name.  All hidden layer will be made visible with Show current layer with a possible exception a hidden background layer will still be hidden.

                             

                            I have never use deselect all layers for I never found I needed to have no layer targeted but  some day maybe I will.

                             

                            Some strange thing can happen in actions when unexpected condition are encountered.  Most actions can faile when something unexpected is encountered.

                            • 11. Re: Can't rename layers Photoshop
                              iamwickedtall Level 1

                              Photoshop lets you run the action with deselect, with no errors shown regardless of if there is a layer selected, yes the menu command is grayed out. Both select all and deselect all, to your point throw errors in an action, if there is only a background layer.

                               

                              The actions I'm running, I tend to be the conditional variable on prep, choosing which one based on the results I want to get, as part of a quality control workflow.

                               

                              I have wrapped the simple "app.activeDocument.layers[0].name = "test";" in conditionals to only execute if there is only 1 layer, naming it something descriptive through lots of regex analysis. But I only extracted this line to further debug. Photoshop needs at least one layer in any document, so select all layers would in fact select at least 1 layer as current. Sounds like we're using select all for the same reason. Deselect all, is probably habit of writing actions in Illustrator, where if you select all, and then select a swatch, brush etc, you're hosed and your art has changed. The only scenario for PS I can think of off the top of my head, is if you have an shape layer involved, and you're setting fills and strokes for those paths. Even with a raster item included in the selection, it'll transform only the shape layers to whatever was recorded.

                               

                              Thanks again for the back and forth, definitely some things to think about, good to know I'm not the only one running into these types of inconsistencies. Generally a head scratcher when one runs into something like this, but I'm glad to have figured out a work around.