8 Replies Latest reply on Oct 13, 2011 12:03 PM by dsackett

    Woes placing text; need benefit of your experience! [CS4 + JS]

    dsackett Level 1

      Hi-- I'm working on a routine for importing a number of text documents into InDesign, but have come up with odd behavior when placing text. I'm working with ID CS4 & javascript; all the actions perform the same when doing them manually.

       

      I start with text--actual unformatted text originating from a Word document, but saved as a text file--and with the text tool place it at the cursor position in a paragraph in 'body text' style; the text picks up formatting different than the style, namely the font from 'Headline' style, although pt size & leading are still 'body text' style.

       

      Yet when I cut the same text from a text editor, then paste it at the cursor position, the text appears as I expect, in body text style with no overrides.

       

      This is a small improvement: When I first tried placing the text,  it had been coming in with a character style applied. I noticed that the character style being applied was selected in the Quick Apply menu. Un-selecting the character style in the Quick Apply got me to where I am now.

       

      It's driving me nuts that I still can't figure out where the Headline-style font is coming from! Any pointers?

       

      Thanks in advance...

       

      Daniel

       

      p.s.: I'm trying the text import angle to avoid other problems I'd been having importing Word documents, namely importing any Word97-2003 document with highlighted text would crash ID, Word character styles adding direct formatting to the text in ID, etc.

       

       

        • 1. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
          Haakenlid Level 3

          If you post the code it would be much easier to guess what might be wrong.

          • 2. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
            [Jongware] Most Valuable Participant

            dsackett wrote:

            [..]

            When I first tried placing the text,  it had been coming in with a character style applied. I noticed that the character style being applied was selected in the Quick Apply menu. Un-selecting the character style in the Quick Apply got me to where I am now.

             

             

            Did you check all of the usual suspects? You already found a character style that got applied accidentally, so check for manual overrides as well. (As a free bonus: it has nothing to do with Quick Apply either. Next time just check your Character Styles panel; either it's selected, or the label at the top tells you which one is active.)

             

            There should not be a difference between creating a frame manually and starting to type, and doing it per script.

             

            dsackett wrote:

             

            p.s.: I'm trying the text import angle to avoid other problems I'd been having importing Word documents, namely importing any Word97-2003 document with highlighted text would crash ID, Word character styles adding direct formatting to the text in ID, etc. 

             

             

            It's kind of radical, but yes, I can see why you were going this way. I have to wrestle Word files into submission about five times each day. It's a goddam shame importing of the only kind of formatted text InDesign can import is so goddam flaky, and Adobe not only flatly refuses to acknowledge its errors (a reply I once got was "you cannot compare imported text in InDesign with the original Word file since the margins and paper size may be different") but actually made the import perform worse from CS3 to CS4.

            1 person found this helpful
            • 3. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
              dsackett Level 1

              Thanks, Haakenlid, I'll post the code once I get it a little more along, but as far as I can tell, it's not a code problem. I was picking through the steps manually to see how things behaved, figuring if I could accomplish the task with manual steps, I'd know it'd be possible to script.

               

              I'm sure it's something with my template. Further testing shows I can open a new blank document, shove stuff into that, then cut and paste that text into my template and style from there. I may take that angle to work around my ignorance, but I'd still like to know what's really happening.

              • 4. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
                dsackett Level 1

                Thanks, Jongware. I did check the usual suspects, which is why I'm perplexed. I have my template with my front page frame strung on to subsequent frames, smart text reflow turned on. When I set my text cursor by the #, the style palettes show just what I want, paragraph as Body Text style, character styles  = [None]. I can grab text from my text editor and paste it, and all is well--all text is still Body Text, no character style. But if I place the same text from the .txt file, it shows up as having the font style overridden with the Headline font.

                 

                As I mentioned in a previous reply, it's probably something lurking in my template, because I can open a new blank ID file, place text in that, and it arrives as expected. Maybe I'll just work that way as a work-around.

                • 5. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
                  dsackett Level 1

                  Update: Well, I ended up upgrading to CS5.5, which seems to solve a number of problems. Importing from Word with matching styles works pretty well, and scripting an update of directly formatted text to character styles is pretty straightforward.

                   

                  In messing around with the old approach, I did come across something odd with GREP that I have yet to discover an answer to. Apparently if you're searching for angle-bracketed tags in text, ID chokes on multiple tags in the same paragraph, e.g.: the pattern: <b>(.*)</b> matches only the earliest <b> and latest </b> tag of multiple tags in the paragraph, consequently any other tag in between is marooned and not found. Seems like ID searches for the first tag from the start of the graph and the last tag from the end, rather than sequentially, like I would expect.

                   

                  Does anyone know a way around this?

                  • 6. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
                    [Jongware] Most Valuable Participant

                    That behavior is by design. By default, GREP is greedy. To make it non-greedy, change your pattern to

                     

                    <b>(.*?)</b>

                    1 person found this helpful
                    • 7. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
                      dsackett Level 1

                      Awesome, Jongware--thanks!

                       

                      I think I read the InDesign Secrets article on formatting text last year, but didn't  recognize the significance of GREP's greed. I also think it's great that the non-greedy modifier's a question mark, the symbol of curiosity, humility, and of an admission and openness to the unknown.

                      • 8. Re: Woes placing text; need benefit of your experience! [CS4 + JS]
                        dsackett Level 1

                        As promised, here is the code, as it stands, for whatever help it can be. The code is specific to my particular uses, but the approach of tagging various direct/character styles from Word, wiping all formatting then reapplying ID styles and removing the tags may be useful.

                         

                         

                        /*
                            ConvertWordBrute.jsx
                          
                            Problem: importing from regularly styled Word templated documents to CS4 can be a mess. Even if import presets are exactly set,
                            if the Word doc has character styles, text can come in with layered character styles. Applying correct character styles and then
                            removing  overrides won't fix because character styles and direct formatting are layered on every bit of text and formatting is not 
                            at all standard. To fix, all character styles AND overrides must be removed to wipe out the strangeness. This script shows one approach
                             to keep italic, bold and bold italic direct formatting, and perhaps other stuff to preserve what the writers intended.
                          
                            The approach: tag formatting outside of ID's usual facilities, wipe all formatting clear, then apply the proper styles & character styles.
                          
                            Presumes:
                                --A word import preset has been set...
                                --Will need to trap for missing fonts? (e.g. Windings Bold, which is faked in Word; doesn't actually exist!) 
                                Left @: Works reasonably well. Probably should be run on before layout has sections.
                                --Document includes a paragraph style named "Body Text"
                        */
                        /**
                        * @@@BUILDINFO@@@ ConvertWordBrute.jsx !Version! Thu Oct 11 2011 10:52:08 GMT-0700
                        */
                        
                        #script "ConvertWord"
                        #target "InDesign"
                        
                        main();
                        
                        function main(){
                            try {
                                var docRef = getActiveDocument();
                            } catch (e) {
                                alert (e);
                            } 
                            var confirmWarning = "Note: bold, italic and bold-italic will be turned into character styles, then this script clears all overrides--" +
                                "any character spacing applied outside of regular paragraph and character styles will be erased--OK?";
                            var myConfirm = confirm(confirmWarning, true, "Text change alert!");
                            if (myConfirm == false){
                                return;
                            }
                            var jumpTextCharStyle = "Body jump text";
                            var jumpLineChars = 30;
                          
                            //saveTextReflowState & turn it off to avoid adding pages...
                            var smartTextReflowState = docRef.textPreferences.smartTextReflow
                            docRef.textPreferences.smartTextReflow = false;
                          
                            //Apply HTML-like tags to text with formatting you want to keep
                            //what you search here depends on how your import preferences were set... did you map incoming word styles? to what? Normal -> Body Text?
                            tagFormattedCharacters(docRef, "Body Text", "Bold" , "b");
                            tagFormattedCharacters(docRef, "Body Text", "Italic" , "i");
                            tagFormattedCharacters(docRef, "Body Text", "Bold Italic" , "bl");
                            tagFormattedCharacters(docRef, "Normal", "Bold" , "b");
                            tagFormattedCharacters(docRef, "Normal", "Italic" , "i");
                            tagFormattedCharacters(docRef, "Normal", "Bold Italic" , "bl");
                            tagFormattedCharacters(docRef, "Body Text indent", "Bold" , "b");
                            tagFormattedCharacters(docRef, "Body Text indent", "Italic" , "i");
                            tagFormattedCharacters(docRef, "Body Text indent", "Bold Italic" , "bl");
                            cleanupTags(docRef);
                        
                            //Convert Word styles to ID styles, then wipe Word styles
                            convertWordStyles(docRef);
                          
                            //Re-apply all paragraph styles with no overrides or character styles
                            formatTaggedCharacters(docRef, "b", "Bold")
                            formatTaggedCharacters(docRef, "i", "Italic")
                            formatTaggedCharacters(docRef, "bl", "Byline")
                          
                            // Replace jump lines character style, since above makes all bold-italic into Byline style
                            formatJumpLines(docRef, jumpLineChars, jumpTextCharStyle);
                          
                            //re-instate text reflow
                            docRef.textPreferences.smartTextReflow = smartTextReflowState;
                          
                        }
                        
                        function getActiveDocument(){
                        //returns reference to active document; otherwise undefined
                            //if a variable is not assigned a value, its value is undefined
                            if (app.documents.length == 0) {
                                throw ("No documents open");
                            }
                            //returns value for variable docRef back to call statement
                            var docRef = app.documents.item(0);
                            return docRef;
                        }
                        
                        function tagFormattedCharacters(docRef, paragraphStyle, fontStyle, fontTag) {
                            // Searches for characters in paragrapfStyle, fontStyle in docRef, enclosing any characters found
                            // in HTML-style angle-bracket tags containing fontTag
                            var myStyles, s, stylesRE;
                          
                            //First chk if passed paragraphStyle exists
                            for (var s = docRef.paragraphStyles.length-1; s >= 2; s--) {
                                //get a list of pipe-separated styles, but not the default styles in brackets, since they'll screw up a RegExp pattern
                             myStyles = docRef.paragraphStyles[s].name + "|" + myStyles;
                           }
                            stylesRE = new RegExp(myStyles);
                            if (!paragraphStyle.match(stylesRE)){
                                return;
                            }
                            //Clear the find/change preferences.
                            clearFindChangePrefs()
                        
                            //Set the find options.
                            app.findChangeTextOptions.caseSensitive = false;
                            app.findChangeTextOptions.includeFootnotes = false;
                            app.findChangeTextOptions.includeHiddenLayers = false;
                            app.findChangeTextOptions.includeLockedLayersForFind = false;
                            app.findChangeTextOptions.includeLockedStoriesForFind = false;
                            app.findChangeTextOptions.includeMasterPages = false;
                            app.findChangeTextOptions.wholeWord = false;
                            app.findTextPreferences.appliedParagraphStyle = paragraphStyle;
                            app.findTextPreferences.fontStyle = fontStyle;
                        
                            var myFoundItems = docRef.findText();
                            openTag = "<"+fontTag+">";
                            closeTag ="</"+fontTag+">";
                          
                            //Note: gotta iterate from the end forward, otherwise tag insertions will skew insertion points
                            for(i=myFoundItems.length-1; i>-1; i--){
                                myFoundItems[i].insertionPoints.lastItem().contents = closeTag;
                                myFoundItems[i].insertionPoints.firstItem().contents = openTag;
                            }
                        }
                        
                        function cleanupTags(myObject){
                            // To correct for faulty formatting resulting in badly placed tags, e.g.: tags on both sides of paragraph returns.
                            // To internalize search routines into this script, it uses a series of searches equivalent to FindChangeByList,
                            // captured with RecordFindChange_CS3-CS5.jsx .
                            // Note GREP search strings MUST be enclosed in quotes with all internal backslashes & quotes escaped,
                            // e.g.: \\ becomes \\\\, findWhat:"( becomes findWhat:\"(
                            var myChangesArray = new Array();
                            // a few changes to clean up placement of formatting tags which may be funky from Word direct formatting
                            myChangesArray[0] = "grep    {findWhat:\"(<[^>]*>)(\\\\s)(</[^>]*>)\"}    {changeTo:\"$2\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false}"; //Nix bolded white space of any kind
                            myChangesArray[1] = "grep    {findWhat:\"(<[^>]*>)(\\\\ )(\\\\[)\"}    {changeTo:\"$2$1$3\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false}"; //move spaces (only!) in front of bylines before tag
                            myChangesArray[2] = "grep    {findWhat:\"(\\\\r)(</[^>]*>)\"}    {changeTo:\"$2$1\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false}"; //move close tags before graf returns
                            myChangesArray[3] = "text    {findWhat:\"<bl>^_</bl>\"}    {changeTo:\"^_\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false}";    //Replace em dashes that somehow get bold italic
                        
                            findChangeByArray(myObject, myChangesArray)
                        }
                        
                        function convertWordStyles(docRef){
                            // Converts Word styles to ID styles, then wipes Word styles
                            // To internalize search routines to this script, this uses a series of searches equivalent to FindChangeByList,
                            // captured with RecordFindChange_CS3-CS5.jsx .
                            // Note search strings MUST be enclosed in quotes with all internal backslashes & quotes escaped, esp. important for GREP
                            // e.g.: \\ becomes \\\\, findWhat:"( becomes findWhat:\"(
                            var i, p, stylesRE;
                            var myChangesArray = new Array();
                            //note: findChangeByArray does not trap for
                            myChangesArray[0] = "text    {findWhat:\"^p^t\"}    {changeTo:\"^p\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false}"; // remove tabs at the start of paragraphs
                            myChangesArray[1] = "text    {findWhat:\"n\", appliedParagraphStyle:\"Heading 1\", appliedFont:\"Wingdings\", fontStyle:\"Bold\"}    {changeTo:\"^8\", appliedCharacterStyle:\"[No character style]\", appliedParagraphStyle:\"Headline 1\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false}"; //replace square bullet in Heading 1 Word style to standard bullet Headline 1 + Bold
                            myChangesArray[2] = "text    {appliedParagraphStyle:\"Normal\"}    {appliedParagraphStyle:\"Body Text\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false}"; // replace Normal paragraph Word style with Body Text
                            myChangesArray[3] = "text    {appliedParagraphStyle:\"CallOut\"}    {appliedParagraphStyle:\"Callout\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:true}"; // replace CallOut Word style with Callout
                            myChangesArray[4] = "text    {appliedParagraphStyle:\"Normal Indent\"}    {appliedParagraphStyle:\"Body Text indent\", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:true}"; //replace Normal Indent Word style to Body Text indent
                            myChangesArray[5] = "text    {appliedParagraphStyle:\"Body Text\", fontStyle:\"Italic\"}    {appliedCharacterStyle:\"Italic\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace direct formatted body text italic with character style
                            myChangesArray[6] = "text    {appliedParagraphStyle:\"Body Text\", fontStyle:\"Bold\"}    {appliedCharacterStyle:\"Bold\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace direct formatted body text bold with character style
                            myChangesArray[7] = "text    {appliedParagraphStyle:\"Body Text\", fontStyle:\"Bold Italic\"}    {appliedCharacterStyle:\"Byline\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace direct formatted body text bold italic with Byline character style
                            myChangesArray[8] = "text    {findWhat:\" -- \"}    {changeTo:\"^_\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace space dash dash space with em dash, no spaces
                            myChangesArray[9] = "text    {findWhat:\"--\"}    {changeTo:\"^_\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace space dash dash space with em dash, no spaces
                            myChangesArray[10] ="text    {findWhat:\"  \"}    {changeTo:\" \"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //replace double spaces with single space
                            myChangesArray[11] ="text    {findWhat:\"^p^p\"}    {changeTo:\"^p\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, wholeWord:false, caseSensitive:false, kanaSensitive:true, widthSensitive:true, ignoreKashidas:true, ignoreDiacritics:false}"; //Nix double paragraph markers
                            // section to put in headline jump reference bullets
                            myChangesArray[12] ="grep    {findWhat:\"\\\\>  ?(from \\\\[\\\\d\\\\d?\\\\])\\\\s?\\\\s?$\"}    {changeTo:\" ~8 $1\"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true, kanaSensitive:true, widthSensitive:true}"//add bullet before end of word, replace space (optional space) 'from [' digit optional digit ']' optional space optional space end of paragraph with space bullet space + the rest
                          
                        
                            // Changes any imported paragraph styles to Body Text, imported character styles to None, nukes imported
                            findChangeByArray(docRef, myChangesArray)
                            removeImportedStyles(docRef);
                            // clear overrides, both character & paragraph
                            // first set what paragraphs to check
                            stylesRE = new RegExp(/Body |Heading /)
                            for (i = 0; i < docRef.stories.length; i++) {
                                //only mess with stories with a bunch of paragraphs & only paragraphs of Body* or Heading* styles
                                if (docRef.stories[i].paragraphs.length > 1) {
                                    for ( p=0; p < docRef.stories[i].paragraphs.length; p++){
                                        if (docRef.stories[i].paragraphs[p].appliedParagraphStyle.name.match(stylesRE)) {
                                            docRef.stories[i].paragraphs[p].clearOverrides(OverrideType.ALL);
                                        }
                                    }
                                }
                            }
                        }
                        
                        function clearFindChangePrefs(){
                            //find/change text preferences
                            app.findTextPreferences = null;
                            app.changeTextPreferences = null;
                            //find/change grep preferences
                            app.findGrepPreferences = null;
                            app.changeGrepPreferences = null;
                            //find/change glyph preferences
                            app.findGlyphPreferences = null;
                            app.changeGlyphPreferences = null;
                        }
                        
                        function findChangeByArray(myObject, myChangesArray){
                            //a shorter version of the supplied FindChangeByList.jsx to allow internalizing search strings
                            // Note search strings passed MUST be enclosed in quotes with all internal backslashes & quotes escaped,
                            // esp. important for GREP, e.g.: \\ becomes \\\\, findWhat:"( becomes findWhat:\"(
                            var myFindChangeArray, myFindType, myFindPreferences, myChangePreferences, myFindChangeOptions, i;
                            var myStyles, s, stylesRE, searchOK;
                            // Prepare to trap for non-existant styles
                            // get a list of pipe-separated styles, but not the default styles in brackets, since they'll screw up a RegExp pattern
                            for (var s = myObject.paragraphStyles.length-1; s >= 2; s--) {
                                 myStyles = myObject.paragraphStyles[s].name + "|" + myStyles;
                           }
                             stylesRE = new RegExp(myStyles);
                            for (i = 0; i < myChangesArray.length; i++) {
                                myFindChangeArray = myChangesArray[i].split("\t");
                                //The first field in the line is the findType string.
                                myFindType = myFindChangeArray[0];
                                //The second field in the line is the FindPreferences string.
                                myFindPreferences = myFindChangeArray[1];
                                // Trap to ensure the style exists
                                //The second field in the line is the ChangePreferences string.
                                myChangePreferences = myFindChangeArray[2];
                                //The fourth field is the range--used only by text find/change.
                                myFindChangeOptions = myFindChangeArray[3];
                        
                                // Trap for non-existant paragraph styles; ID will choke on searching for a style not in doc
                                // Look for paragraph style in find string
                                if (myFindPreferences.match(/appliedParagraphStyle/)){
                                    // & that the search is for a style existing in the document
                                    if (!myFindPreferences.match(stylesRE)){
                                        continue;
                                    }
                                }
                                switch(myFindType){
                                    case "text":
                                        myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                        break;
                                    case "grep":
                                        myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                        break;
                                    case "glyph":
                                        myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                        break;
                                }
                            }
                        }
                        
                        function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                            //Reset the find/change preferences before each search.
                            app.changeTextPreferences = null;
                            app.findTextPreferences = null;
                            var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
                            myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
                            myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
                            app.doScript(myString, ScriptLanguage.javascript);
                            myFoundItems = myObject.changeText();
                            //Reset the find/change preferences after each search.
                            app.changeTextPreferences = null;
                            app.findTextPreferences = null;
                        }
                        
                        function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                            //Reset the find/change grep preferences before each search.
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                            var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
                            myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
                            myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
                            app.doScript(myString, ScriptLanguage.javascript);
                            var myFoundItems = myObject.changeGrep();
                            //Reset the find/change grep preferences after each search.
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                        }
                        function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
                            //Reset the find/change glyph preferences before each search.
                            app.changeGlyphPreferences = null;
                            app.findGlyphPreferences = null;
                            var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
                            myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
                            myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
                            app.doScript(myString, ScriptLanguage.javascript);
                            var myFoundItems = myObject.changeGlyph();
                            //Reset the find/change glyph preferences after each search.
                            app.changeGlyphPreferences = null;
                            app.findGlyphPreferences = null;
                        }
                        
                        function removeImportedStyles(docRef){
                            // Changes any imported paragraph styles to Body Text, imported character styles to None, nukes imported
                           var paraStyle = docRef.paragraphStyles.item("Body Text");
                           var noneCharStyle = docRef.characterStyles.item("[None]");
                        
                           for(var myCounter = docRef.paragraphStyles.length-1; myCounter >= 2; myCounter--){
                             if (docRef.paragraphStyles[myCounter].imported == true ) {
                                docRef.paragraphStyles[myCounter].remove(paraStyle); //Replaces w/paraStyle
                             }
                           }
                        
                           for(var myCounter = docRef.characterStyles.length-1; myCounter >= 2; myCounter--){
                             if (docRef.characterStyles[myCounter].imported == true) {
                                docRef.characterStyles[myCounter].remove(noneCharStyle);
                             }
                           }
                        }
                        
                        function formatTaggedCharacters(docRef, fontTag, characterStyle){
                            // Searches docRef for text between <fontTag> </fontTag> tags & applies characterStyle
                            // then removes the fontTags.
                            // For characterStyle = Byline, If found text is greater than jumpTextLen in length, apply jumpTextCharStyle instead 
                            // First verify the passed charstyle exists...
                        
                            // use your standard GREP search & replace
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                            // note ? mark in following GREP search string, the non-greedy modifier. Thanks Jongware!
                            var myString = "app.findGrepPreferences.properties = {findWhat:\"<"+ fontTag + ">(.*?)<\/" + fontTag + ">\"};";
                            myString += "app.changeGrepPreferences.properties = {changeTo:\"$1\", appliedCharacterStyle:\""+characterStyle+"\"};";
                            myString += "app.findChangeGrepOptions.properties = {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true};";
                            app.doScript(myString, ScriptLanguage.javascript);
                            var myFoundItems = docRef.changeGrep();
                            //Reset the find/change grep preferences after each search.
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                          
                            //OK, the tags are still there, so wipe 'em
                            removeTag(docRef, fontTag);
                        }
                        
                        function removeTag(docRef, fontTag){
                            // Use a GREP search to replace the given tag in docRef; don't mess with styles, as that should've been handled already
                            // Reset the find/change grep preferences before each search.
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                            var myString = "app.findGrepPreferences.properties = {findWhat:\"<"+ fontTag + ">(.*)<\/" + fontTag + ">\"};";
                            myString += "app.changeGrepPreferences.properties = {changeTo:\"$1\"};";
                            myString += "app.findChangeGrepOptions.properties = {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true};";
                            app.doScript(myString, ScriptLanguage.javascript);
                            var myFoundItems = docRef.changeGrep();
                            //Reset the find/change grep preferences after each search.
                            app.changeGrepPreferences = null;
                            app.findGrepPreferences = null;
                        }
                        
                        function formatJumpLines(docRef, jumpLineChars, jumpTextCharStyle){
                            //  Since previous convertWordStyles() changes all bold italic styled text to Byline char style, change any that are
                            //  >jumpLineChars to 'Body jump text' style.
                                app.changeTextPreferences = null;
                                app.findTextPreferences = null;
                                var myString = "app.findTextPreferences.properties = {appliedCharacterStyle:\"Byline\"};";
                                myString += "app.findChangeTextOptions.properties = {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false};";
                                app.doScript(myString, ScriptLanguage.javascript);
                                var myFoundItems = docRef.findText();
                                //Reset the find/change text preferences after each search.
                                app.changeTextPreferences = null;
                                app.findTextPreferences = null;
                                //Note: best to iterate from the end forward, avoiding any potential insertion point skew
                                for(i=myFoundItems.length-1; i>-1; i--){
                                    if (myFoundItems[i].length > jumpLineChars){
                                        myFoundItems[i].appliedCharacterStyle = jumpTextCharStyle;
                                    }
                                }
                        }