2 Replies Latest reply on Feb 17, 2011 1:44 AM by gv1964

    Adding Bookmarks

    gv1964

      Hi,

       

      I had some problems creation bookmarks from a xml file with xml rules.

      Therefore I wrote the following basic script to track the error I got.

      The script inserts a root bookmark and a child in a new document.

      When the bookmark panel is closed everything is fine!

      When the panel is visible the root bookmark is created but then the child bookmark

      overrides the name of the bookmark or the name  is reseted to the default value ( bookmark 1 or in german Lesezeichen 1 e.g.)

       

      When I rename the parent name (  myParentBookmark.name = "root";) this is fixed is this simple case.

      But is this a feature or a bug?

       

      Another question:

      When I search the bookmarks for a bookmark with a special name like:

      var myParentBookmark = myDocument.bookmarks.item(myParentName);

      not all bookmarks and there child bookmarks are searched in ( I think because bookmarks on

      different levels /indents can have the same name)

      Is there a way to search all bookmarks ( the whole bookmark tree !) ?

       

      Thanks in advance

      Any hint is welcome

       

      Götz

       

       

       

      /**

      * @@@BUILDINFO@@@ BookmarkTest.jsx !Version! Mon Feb 14 2011 12:25:37 GMT+0100

      */

       

       

       

      main();

       

      function main(){

          mySetup();

          mySnippet();

          myTeardown();

      }

       

      //<setup>

      function mySetup(){

          app.documents.add();

         // alert ("Document created");

      }

      //</setup>

       

      //<snippet>

      function mySnippet(){

       

          //<fragment>

          var myDocument = app.documents.item(0);

          var myBookmark = app.documents.item(0).bookmarks.add({

                                                              destination:myDocument.pages.item(0),

                                                                     name:"root",

                                                                    label:"root" });

          // add a child bookmark to root   

          var myParentBookmark = myDocument.bookmarks.itemByName("root");

          var myChildBookmark = myParentBookmark.bookmarks.add({

                                                              destination:myDocument.pages.item(0),

                                                                     name:"child 1",

                                                                    label:"child 1" });

          // when the bookmark panel is closed everythink is fine

          // when the bookmark panel is opened the root element is renamed to the default name:

          // e.g. bookmark 1 or in german Lesezeichen 1 !!!

          // Bug or feature ?

        //   myParentBookmark.name = "root";  // this helps !!

       

          //</fragment>

      }

      //</snippet>

       

      //<teardown>

      function myTeardown(){

      }

      //</teardown>

       

       

      //////////////////

       

       

       

       

       

       

        • 1. Re: Adding Bookmarks
          gv1964 Level 1

          Hi,

           

          just some additional info:

          I work with InDesign CS5 on OS X 10.6.6.

           

          Could someone test the small script

          an confirm my problem?

           

          Thanks

          • 2. Re: Adding Bookmarks
            gv1964 Level 1

            Hi,

             

            I found a solution!

            I have to create a Hyperlink for every bookmark!

            See the adapted mySnippet() function.

            BUT the Bookmark name is named from the hyperlink and NOT from the property in the add method!

            Hope this helps someone else!

             

             

             

            //<snippet>

            function mySnippet(){

             

                //<fragment>

              var myDocument = app.documents.item(0);

                var myRootHyperlink =  myDocument.hyperlinkPageDestinations.add(app.documents.item(0).pages.item(0), {name:"root"});

             

             

                var myBookmark = myDocument.bookmarks.add({

                                                                    destination:myRootHyperlink,

                                                                           name:"root",

                                                                          label:"root" });

                // add a child bookmark to root   

                var myParentBookmark = myDocument.bookmarks.itemByName("root");

                var myChildHyperlink =  myDocument.hyperlinkPageDestinations.add(app.documents.item(0).pages.item(0), {name:"Child"});   

             

                var myChildBookmark = myParentBookmark.bookmarks.add({

                                                                    destination:myChildHyperlink,

                                                                           name:"child 1",

                                                                          label:"child 1" });

                // when the bookmark palette is closed everythink is fine

                // when the bookmark palette is opened the root element is renamed to the default name:

                // e.g. bookmark 1 or in german Lesezeichen 1 !!!

                // Bug or feature ?

              //  myParentBookmark.name = "root";

             

                //</fragment>

            }

            //</snippet>