5 Replies Latest reply on Nov 23, 2010 1:08 PM by jaal

    Apply Nested Styles Script not working for me anymore

    jaal Level 1

      //DESCRIPTION: Applies nested styles as directly applied character styles.         WARNING: This script will override any character styles which are directly applied to the text with the nested styles applied, and formatting might change!
           function IsValid (obj){
                var err;
                     if(!obj){return false}
                          return obj.isValid;
                     var test = obj.parent;
                     return true;
                catch(err){return false;}
           function ResetFindPrefs(){
                if(kAppVersion<5){app.findPreferences = null;}
                else{app.findTextPreferences = null;ResetFindChangeOptions();}
           function ResetFindChangeOptions(){
                app.findChangeTextOptions.properties = {
           function GetTempColor(doc){
                for(var i=0;i<doc.swatches.length;i++){
                     if(doc.swatches[i].label == 'harbsTempColor'){return doc.swatches[i]}
                return doc.colors.add({label:'harbsTempColor'});
           function GetAppColor(colorName){
                for(var i=0;i<app.swatches.length;i++){
                     if(app.swatches[i].name==colorName){return app.swatches[i]}
                return null;
           kAppVersion = parseFloat(app.version);
           var doc = app.documents[0];
                var charStyles = doc.characterStyles;
                var charStyles = doc.allCharacterStyles;
           var tempDocColor = GetTempColor(doc);
           var colorName = tempDocColor.name;
           var tempAppColor = GetAppColor(colorName);
           var removeAppColor=false;
           for(var i=1;i<charStyles.length;i++){
                var savedColor = charStyles[i].underlineGapColor;
                var finds=undefined;
                var findsLength=0;
                          app.findPreferences.underlineGapColor = tempDocColor;
                          app.changePreferences.appliedCharacterStyle = charStyles[i];
                               app.findTextPreferences.underlineGapColor = tempAppColor;
                               app.findTextPreferences.underlineGapColor = tempDocColor;
                          app.changeTextPreferences.appliedCharacterStyle = charStyles[i];
                          finds = doc.changeText();







      This was a script to apply nested styles directly to the text as character styles.It was supplied to me by someone on this forum to help make a file adaptable to an epub doc. It has worked fine for many months but now it does not. I am wondering if the cause is that I have added two nested styles in the paragraphs, where before there was only one. The paras. are currently set up with nested styles as follows:[none] up to En Space, italic through 5 sentences.                  I am using 5 sentences because I can't figure how to use a para. end as a limiter. I know this is confused but any help will be appreciated. Thanks