11 Replies Latest reply on Jun 6, 2009 7:47 AM by patti26

    Delete defined bookmarks

    patti26

      Hello together,

       

      i need help for this script. I will delete bookmarks with a name"EXP". The script at the end works, but only for one bookmark, then the script end.

      The structure of the bookmarks look like

       

      12345678901

           +EXP

                +Zeichenansicht1

                +Zeichenansicht2

      23456789012

           +EXP

                +Zeichenansicht1

                +Zeichenansicht2

           .

           .

           .

           .

           .

      depending on the map, it is up to 150. Now i must delete manual. The script just work for only one Bookmark.

      pls help

      thx

       

       

       

      SCRIPT:

       

      // Löschen der Bookmarks EXP und darunterliegender Bookmarks
      //
      var bkm=searchBookmarks(this.bookmarkRoot, 1, "EXP");
      console.println("Programmende --- " + this.bookmarkRoot.name);
      //bkm.execute();

      function searchBookmarks(bkm, nLevel, bkmName)
      {
      if (bkm == null) return null;
       
      if (bkm.name == bkmName)
        {
                      console.println("Knotenname: " + bkm.name);
          bkm.remove();
                      return null;
        }
      if (bkm.children != null)
        console.println("Anzahl Childs: " + bkm.children.length);
      var s=""
      for (var i = 0; i < nLevel; i++) s += " ";
        for (var i = 0; i < bkm.children.length; i++)
         {
         var bkMark = searchBookmarks(bkm.children[i], nLevel +1, bkmName);
         if ( bkMark != null ) break;
                  console.println("Childrenname: " + bkm.children[i].name);
         }
         return bkMark;
           
      return null;
      }

       

       

      thx for help

      mfg Patrick

        • 1. Re: Delete defined bookmarks
          Bernd Alheit Adobe Community Professional & MVP

          First remove all unnessary code:

           

          Variable s is never used.

           

          Code 'if ( bkMark != null ) break;' makes no sense. Function searchBookmarks returns always 'null'.

          • 2. Re: Delete defined bookmarks
            patti26 Level 1

            thx for the quick reply,

             

            i have removed all unnessary code and the line with 'if ( bkMark != null ) break;' . But it is also the same, only one bookmark remove and then stop the script.

            This is the reply from the debugger of Acrobat:

            Anzahl Childs: 17
            Anzahl Childs: 1
            Anzahl Childs: 1
            Vor Anzeige Childrenname
            Childrenname: Zeichenansicht7
            Vor Anzeige Childrenname
            Childrenname: Blatt2
            Vor Anzeige Childrenname
            Childrenname: 10110192363
            Vor Anzeige Childrenname
            Childrenname: 10120000000
            Vor Anzeige Childrenname
            Childrenname: 10120000006
            Vor Anzeige Childrenname
            Childrenname: 10120000010
            Vor Anzeige Childrenname
            Childrenname: 10120000013
            Anzahl Childs: 1
            Knotenname: EXP
            BKM geloescht
            Vor Anzeige Childrenname

            bkm.children has no properties
            26:Batch:Exec

             

            I don´t know why only one bookmark will be deleted, because the println from the debugger replays all childrens.

             

            mfg Patrick

            • 3. Re: Delete defined bookmarks
              Bernd Alheit Adobe Community Professional & MVP

              You get a error message and the script stops. You get the error because you access a bookmark which was removed.

               

              You can collect all bookmarks with the specified name in an array. At the end you can remove all bookmarks in the array.

              1 person found this helpful
              • 4. Re: Delete defined bookmarks
                patti26 Level 1

                thx for the tip,

                 

                this is what i think too. I will try it at the weekend and give an answer next week.

                 

                mfg Patrick

                • 5. Re: Delete defined bookmarks
                  ReinhardF Level 3

                  HTH, Reinhard

                   

                  var BmToDel = "test" //bm to delete
                  RemoveBookmarks(this.bookmarkRoot, 0);

                  function RemoveBookmarks(bm, nLevel)
                  {

                       for (var i = 0; i < nLevel; i++)
                       if (bm.name == BmToDel){bm.remove()};
                       if (bm.children != null)
                         for (var i = 0; i < bm.children.length; i++)
                         RemoveBookmarks(bm.children[i], nLevel + 1);
                  }

                  • 6. Re: Delete defined bookmarks
                    patti26 Level 1

                    Dear Reinhart,

                     

                    i have tested your script, but i have the same error as my script.

                     

                    bm.children has no properties
                    17:Batch:Exec

                     

                    mfg

                    Patrick

                    • 7. Re: Delete defined bookmarks
                      Bernd Alheit Adobe Community Professional & MVP

                      Try this:

                       

                      var BmToDel = "test" //bm to delete
                      RemoveBookmarks(this.bookmarkRoot);

                      function RemoveBookmarks(bm)
                      {
                           if (bm.children != null)
                             for (var i = 0; i < bm.children.length; i++)
                               RemoveBookmarks(bm.children[i]);

                           if (bm.name == BmToDel) {bm.remove()};

                      }

                      • 8. Re: Delete defined bookmarks
                        patti26 Level 1

                        I´ve tried again, but the same. This time i tested with Acrobat version 6 and 8. The script only delete only one bookmark and stop with following error.

                         

                        Acrobat 6:
                        Type error:bm.children has no properties
                        8:Batch:Exec

                         

                        Acrobat 8
                        bm.children has no properties
                        8:Batch:Exec

                        • 9. Re: Delete defined bookmarks
                          ReinhardF Level 3

                          Ok,

                           

                          tested it only on 1.Level. That works. But on 2.Level = childlevel it fails.

                          Have to think about it - by time.

                           

                          best regards, Reinhard

                          • 10. Re: Delete defined bookmarks
                            Bernd Alheit Adobe Community Professional & MVP

                            Try this:

                             

                            var BmToDel = "EXP" //bm to delete
                            var arr = new Array(0);
                            var bm;
                            RemoveBookmarks(this.bookmarkRoot);
                            while (bm = arr.pop()) bm.remove();

                             

                            function RemoveBookmarks(bm)
                            {
                                 if (bm.children != null)
                                   for (var i = 0; i < bm.children.length; i++)
                                     RemoveBookmarks(bm.children[i]);

                                 if (bm.name == BmToDel) { arr.push(bm); };

                            }

                            • 11. Re: Delete defined bookmarks
                              patti26 Level 1

                              it works perferct, much thanks for help