5 Replies Latest reply on Sep 26, 2011 2:09 PM by Harbs.

    Applying master to a collection of pages

    Ken Krugh Level 1

      Hello all,

       

      Still in CS3, VB.

       

      Back in 2008 I did a post on this same subject (http://forums.adobe.com/message/3312350#3312350) and Harbs was kind enough to show it to me in Java script.

       

      Now that it's been a while I'm wondering if anyone has clue as to why this doesn't work in VB:

       

      Set pgs = InD.ActiveDocument.Pages.ItemByRange(149, 152)
      pgs.AppliedMaster = InD.ActiveDocument.MasterSpreads.Item("LNG-TXT")

       

      But his DOES work in Javascript:

       

      var thepgs = app.activeDocument.pages.itemByRange(148,151);
      thepgs.appliedMaster = app.activeDocument.masterSpreads.item("LNG-TXT");

       

      Many thanks,

      Ken

        • 1. Re: Applying master to a collection of pages
          Harbs. Level 6

          Does VB take an index as an argument?

           

          Try:

          Set pgs = InD.ActiveDocument.Pages.ItemByRange(InD.ActiveDocument.Pages.item(149), InD.ActiveDocument.Pages.item(152))
          
          1 person found this helpful
          • 2. Re: Applying master to a collection of pages
            Ken Krugh Level 1

            Hey Harbs,

             

            Thanks a gain for taking a crack at this. Unfortunately I've tried that. I'm beginning to think it just isn't in the VB model, or something.

             

            VB has a TypeName() function that returns a string with the type of variable passed. So when a text frame is selected and I do this:

             

            set MyTxtFrame = InD.Selection(1)

            MsgBox TypeName(MyTxtFrame)

             

            I get a message box that says "TextFrame."

             

            When I pass pgs to TypeName I get "Objects" and when I pass pgs(1) I get "Page" so I'm nearly sure the collection is getting created OK. I can even set the AppliedMaster of one of the pages within the collection like this:

             

            pgs(1).AppliedMaster = InD.ActiveDocument.MasterSpreads("LNG-TXT")

             

            It's just the darn application of the master to the collection that simply doesn't work.

             

            Currently I'm building a string that is the Java code and running the DoScript command, which works MUCH faster than itterating through all the pages.

             

            Thanks again,

            Ken

            • 3. Re: Applying master to a collection of pages
              Harbs. Level 6

              Ah. I seem to remember that itemByRange in VB is a VB functionality which is really more of an array than an InDesign collection. You can't use methods or set properties to arrays. It only works for collections.

               

              I don't use VB, so my memory is a bit fuzzy.

               

              Try checking the type of the object you get from ItemByRange. What is it?

              • 4. Re: Applying master to a collection of pages
                Ken Krugh Level 1

                Just just as TypeName(pgs) returns "Objects," this:

                 

                TypeName(InD.ActiveDocument.Pages.ItemByRange(InD.ActiveDocument.Pages.Item(161), InD.ActiveDocument.Pages.Item(164)))

                 

                also returns "Objects."

                 

                Something, somewhere made me think that you work primarily in Windows. True? Do you have any recommendations for a development environment for Java scripts? Preferrably something that has a GUI for developing forms?

                 

                Ken

                • 5. Re: Applying master to a collection of pages
                  Harbs. Level 6

                  Ken Krugh wrote:

                   

                  Something, somewhere made me think that you work primarily in Windows. True?

                   

                  Nope. My primary machine is Mac.