7 Replies Latest reply on Dec 11, 2008 12:36 PM by (Ariel_Walden)

    Getting a CS2 Script to Work in CS4 VB

    Level 1
      Hi,

      The following script works for CS2. I am now trying to run it in CS4 but it
      doesn't work. I have put the script in a folder within a folder called
      "Version 2.0 Scripts" (inside the preexisting "Scripts Panel" folder).
      Nevertheless, it doesn't work. Can anyone help me run this in CS4?

      Rem BoxParagraphs.vbs
      Rem An InDesign CS2 VBScript
      Rem
      Rem Converts all paragraphs of a given paragraph style
      Rem to single-cell tables.
      Set myInDesign = CreateObject("InDesign.Application.CS2")
      Set myDocument = myInDesign.Documents.Item(1)
      Set myStyle = myDocument.ParagraphStyles.Item("HRBox")
      myInDesign.FindPreferences = idNothingEnum.idNothing
      myInDesign.ChangePreferences = idNothingEnum.idNothing
      myInDesign.FindPreferences.AppliedParagraphStyle = myStyle
      Set myFoundItems = myDocument.Search()
      myInDesign.FindPreferences = idNothingEnum.idNothing
      If myFoundItems.Count <> 0 Then
      For myCounter = myFoundItems.Count To 1 Step -1
      Set myFoundItem = myFoundItems.Item(myCounter)
      Set myStartCharacter = myFoundItem.Characters.Item(1)
      Rem Special case for the last paragraph in a story.
      Set myEndCharacter = myFoundItem.Characters.Item(-1)
      If myEndCharacter.Contents = vbCr Then
      Set myEndCharacter = myFoundItem.Characters.Item(-2)
      End If
      Rem Get the text of the paragraph, excluding the return character.
      Set myText = myFoundItem.Texts.ItemByRange(myStartCharacter,
      myEndCharacter)
      Rem Convert the paragraph to a table.
      Set myTable = myText.Item(1).ConvertToTable
      Rem Adjust table properties here, if necessary.
      Next
      End If


      Thank you,
      Ariel
        • 1. Re: Getting a CS2 Script to Work in CS4 VB
          Level 1
          Hi Ariel,

          Try something like this:

          Rem BoxParagraphs.vbs
          
          Rem An InDesign CS4 VBScript
          Rem
          Rem Converts all paragraphs of a given paragraph style
          Rem to single-cell tables.
          Set myInDesign = CreateObject("InDesign.Application.CS4")
          Set myDocument = myInDesign.Documents.Item(1)
          Set myStyle = myDocument.ParagraphStyles.Item("HRBox")
          myInDesign.FindTextPreferences = idNothingEnum.idNothing
          myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
          myInDesign.FindTextPreferences.AppliedParagraphStyle = myStyle
          Set myFoundItems = myDocument.FindText()
          myInDesign.FindTextPreferences = idNothingEnum.idNothing
          If myFoundItems.Count <> 0 Then
              For myCounter = myFoundItems.Count To 1 Step -1
                  Set myFoundItem = myFoundItems.Item(myCounter)
                  Set myStartCharacter = myFoundItem.Characters.Item(1)
                  Rem Special case for the last paragraph in a story.
                  Set myEndCharacter = myFoundItem.Characters.Item(-1)
                  If myEndCharacter.Contents = vbCr Then
                      Set myEndCharacter = myFoundItem.Characters.Item(-2)
                  End If
                  Rem Get the text of the paragraph, excluding the return character.
                  Set myText = myFoundItem.Texts.ItemByRange(myStartCharacter, myEndCharacter)
                  Rem Convert the paragraph to a table.
                  Set myTable = myText.Item(1).ConvertToTable
                  Rem Adjust table properties here, if necessary.
              Next
          End If

          Thanks,

          Ole
          • 2. Re: Getting a CS2 Script to Work in CS4 VB
            Level 1
            Thank you very much Ole.

            The only difference I can see is the FindPreferences becomes
            FindTextPreferences throughout.

            I plan to learn up on the new CS4 stuff, but now is not the time as I've got
            to finish something here asap.

            Just wondering, though, why putting it in a Version 2.0 folder didn't work?

            Thanks again,
            Ariel
            • 3. Re: Getting a CS2 Script to Work in CS4 VB
              Level 1
              Oh, and I see that method is now FindText() rather than Search()
              • 4. Re: Getting a CS2 Script to Work in CS4 VB
                [Jongware] Most Valuable Participant
                >why putting it in a Version 2.0 folder didn't work?

                That's easier than you think. CS4 is InDesign v.6, CS3 is v.5, and CS2 -- the original target -- is v.4. I have a Version 4.0 Scripts folder and even a Version 3.0 (for CS scripts) which, AFAIK , work just fine.

                I don't think InDesign 2.0 already had scripts :-)
                • 5. Re: Getting a CS2 Script to Work in CS4 VB
                  Level 1
                  Ho hum,

                  The truth is that for a moment there I also thought it was strange calling CS2 v.2. However, I was simply dutifully doing that which is written:

                  "...To do this, run the script from a folder in the Scripts panel folder
                  named Version 5.0 Scripts (for InDesign CS3 scripts) or Version 2.0 Scripts
                  (for InDesign CS2 scripts), or explicitly..."

                  (Source: Adobe InDesign CS4 Scripting Guide: VB)
                  • 6. Re: Getting a CS2 Script to Work in CS4 VB
                    Level 1
                    Hi Ariel,

                    It's just a typo. Sorry!

                    Thanks,

                    Ole
                    • 7. Re: Getting a CS2 Script to Work in CS4 VB
                      Level 1
                      No probs. Thanks again for your help.
                      Ariel