Skip navigation
Currently Being Moderated

Need Help With Script Skipping Word Before Variable

Dec 17, 2013 4:59 AM

Tags: #text #extendscript #beginner

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/

 

Thanks,

Marc

 

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 )

            {

                $.writeln(vTextItems.String)

                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

        vDocStart=vDocStart.NextPgfInFlow;

        }

}

 

 

 

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

         return;

         }

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points