10 Replies Latest reply on Oct 2, 2012 1:08 AM by Laubender

    assign goto url to all buttons

    mrdonthave

      Hi!

       

      I have a document with multiple pages.

       

      In the head of every page is a button (let say the name of it is in every case: 'buttonXY'). There are some more buttons at the pages, but with other names.

       

      How can i change every buttonXY-button's action (the button already have the action) 'go to url' (on all pages) to a specified url (to defined in the script or as input form).

       

      thanks a lot,

      Christian

        • 1. Re: assign goto url to all buttons
          mrdonthave Level 1

          ok ... i thought about and checked the document. it was a bit of nonsense i wrote in my question.

           

          every button gets another name while creating my document <- so the buttons names are unique.

           

          but i could care about that every button i want to change (not every -> only they i want to change) have the same pre-filled content.

           

          i have a great problem to get the content of a button ... tried a lot of "app.activeDocument.pages[1].buttons[1].gotoURLBehaviors.item[1]" and such ... but only got error-messages ... but in the case of search-and-replace all the buttons with the to specified pre-filled content i need a array of all button in the document and a foreach about all of them.

           

          i don't expect the whole script for that ... but some ideas (especially about to fetch the buttons gotoURLBehavior) woul be realy great!

           

          Thank you!

          • 2. Re: assign goto url to all buttons
            [Jongware] Most Valuable Participant

            mrdonthave wrote:

             

            [..] i have a great problem to get the content of a button ... tried a lot of "app.activeDocument.pages[1].buttons[1].gotoURLBehaviors.item[1]" and such ... but only got error-messages ...

             

            Can you try some more, but this time taking into account that Javascript starts counting at 0?

             

            It's not easy to write a complete script without seeing your actual document, but it seems you know exactly what you want to do (just not how to do it ).

            • 3. Re: assign goto url to all buttons
              mrdonthave Level 1

              hi Jongware,

               

              thank you for your answer.

               

              also, if i try "alert(app.activeDocument.pages[0].buttons[0].gotoURLBehaviors.item[0]);" i've got a error: "Fehlernummer 45 / Fehlerzeichenfolge: Objekt ist ungültig (Error Number 45 / Object is not valid)".

               

              what i want to do:

              in my document i have a lot of buttons in a lot of pages (the document is generated auotmaticly) and i only want to change the content of this buttons with a to specified content (search/replace for the goto url behaviour field). all other buttons should be unchanged. (MAYBE thats important: the buttons are grouped with other elements)

               

              thank you,

              Christian

              • 4. Re: assign goto url to all buttons
                [Jongware] Most Valuable Participant

                You got me worried there for a moment! I got the same error. That had me examine the object hierarchy for buttons, but the problem wasn't in there. After some lateral thinking, I found you got a basic Syntax Error:

                 

                alert(app.activeDocument.pages[0].buttons[0].gotoURLBehaviors.item[0] )

                 

                -- the problem is "item[0]". "item" is a function, not an array (it's a function that returns the nth item from its parent array). So you should either use

                 

                ...gotoURLBehaviors[0];    // as array
                

                 

                or

                 

                ...gotoURLBehaviors.item(0); // as function
                

                 

                (Personally I prefer the array [..] notation, but 'item(x)' has a number of useful overrides. For your purposes, it shouldn't matter which notation you use -- but only when you're using them correctly.)

                (Speaking about "worried": normally I would refer you to a reference webpage for Buttons, but it seems it's down. ...)

                 

                If you have more than one button on a page, you can test which one(s) have gotoURL actions using something like this:

                 

                pg = app.activeDocument.pages[0];
                
                for (i=0; i<pg.buttons.length; i++)
                {
                  if (pg.buttons[i].gotoURLBehaviors.length > 0)
                  {
                    .. // do something with this button
                  }
                }
                
                • 5. Re: assign goto url to all buttons
                  mrdonthave Level 1

                  Jongware, thank you again!

                   

                  yes ... now you help me a bit to identify methods and variables. :-)

                   

                  but nevertheless at the moment i don't understand how i can systematicly reach a value or function.

                   

                  in php for example i can print out a whole object or array (print_r()) and can systematicly fetch that what i need ...

                   

                  now i have upped my (cleaned) .indd here.

                  there you can see, at every header is a button with the action gotourl and the value: "navto://lbt_einstieg_h" <- and I want to search and replace that to (for example) to "navto://XYZ_einstieg_h" on every page in the document.

                   

                  There are more buttons in the upper right side for open and close a hover <- they should be untouched by the script.

                   

                  could you please took a look about it?

                   

                  thanks,

                  Christian

                  • 6. Re: assign goto url to all buttons
                    [Jongware] Most Valuable Participant

                    Something like this? This code inspects all buttons in the document and gathers the ones with a single gotoURLBehavior. It shows the list in a simple dialog, where you can also enter a new URL. Press OK to change the listed URLs, or Cancel to bail out.

                     

                    If the dialog shows other URLs than the one(s) you want to change, you'll have to devise a way to discern these. (Although another way could be to add checkboxes for each one to change, but that's a bit more work )

                     

                    allButtons = app.activeDocument.buttons;
                    urlButtons = [];
                    urls = [];
                    
                    for (i=0; i<allButtons.length; i++)
                    {
                      if (allButtons[i].gotoURLBehaviors.length == 1)
                      {
                        urlButtons.push (allButtons[i]);
                        urls.push (allButtons[i].gotoURLBehaviors[0].url);
                      }
                    }
                    
                    urlDialog = app.dialogs.add ({name:"URL buttons",canCancel:true});
                    with (urlDialog)
                    {
                     with (dialogColumns.add())
                     {
                        for (i=0; i<urls.length; i++)
                          staticTexts.add ({staticLabel:urls[i]});
                    
                    
                        edBox = textEditboxes.add({editContents:"http://www. ...", minWidth:240});
                     }
                    }
                    if (urlDialog.show())
                    {
                      for (i=0; i<urlButtons.length; i++)
                        urlButtons[i].gotoURLBehaviors[0].url = edBox.editContents;
                    }
                    
                    • 7. Re: assign goto url to all buttons
                      [Jongware] Most Valuable Participant

                      Ah, I see my Class Reference is up again! The page I wanted to show you displays the hierarchy for this 'behavior' in a button: http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_GotoURLBehavior.html

                      • 8. Re: assign goto url to all buttons
                        mrdonthave Level 1

                        thank you Jongware! thats exactly what i want. but i forgot to say - and to redo it in the .indd - all elements on every page are one-time-grouped.

                         

                        I think there must only changed the first line:

                         

                        allButtons = app.activeDocument.buttons;

                         

                        but i frustrated by try-and-erroring and only see: "wrong object" or seeing the script does nothing.

                         

                        (ungrouped the script works perfectly an does exact that what i want!)

                         

                        Christian

                        • 9. Re: assign goto url to all buttons
                          mrdonthave Level 1

                          for me i found another script, that ungroups everything at the document -> then the script above works. thats a solution for me (it's not important to hold the elements grouped).

                           

                          a idea, how i could fetch a element in a group would be nice - but at lowest priority! ;-)

                           

                          thank you!

                          • 10. Re: assign goto url to all buttons
                            Laubender Adobe Community Professional & MVP

                            @mrdonthave – ok. If you want to get all Button objects in a document, equal if grouped or not, if inserted inside a graphic frame or not, you could loop through "allPageItems" of the document and fetch the "Button" objects by looking at the "constructor.name" or ask if the page item in question is "instanceof" a Button. No need to un-group objects…

                             

                            In case of MultiStateObejcts (MSOs), it's getting a bit weird…

                             

                            With "allPageItems" you can only reach all page items that are in the active state of an MSO. To reach Button objects of different states you have to cycle through the MSO and make all states one after another the active one. Otherwise you could miss Buttons in none-active states…

                             

                            Uwe