23 Replies Latest reply on Apr 10, 2008 7:04 AM by (Avi)

    About Master page

      I want to Set up multiple master pages, and base one master page on another to help keep designs consistent when updating documents. Using my script i am able to create a A- Matser but i want to create B-Master, C-Master... What changes i need to do to make multiple master.

      Thnak you.
        • 1. Re: About Master page
          [Jongware] Most Valuable Participant
          (Untested:) MasterSpread has a property 'appliedMaster', which I think means you have to create a new master spread first, then set appliedMaster to your A-Master.

          I guess the easiest way is to use duplicate on A-Master, set the appliedMaster prop on this new one to A-Master, then apply changes on the new one.
          • 2. Re: About Master page
            Level 1
            I am new to Javascript. Can you tell me how to write a script to duplicate on A-master and how to use that master or how to apply that master to any document.
            • 3. Re: About Master page
              [Jongware] Most Valuable Participant
              It's staggering simple.

              >var newMaster = app.activeDocument.masterSpreads.add();

              >newMaster.appliedMaster = app.activeDocument.masterSpreads.item("A-Master");

              This creates a new (empty) master and sets its 'applied'. My 2nd idea of duplicating an existing one, using

              >var newMaster = app.activeDocument.masterSpreads.item("A-Master").duplicate();

              i does
              work, but then you get all items duplicated as well (once from the original master, once from the master page).

              Applying this new master to your pages is equally simple. How about

              >app.activeDocument.pages[0].appliedMaster = newMaster;

              You don't need "pages.items(0)" here -- you can use the index immediately.
              • 4. Re: About Master page
                Level 1
                Thank you jongware,

                I just have a small question. If i have name the new master as "B-master". what should i do then.
                • 5. Re: About Master page
                  [Jongware] Most Valuable Participant
                  If you changed the name using the previously gotten pointer "newMaster", you can still use that variable, even after you changed the name of the master.

                  If you need the pointer some time later, use


                  -- that'll work every time.
                  • 6. Re: About Master page
                    Level 1
                    When i am using your script


                    I want to change the name of master "B-Master" to some other name as "B-First Page". When i am trying to change the name in above script still it will take as "B-Master". Is there any way to change the name.

                    What i want is, I want the name of B-Master as B-First Page in my pages section.

                    Thank you for your help.

                    • 7. Re: About Master page
                      [Jongware] Most Valuable Participant
                      D'ya mean you want to rename 'B-master' to something else?

                      Ordinarily, I'd refer you straight to the Help! From this point on, you can find all you need in the ESTK. In this case, you should look for something called 'name' -- all named objects should have one. But, strangely, although MasterSpread
                      i does
                      have a 'name' property, it's marked as "read-only".


                      Try changing one or both of the properties 'namePrefix' ("The prefix of the master spread name.") and 'baseName' ("The name of the master spread."). I have some idea in mind what would/should happen, but no time to try it out for you right now.
                      • 8. Re: About Master page
                        Level 1
                        I tried all the stuff it gives me error as invalid object MasterSpread. In my opinion we are using MasterSpreads and then activeDocument will be MasterSpreads not MasterSpread. There is no property to rename the master

                        var newMaster = app.activeDocument.masterSpreads.item("A-Master").duplicate();
                        app.activeDocument.masterSpread.name("B-First Page");

                        I tried above stuff but it wound not work. Do you have any other way.
                        • 9. Re: About Master page
                          [Jongware] Most Valuable Participant
                          >app.activeDocument.masterSpread.name("B-First Page");

                          is just a single pointer to something. You aren't
                          i doing
                          anything to it by putting it on a single line.
                          Besides that, I noticed a few other possible reasons for an error. It is not 'MasterSpread', but 'masterSpreads'.

                          JS is CaSe-SeNsItIvE. 'MasterSpread' is the type of object (just as 'String', 'Number').
                          Its instance in activeDocument (which is a 'Document') is called 'masterSpreads' -- plural.

                          Referring to "app.activeDocument.masterSpread.name("B-First Page");" (by name) only works if you already
                          i have
                          an object with that name; you can't set the name with it. For setting the name, see my thought in post #7.
                          • 10. Re: About Master page
                            Level 1
                            app.activeDocument.masterSpread.name("B-First Page");

                            I tried above script as well. But i am getting error as "Object does not support the property or method masterSpread". Now tell me what should i do.
                            • 11. Re: About Master page
                              Level 1
                              One of the reasons I've not joined this topic is because when it comes right down to it, I don't have a clue what you're actually trying to do.

                              Collections exist as properties of the parent/owner object. You address them using plurals. If you want one of them and you know its name you write (for the master spread of the active document named "B-First Page"):

                              app.activeDocument.masterSpreads.item("B-First Page");

                              • 12. Re: About Master page
                                Level 1
                                app.activeDocument.masterSpreads.item("B-First Page");

                                I tried above script as well. But still it will not change the name. Above script will not give you an error but it will not rename the master name.
                                • 13. Re: About Master page
                                  Level 1
                                  Ah, you want to change the name!

                                  app.activeDocument.masterSpreads.item("B-First Page").baseName = "Hello Ducky";

                                  • 14. Re: About Master page
                                    Level 1
                                    Thank you dave and jongware. This is what i want.
                                    But i have a question for you. Where did you get .baseName. I tried lot but i could not foind in masterSpreads. Where did u find it and how. Please tell me this will help me to find complicated stuff.
                                    • 15. Re: About Master page
                                      Level 1
                                      I guess I've known about it for ages. I first used it in InDesign CS. For CS2, it's on page 876 of the Scripting Reference PDF. For CS3, it's in the InDesign CS3 OMV in the properties of the MasterSpread class of objects.

                                      • 16. Re: About Master page
                                        [Jongware] Most Valuable Participant

                                        Did you actually read my post #7? And my post #9?

                                        You succeeded in repeating the same "instruction" (I think you believe it is one) 3 times, and asking the same question why it din't work. Now you ask Dave (who kindly jumped in) how to do something I explained in #7. Dave knows all properties and methods by heart -- I don't, so I looked it up in the ESTK help. There I read

                                        >MasterSpread: baseName (string, r/w) The name of the master spread.


                                        >Please tell me this will help me to find complicated stuff.

                                        ... look in the Help.

                                        You might have looked up "masterSpreads", but that's not an object, and it doesn't have methods or properties of its own. It's an array of MasterSpread objects in a Document, its description in the Help is

                                        >A collection of master spreads.

                                        with a
                                        i type
                                        of MasterSpread.
                                        • 17. Re: About Master page
                                          Level 1

                                          Take care not to confuse collections and arrays. They're similar but there are significant differences.

                                          • 18. Re: About Master page
                                            [Jongware] Most Valuable Participant
                                            Yeah, I used both in one sentence. But in that case, shouldn't the help on 'masterSpreads' read 'An
                                            b array
                                            of master spreads'? Since you can use


                                            and that's array indexing. Mind, I never had any problems with either :-)
                                            I've seen a few posts on differences between CS2 and '3, concernin' addressing items like these -- is that connected?
                                            • 19. Re: About Master page
                                              Level 1
                                              Sorry to trouble you both but thank you.
                                              Thanks a lot.
                                              • 20. Re: About Master page
                                                Level 1
                                                With collections, when you write:


                                                you're simply using a syntactic shortcut for:


                                                and the big difference is that you can use negative indexes with the .item() method, whereas you can't with arrays -- negative indexes "work" with arrays, but they don't have the same meaning because arrays are really associative and if you set a value to anArray[-1], it creates a new member of the array with the index -1 rather than refer to the last member of the array.

                                                Thus, in CS2, when referring to the text frames that make up a story, you can write:


                                                to refer to the last one because the textFrames property of a CS2 story is a collection. But in CS3, the more accurate term textContainers is used (because the story can include textPaths), but it is only an array. So, to get the last one you have to write:

                                                myStory.textContainers[myStory.textContainers.length - 1];

                                                • 21. Re: About Master page
                                                  Level 1
                                                  Hello Dave,

                                                  Can you tell me where i can get the sample script for hyperlink.
                                                  Hyperlink is most difficult part in the indesign and i need to done it by automation using javascript. Is there any way to get sample script or did you have any script which uses hyperlink. Please let me know.

                                                  • 22. Re: About Master page
                                                    Level 1
                                                    Hyperlinks can be used in a variety of ways. What are you trying to do with a hyperlink?

                                                    If you just want to cause a browser to open at a URL, you can use this function:
                                                    function goToURL(theURL) {
                                                      var aDoc = app.documents.add(false);
                                                      var myDest = aDoc.hyperlinkURLDestinations.add(theURL);
                                                    For another example, check out Teus de Jong's cross-reference script which can be downloaded from here:


                                                    • 23. Re: About Master page
                                                      Level 1

                                                      I am creating 10 document in indesign. There are up and down arrow in the Document which i created using javascript. I want to apply a hyperlink to them. It means that when you hit the down arrow the next page will come and if you hit up arrow previous page will come.

                                                      For example currently you are on third document if you hit up arrow it will go to second document and if you hit down arrow it will go to forth document.