9 Replies Latest reply on Jan 14, 2015 8:18 AM by captainfodder

    Can layers be sorted alphabetically in InDesign?

    paul@psl

      Please could someone tell me if layers can be sorted alphabetically in InDesign?

        • 1. Re: Can layers be sorted alphabetically in InDesign?
          Steve Werner Adobe Community Professional & MVP

          Sounds like it's probably scriptable. If you don't hear an answer from someone here, ask in the InDesign Scripting forum.

          • 2. Re: Can layers be sorted alphabetically in InDesign?
            Sandee Cohen Adobe Community Professional

            Steve's right about a script. But you do know that's going to send your objects into new z orders

            • 3. Re: Can layers be sorted alphabetically in InDesign?
              BobLevine MVP & Adobe Community Professional

              Probably by scripting but certainly not natively.

              • 4. Re: Can layers be sorted alphabetically in InDesign?
                Peter Spier Most Valuable Participant (Moderator)

                I'm not sure you want to sort the layers in ID, though. Changing the stacking order by sorting can have SERIOUS consequences for your document. Layers are not like styles or swatches where the order in the panel has no effect on the document structure.

                • 5. Re: Can layers be sorted alphabetically in InDesign?
                  captainfodder

                  Well I've found this script and it barely works.... So far it is only capable of sorting the layer groups, and it doesn't sort each object layer contained within. This is for Adobe Illustrator though.

                   

                  Basically what I'm trying to achieve is a layer group by state, then by provider, then by city, then the dot representing the city.

                  Example:

                  • Wyoming
                    • Charter
                      • Cable
                        • Gillette, WY

                   

                  That above script so far will sort everything except the final (deepest) layer, the one with the object (my dot).

                  • 6. Re: Can layers be sorted alphabetically in InDesign?
                    rob day Adobe Community Professional & MVP

                    A script to sort layers would be fairly simple see the Applescript below. The page items z-order on a layer can be manipulate via a script but unless you explicitly name an item in the Layers panel, you would not be able to sort them via scripting because by default they have no name. So in this case I gave the blue box the name Blue, the magenta rectangle by default is <rectangle>, but the scripting engine sees it as no name:

                     

                    Screen Shot 2015-01-13 at 3.49.38 PM.png

                     

                     

                    So what you are asking for could be done if you've gone through and given each page item a name and as others have noted there's no overlap between the items.

                     

                     

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

                     

                    tell application "Adobe InDesign CC 2014"

                        tell active document

                            set alphalist to my sort(name of every layer)

                            repeat with i from 1 to count of alphalist

                                set x to item i of alphalist

                                move layer x to before layer 1

                            end repeat

                        end tell

                    end tell

                     

                    on sort(l)

                        set old_delims to AppleScript's text item delimiters

                        set AppleScript's text item delimiters to {ASCII character 10}

                        set list_string to (l as string)

                        set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"

                        set new_list to (paragraphs of new_string)

                        set AppleScript's text item delimiters to old_delims

                        return new_list

                    end sort

                    • 7. Re: Can layers be sorted alphabetically in InDesign?
                      captainfodder Level 1

                      Thanks for your reply Rob

                       

                      I worked with a few people and managed to get it accomplished with .jsx script. I'm using Adobe Illustrator CC, so I was hoping that I might be able to "borrow" some code from what might have turned up here.

                       

                      Here is the script that we got drawn up to alphabetize pathItems within Illustrator, and the original code that sorts layers is at the top of the post:

                      Re: Re: Re: How to sort objects alphabetically (inside of a layer)?

                       

                      ***EDIT***

                      I pulled the script from that post just in-case that post goes down or gets deleted.

                      #target "Illustrator"
                      
                      
                      function alphabetize()
                      {
                           if (app.documents.length == 0)
                           {
                                alert("No document Open");
                                return;
                           }
                      
                           var docRef = app.documents[0];
                           var state = docRef.layers;
                      
                      
                           for (a = 0; a < state.length; a++)
                           {
                                var provider = state[a].layers;
                                for (b = 0; b < provider.length; b++)
                                { 
                                     var product = provider[b].layers;
                                     for (c = 0; c < product.length; c++)
                                     {  
                                          var town = product[c].pathItems;
                                          if (town.length > 0)
                                          {
                                               var townList = [];
                      
                                               for (d = 0; d < town.length; d++)
                                               { 
                                                    townList.push(town[d].name);
                                               }
                                               townList.sort();
                                               sort_layer(product[c], townList);
                      
                                          }
                                     }
                                }
                           }
                      }
                      function sort_layer (obj, array) {
                           for (var ri=0, riL=array.length; ri < riL ; ri++) {
                           obj.pathItems.getByName(array[ri]).zOrder( ZOrderMethod.SENDTOBACK );
                           };
                      }
                      alphabetize();
                      
                      • 8. Re: Can layers be sorted alphabetically in InDesign?
                        rob day Adobe Community Professional & MVP

                        I think the problem you will run into is InDesign and AI layers don't have the same functionality. In AI you can drag a layer inside of another layer, don't think you can do that with ID. The "sub layers" you see in ID are actually page items. You could sort the layer order of the page items but only if you have given them names. Have you done that and can you share a sample?

                        • 9. Re: Can layers be sorted alphabetically in InDesign?
                          captainfodder Level 1

                          Unfortunately Rob, I've never used InDesign and don't have the program installed. I was simply cross posting what I've figured out with my Illustrator problems to here (mainly because I posted in here for help), in hopes that what I've found will help someone else figure out their problems.

                           

                          Thanks!