20 Replies Latest reply on Feb 10, 2009 10:06 AM by Harbs.

    Trying to get an old script to work in CS3

    Level 1
      I have a script that somebody wrote for me some time back (I think when I was still in CS2) that finds a paragraph style and pulls that text out and places it in an anchored text box with an assigned object style. It was written for a specific job, but I'm trying to update it to use generally because I have a project that crosses my plate on a fairly regular basis that has paragraphs that need to be pulled out into anchored text boxes . Only problem is the script no longer works. I was able to find a few of the syntax errors and correct them myself (such as findPreferences to findTextPreferences), but I'm no scripter and the script still will not work. I don't know what else to do but post it here and beg for help. Would someone please look at it and see if it is something simple that can be reworded to make it work? It's currently stopping at line 6 "myDoc.search" I'm still in CS3. Thanks!

      //find paragraph style text and replace with text in anchored text frame
      myDoc = app.activeDocument
      myPstyle = myDoc.paragraphStyles.itemByName("Teaching Tip");
      app.findTextPreferences = app.changeTextPreferences = null;
      app.findTextPreferences.appliedParagraphStyle = myPstyle;
      myFinds = myDoc.search("", false, false, undefined, {appliedParagraphStyle:myPstyle});
      for (var j = myFinds.length - 1; j >= 0; j--) {
      if ((j > 0) && (j % 100 == 0)) {

      function getParentTextFlow(theTextRef) {
      // Returns reference to parent story or text of cell, as appropriate
      if (theTextRef.parent.constructor.name == "Cell") {
      return theTextRef.parent.texts[0];
      } else {
      return theTextRef.parentStory;

      function makeAnchor(theText) {
      // Transfers contents of theText into new anchored frame that replaces theText
      var myStory = getParentTextFlow(theText);
      var myAnchLocation = theText.insertionPoints[-2].index;
      var myTF = myStory.insertionPoints[myAncLocation].textFrames.add();
      myTF.applyObjectStyle(myDoc.objectStyles.item("Teacher's Tip", true));
      theText.move(LocationOptions.atEnd, myTF.parentStory);
      myAnchStory = myTF.parentStory;
      theText.move(LocationOptions.atEnd, myAnchStory);
      myAnchStory.texts[0].appliedParagraphStyle = myDoc.paragraphStyles.item("Teaching Tip");