5 Replies Latest reply on Aug 13, 2009 9:58 AM by CatalogCreator

    (VBS CS2) Need indexing help: Creating a page reference

    CatalogCreator Level 1

      This is my first post on this forum. While I have years of experience in PageMaker scripting, I am new to InDesign scripting. I need to create a current page reference and index the word, "Widgets." I've read PDF's until my brain has turned to mush. I can't seem to connect the dots (literally) when it comes to this task.

       

      This is my test script. The last line is where I am stuck:

       

      Const idCurrentPage = 1668444263
      Rem Hello World
      Set myInDesign = CreateObject("InDesign.Application.CS2")
      Rem Create a new document.
      Set myDocument = myInDesign.Documents.Add

      Rem Get a reference to the first page.
      Set myPage = myDocument.Pages.Item(1)
      Rem Create a text frame.
      Set myTextFrame = myDocument.TextFrames.Add
      Rem Specify the size and shape of the text frame.
      myTextFrame.GeometricBounds = Array("0p0", "0p0", "18p0", "18p0")
      Rem Enter text in the text frame.
      myTextFrame.Contents = "This is the new WidgetPro."

      Rem Create a new story.
      Set myStory = myInDesign.ActiveDocument.Stories(1)
      Rem Open the story editor.
      Set myStoryEditor = myInDesign.ActiveDocument.Stories(1).StoryEdit
      Rem Enter some text.
      myStory.insertionPoints.item(-1).contents = vbCr
      myStory.insertionPoints.item(-1).contents = "Widgets"
      Rem Create an index (not sure if this is needed).
      Set myIndex = myDocument.indexes.add()
      Rem Add a topic (not sure if this is needed).
      Set myTopic = myIndex.Topics.add("Widgets")
      Rem Set a reference to the current page DOES NOT WORK
      myTopic.pageReferences.add(myStory.insertionPoints[myIndex], PageReferenceType.CurrentPage)

       

      A bit more info if it helps: This process of building the story with corresponding indexed words/phrases continues on through 30+ chapters totalling 500+ pages in the final book. The actual index is at the end of the book will be created through the normal InDesign menu commands.

      -Ike

        • 1. Re: (VBS CS2) Need indexing help: Creating a page reference
          Steven.. Level 3

          I think the code is good, but VB arrays use parenthesis, and only functions put parameters in parnthesis. Use call to tur Sub into function

          try

          Call myTopic.pageReferences.add(myStory.insertionPoints.item(myIndex), PageReferenceType.CurrentPage)
          

          • 2. Re: (VBS CS2) Need indexing help: Creating a page reference
            CatalogCreator Level 1

            I replaced my bad line of code with yours and get the error, Invalid parameter.

             

            Maybe I am making it harder than what it needs to be. What I am trying to accomplish is the equivalent of selecting the word, Widgets, and hitting the keyboard shortcut, <Shift><Ctrl><Alt>[. I need the scripting equivalent of that.

             

            [Edit] Does InDesign have the PageMaker equivalent of IndexAuto? [/Edit]

            • 3. Re: (VBS CS2) Need indexing help: Creating a page reference
              CatalogCreator Level 1

              I finally figured out how to create an index, a topic and corresponding index marker. Here the woking code is for others who are seeking similar help:

               

              Const idNo = 1852776480
              Const idCurrentPage = 1668444263
              Set myInDesign = CreateObject("InDesign.Application.CS2")
              Set myDocument = myInDesign.Documents.Add
              Set myPage = myDocument.Pages.Item(1)
              Set myTextFrame = myDocument.TextFrames.Add
              myTextFrame.GeometricBounds = Array("0p0", "0p0", "18p0", "18p0")
              myTextFrame.Contents = "This is the new WidgetPro."
              Set myStory = myInDesign.ActiveDocument.Stories(1)
              Set myStoryEditor = myStory.StoryEdit
              myStory.insertionPoints.item(-1).contents = vbCr
              Set myIndex = myDocument.indexes.add()
              Set myTopic = myIndex.Topics.add("Widgets")
              myTopic.PageReferences.add myStory.InsertionPoints.Item(1), idCurrentPage
              myStory.insertionPoints.item(-1).contents = vbCr

               

              The line of code in blue was the part that was giving me fits. Please note the lack of surrounding parenthesis after '.add'. Considering I am new to InDesign scripting, I can only speculate this is a peculiarity of VBSEdit. If I try running the same script via InDesign's script palette, I get an error.

               

              What is going on here? I need to get a handle on this and I still feel like I am coding by the million monkeys method.

              • 4. Re: (VBS CS2) Need indexing help: Creating a page reference
                Steven.. Level 3

                As I replied earlier, in Classic VB there are Sub's and Functions. A Sub doesn't return anything, and it's parameters are not surrounded with parenthesis. A Function returns a value and its parameters are surrounded with parenthesis.

                 

                For example

                Msgbox "This is a sub"
                result = Msgbox("This is a Function")
                

                 

                even though the same command is used, it changes the rules when returning a value.

                 

                (Please note this wackyness has been changed in vb.net)

                 

                If you wan't to deal with a Sub as a Function, you can add the "Call" keyword before the Sub.

                 

                For example

                Call Msgbox("This Sub acts like a Function")
                

                 

                Good Luck

                Steven

                • 5. Re: (VBS CS2) Need indexing help: Creating a page reference
                  CatalogCreator Level 1

                  Steven,

                   

                  Though I did not realize it at the time, I have no doubt you gave me the correct answer originally. I have been trying out VBSEdit to write my test scripts because its object browser is so helpful. I have since then learned a script written in VBSEdit that runs successfully does not necessarily work when run via InDesign's script palette. Why? I have no idea. But it gets me the close enough to the correct answer that I can transfer the routine over to my master application and have it function.

                   

                  I have about 50 PageMaker commands that I need to duplicate in InDesign's scripting. Indexing and autoflow have been the only two that have truly perplexed me. The rest are pretty straight forward and I have been able to handle them on my own. At the pace I am going, I should be done in a week or so.

                   

                  Your assistance has been very helpful.

                   

                  Thank you,

                  Ike