1 Reply Latest reply on Jun 15, 2008 3:28 AM by Harbs.

    Does Document.FindText return a Text object Array?

      Hello. I'm new here but it seems to be the only place where I can post this question to.
      I'm working in a C# application that uses InDesign CS3 scripting. I'm trying to create an index automatically from a tabbed list of words in a text file.
      As C# is a strongly typed language, I have to cast all objects to the right type. I'm having problems when I try to add the page numbers to the created index entries using the following code (I've used the CreateIndexEntry.jsx scrip as a starting point).

      //Find all occurrences of the word or set of words (the topic name)

      ...
      ((InDesign.FindTextPreference) app.FindTextPreferences).FindWhat = topic.Name;

      ...

      InDesign.Objects foundTexts = doc.FindText(System.Reflection.Missing.Value);

      It's supposed to be an Array of Text objects (InDesign.Text) but when I try to cast each object using this

      //Code is forced because I've tried everything here

      //Loop through each finding and add page numbers to topic

      IEnumerator textEnum = foundTexts.GetEnumerator();
      while (textEnum.MoveNext())
      {
      object text = textEnum.Current;
      topic.PageReferences.Add((InDesign.Text)text, InDesign.idPageReferenceType.idCurrentPage, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
      }
      }

      I got the following exception (translated).

      text is not an InDesign.Text object (Interfaces doesn't match)

      So the question is what object type should I use to cast each object resulting by calling the Document's FindText method.

      Every suggestion will ve very welcome.
      Thank You very much.