2 Replies Latest reply on May 22, 2008 3:19 AM by (Dmitry1776)

    Can i arrange find process with "while" condition?

    Level 1
      I'd like to find all chapters 1, 2, 3... and add after line break.
      But i do not know how many chapters i have. So i did:

      Set mInd = CreateObject("InDesign.Application.CS3")
      ...
      Set mParaStyle = mDoc.ParagraphStyles.Item("Zag1")

      mInd.FindTextPreferences = idNothingEnum.idNothing
      mInd.FindTextPreferences.AppliedParagraphStyle = mParaStyle
      mInd.FindTextPreferences.FindWhat = ""

      b Do While mInd.FindTextPreferences.FindWhat.Execute

      '''commands

      Loop

      So how can i write condition "while" (if it's allowed)?

      Thanks
        • 1. Re: Can i arrange find process with "while" condition?
          Level 1
          this is not WORD ;)
          you don't need search next result ;)

          Set myFindRes = myStory.FindText

          will return collection of all text ranges with applied selected ParaStyle

          Function FindText([ReverseOrder]) As Objects
          Member of InDesign.Story
          Finds text that matches the find what value. / Return value: The found text. / ReverseOrder: If true, returns the results in reverse order. as Boolean

          so - you need to iterate this collection - backward:

          for a=myFindRes.Count to 1 step -1
          set myResult = myFindRes.item(a)
          ' do something here
          next

          I wrote "[...] all text ranges [...]" becuase if you have few paragraphs styled with specified ParaStyle - Indesign will return it as one object/range - few Paragraphs
          if you need to act to each paragraph separatelly - you need to add second loop to iterate paragraphs in founded range

          for a=myFindRes.Count to 1 step -1
          set myResult = myFindRes.item(a)
          for b=myResult.Paragraphs.Count to 1 step -1
          ' do something here with each paragraph
          next
          next

          and this will work fine if there will be only one Paragraph in founded range ;)

          and remember to not use For...Each - limited to 255 iterations - and remember to iterate backward if you need to make changes in text

          robin

          --
          www.adobescripts.com
          • 2. Re: Can i arrange find process with "while" condition?
            Level 1
            Yesss! Thanks very match, Robert. Now i see the difference between WORD and InDi. It works excellent.