3 Replies Latest reply on May 1, 2008 11:30 AM by (Diane_King)

    Have a CS2 script that will not run in CS3. Can someone help?

    Level 1
      I have a script that was written for me to find a certain paragraph style and replace the paragraph with an anchored text frame containing the text from the paragraph. I moved the script over to CS3 and updated the style names for my new document, but nothing happens when I try to run the script. I'll flow the script in after my opening post.
        • 1. Re: Have a CS2 script that will not run in CS3. Can someone help?
          Level 1
          //find paragraph style text and replace with text in anchored text frame
          myDoc = app.activeDocument
          myPstyle = myDoc.paragraphStyles.itemByName("Teaching Tip");
          app.findPreferences = app.changePreferences = null;
          app.findPreferences.appliedParagraphStyle = myPstyle;
          myFinds = myDoc.search("", false, false, undefined, {appliedParagraphStyle:myPstyle});
          for (var j = myFinds.length - 1; j >= 0; j--) {
          makeAnchor(myFinds[j]);
          if ((j > 0) && (j % 100 == 0)) {
          myDoc.save(myDoc.fullName);
          }
          }

          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();
          myStory.recompose();
          makeInchWide(myTF);
          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");
          myTF.fit(FitOptions.frameToContent);
          makeInchWide(myTF);
          }

          function makeInchWide(theObj) {
          // Makes theObj one inch wide
          //Save user's measurement preferences
          userHoriz = myDoc.viewPreferences.horizontalMeasurementUnits;
          userVert = myDoc.viewPreferences.verticalMeasurementUnits;
          myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
          myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;
          var myBounds = theObj.geometricBounds;
          myBounds[3] = myBounds[1] + 3;
          theObj.geometricBounds = myBounds;
          myDoc.viewPreferences.horizontalMeasurementUnits = userHoriz
          myDoc.viewPreferences.verticalMeasurementUnits = userVert
          }
          • 2. Re: Have a CS2 script that will not run in CS3. Can someone help?
            Level 1
            Diane,

            Place this line at the top of your sctipt:

            app.scriptPreferences.version = 4.0;

            Like so:

            //find paragraph style text and replace with text in anchored text frame
            app.scriptPreferences.version = 4.0;
            myDoc = app.activeDocument

            that should do it for you.

            Bob
            • 3. Re: Have a CS2 script that will not run in CS3. Can someone help?
              Level 1
              Still doesn't work.

              I've opened it in ExtendScript Toolkit 2 and tried running it from there and it stops at line 29

              var myTF = myStory.insertionPoints[myAncLocation].textFrames.add();