0 Replies Latest reply on Dec 17, 2013 4:59 AM by mdver

    Need Help With Script Skipping Word Before Variable

    mdver Level 1

      I borrowed and modified a skip I found here: http://forums.adobe.com/message/4808804 with code borrowed from elsewhere.


      I noticed that it seems to run fine, but it skips any word that appears right before a variable. The point of the script is to find any text using an italic override or bold override, and replace the override with the appropriate character format from the catalog.


      Can someone tell me why the code below skips words before a variable? I am sure it is a simple thing, but I am teaching myself Extendscript, and only recently started the attempt/





      var doc = app.ActiveDoc;

      removeOverrides (doc)

      function removeOverrides (pDoc)


          var vDocStart = pDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

          var vBoldFmt=pDoc.GetNamedCharFmt ('bold')

          var vItalicFmt=pDoc.GetNamedCharFmt ('italic')

          initFA_errno ();

          var vTextLoc = new TextLoc(vDocStart,0);

          var vFindParams=findOverrideParams (pDoc);

          while (FA_errno==Constants.FE_Success)


              var vTextRange=pDoc.Find(vTextLoc,vFindParams);

              if (vTextRange.beg.obj.ObjectValid())


                  var vTextItems=pDoc.GetTextForRange (vTextRange, Constants.FTI_CharPropsChange)

                  if (vTextItems.length==!0 )



                      if (vTextItems[0].idata==Constants.FTF_WEIGHT)


                         pDoc.SetTextProps (vTextRange, vBoldFmt.GetProps())


                      if (vTextItems[0].idata==Constants.FTF_ANGLE)


                         pDoc.SetTextProps (vTextRange, vItalicFmt.GetProps())


                      }// else (Log (vLogFileName, '\nERROR: No items were found in the text format array but format override was found: '+pDoc.Name))


              vTextLoc = vTextRange.end







      function findOverrideParams (pDoc)


          var vFindParams = AllocatePropVals(1);

          vFindParams[0].propIdent.num = Constants.FS_FindObject;

          vFindParams[0].propVal.valType = Constants.FT_Integer;

          vFindParams[0].propVal.ival = Constants.FV_FindCharacterFormatOverride;

         return vFindParams;




        function initFA_errno()


               app.GetNamedMenu("!MakerMainMenu"); //If this fails, you've got bigger problems