18 Replies Latest reply on Dec 9, 2010 12:55 PM by dsackett

    Sorting bookmarks?

    dsackett Level 1

      InDesign CS4 has a sort bookmarks function--does anyone know how to invoke or replicate it in a script? This has been referenced before (http://forums.adobe.com/message/1106343#1106343) but wasn't answered. Googling around about it led me to discover that ID's bookmark sort goes by page order, but nothing about scripting. I'd love to be able to use the function without having to code a sort routine.

        • 1. Re: Sorting bookmarks?
          Harbs. Level 6

          Bookmark.move()

           

          Harbs

          • 2. Re: Sorting bookmarks?
            dsackett Level 1

            Yes, I saw that method, Harbs; I was looking for a way to invoke the whole sorting routine that ID CS4 uses, rather than repositioning a single bookmark in the stack.

            • 3. Re: Sorting bookmarks?
              Marijan Tompa [tomaxxi] Level 4

              I think this is what you want:

               

              app.menuActions.itemByID(95498).invoke();
              

               

              Hope that helps.

               

              --

              tomaxxi

              http://indisnip.wordpress.com/

              • 4. Re: Sorting bookmarks?
                dsackett Level 1

                Marjan--

                 

                Sweet! That's exactly it. Thank you.

                 

                And thanks for showing me how to find and invoke any menu item with your example. I was just toying with the GetMenuActions.jsx sample script, which uses

                 

                var myMenuActionNames = app.menuActions.everyItem().name;

                 

                to grab all the menu item names for writing to a text file. So, adding another line:

                 

                var myMenuActionIDs = app.menuActions.everyItem().id;

                 

                makes it easy to include the ID in the resulting text file by modifying text file writing line to something like this:

                 

                myTextFile.writeln(myMenuActionNames[myCounter]+"; id = "+ myMenuActionIDs[myCounter]);

                 

                With nudges like yours, I'll get the hang of this yet.

                • 5. Re: Sorting bookmarks?
                  Marijan Tompa [tomaxxi] Level 4

                  You are welcome!

                   

                  This function dumps all available menu items into one table:

                   

                  var myActions = app.menuActions;
                  var myActionsList = Array();
                  var counter = Number(0);
                  
                  for(var i = 0; i < myActions.length; i++){
                      myActionsList.push(String(myActions[i].name));
                      myActionsList.push(String(myActions[i].area));
                      myActionsList.push(String(myActions[i].id));
                  }
                  
                  var myDoc = app.activeDocument;
                  var myTextFrame = myDoc.pages[0].textFrames.add();
                  myTextFrame.geometricBounds = app.activeDocument.pages[0].bounds;
                  
                  var myMenuActionsTbl = myTextFrame.insertionPoints[0].tables.add();
                  myMenuActionsTbl.columnCount = 3;
                  myMenuActionsTbl.bodyRowCount = myActions.length;
                  myMenuActionsTbl.contents = myActionsList;
                  

                   

                  --

                  tomaxxi

                  http://indisnip.wordpress.com/

                  1 person found this helpful
                  • 6. Re: Sorting bookmarks?
                    Peter Kahrel Adobe Community Professional & MVP

                    Nice one, Marijan. I had hoped that I would find in that table some menu action to discard the RGB and CMYK profiles (Edit > Assign Profiles > Discard (twice)), which reduces document size by about 700 Kb. I could find "Assign Profiles. . ." but nothing from in that dialog. Do you have any ideas?

                     

                    Thanks,

                     

                    Peter

                    • 7. Re: Sorting bookmarks?
                      Harbs. Level 6
                      doc.rgbPolicy = doc.cmykPolicy = ColorSettingsPolicy.COLOR_POLICY_OFF;
                      
                      

                       

                      Harbs

                      • 8. Re: Sorting bookmarks?
                        Peter Kahrel Adobe Community Professional & MVP

                        Thanks, Harbs. I tried that one a while ago, but it doesn't work.

                         

                        P.

                        • 9. Re: Sorting bookmarks?
                          Marijan Tompa [tomaxxi] Level 4

                          Hey guys!

                           

                          Sorry for delayed answer, I was on family trip today.

                          I'll try to find it Peter, or a way to shut it down

                           

                          Cheers!

                           

                          --

                          tomaxxi

                          http://indisnip.wordpress.com

                          • 10. Re: Sorting bookmarks?
                            dsackett Level 1

                            I'll add my thanks, again, Marijan, for the list and a fine example of using array attributes. I've had a little experience using complex arrays in VBA, was looking for something similar in javascript, and how you managed the the three menuAction attributes shone some light on how to look at it.

                            • 11. Re: Sorting bookmarks?
                              Marijan Tompa [tomaxxi] Level 4

                              You are welcome!

                               

                              The fact is, I'm also still learning

                              Every day I learn something new and find out something exciting!

                               

                              Great thing with Arrays is if you throw it into table,

                              it populates table with Array values! Cool!

                               

                              I just found out that this line does nothing:

                               

                              var counter = Number(0);
                              

                               

                              You can delete it from snippet

                               

                              --

                              tomaxxi

                              http://indisnip.wordpress.com/

                              • 12. Re: Sorting bookmarks?
                                Harbs. Level 6

                                I just checked and this seems to do it:

                                doc.rgbProfile = doc.cmykProfile = "";

                                 

                                Harbs

                                • 13. Re: Sorting bookmarks?
                                  Peter Kahrel Adobe Community Professional & MVP

                                  You've made my day!

                                  Thanks very much.

                                   

                                  Peter

                                  • 14. Re: Sorting bookmarks?
                                    [Jongware] Most Valuable Participant

                                    Related to this (also to IDSecrets: MenuID or MenuAction):

                                     

                                    Is there any way to get the language independent string version of the menu actions? I searched hi & lo, even in the SDK, but there seems to be no listing of stuff like "$ID/RtMouseLayout".

                                    • 15. Re: Sorting bookmarks?
                                      Harbs. Level 6

                                      You can get it out of the debug.

                                       

                                      What are you looking for?

                                       

                                      Harbs

                                      • 16. Re: Sorting bookmarks?
                                        [Jongware] Most Valuable Participant

                                        Ah -- the elusive "debug" versions of InDesign ...

                                         

                                        Well, I'd think that the recommended way of calling menu actions would not be by Menu Name (since these can be localized), and using id #s is so ...  unnecessary! Since, as we all know, all menus have a language-independent descriptional name; and we all know that because we all have read the JS Ref Guide, where the $ID/RtLayout(etc) menu is mentioned in an example of invoking menu actions.

                                         

                                        But the entire system, smart as it may be, falls apart if you can use, but not actually get hold of the proper menu action names in a script!

                                        • 17. Re: Sorting bookmarks?
                                          Steven.. Level 3

                                          Menu actions do not have unique names. The string supplied with action

                                          is the text for the menu calling this action, which may be the same

                                          for multiple menus, since many menus can share one menu action. The

                                          only unique characteristic of an action is its id.

                                          • 18. Re: Sorting bookmarks?
                                            dsackett Level 1

                                            Just thought I'd post back how I've mostly solved my bookmark sorting puzzle. This is a weird case because of how the newsletter headlines are set up, with news item numbers in brackets at the start of the headline, e.g. "[9] Headline Text."

                                             

                                            The InDesign bookmark sort works for most cases, since it sorts alphabetically by page, but when a page has headlines that start with [8], [9], [9.1], [9.2] & [10], the bookmark sort function will order these [10] [8], [9.1], [9.2] & [9]--not what's required. Javascript can sort on floating point numbers; so the solution required pulling the number out of the headline & keeping that number's relationship to the rest of the headline. Enter the object, the javascript equivalent to a complex array.

                                             

                                            I started with the Bookmarks.jsx from scripting samples & modified it to loop through an array of headline styles, since headlines I need to bookmark have different styles. Using an object constructor to hold the news item number, the bookmark name and a reference to the bookmark text, the script assembles an array of headlines to bookmark, uses a sort function to sort on the numeric story item values, then creates the bookmarks in the correct order.

                                            ----
                                            snip
                                            ----
                                                 // now with a full array of NLbookmarks, sort and create document bookmarks
                                                 NLbookmarks.sort(sortByItemNum);                    
                                                 for (var b = 0; b < NLbookmarks.length; b++) {
                                                      docRef.bookmarks.add({name:NLbookmarks[b].bmName, destination:NLbookmarks[b].bmDest});
                                                 }
                                            ----
                                            snip
                                            ----

                                             

                                            function NLbookmark(itemNum, bmName, bmDest) {
                                                 //constructor for NLbookmark object
                                                this.itemNum = parseFloat(itemNum);
                                                this.bmName = bmName;
                                                this.bmDest = bmDest;
                                            }

                                             

                                            function sortByItemNum(a, b) {
                                                 //assumes sorting on a NLbookmark object
                                                var x = parseFloat(a.itemNum);
                                                var y = parseFloat(b.itemNum);
                                                return ((x < y) ? -1 : ((x > y) ? 1 : 0));
                                            }

                                             


                                            I'm still working on trapping for overset text, since a headline in the overset will cause the script to hang, and running the script when the bookmarks window is open causes ID to put  strange bookmarks in the list (Page 5678 ...?), then crash.

                                             

                                            Thanks, everyone, for your help and ideas!