2016-12-19 2 views
1

J'essaye d'écrire un script qui convertira tous les caractères en minuscules si un style imbriqué particulier est appliqué. Je n'arrive pas à trouver la syntaxe correcte pour obtenir le texte.Comment obtenir le texte auquel un style imbriqué est appliqué? InDesign

Je l'origine essayé ce qui suit, qui a travaillé à une extension, mais en minuscules tout le paragraphe plutôt que seul le texte qui a le style de caractère appliqué:

function lowerCaseNest(myPStyle, myCStyle){ 

var myDocument = app.documents.item(0); 
//Clear the find/change preferences. 
app.findTextPreferences = NothingEnum.nothing; 
app.changeTextPreferences = NothingEnum.nothing; 
//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 = myPStyle; 

var missingFind = app.activeDocument.findText(); 
var myDoc = app.documents[0]; 

for (var listIndex = 0 ; listIndex < missingFind.length; listIndex++) { 

      for (i = missingFind[listIndex].nestedStyles.length-1;i>=0; i--) { 

        for (j = missingFind[listIndex].nestedStyles[i].parent.characters.length-1;j>=0; j--) { 

         if (missingFind[listIndex].nestedStyles[i].parent.characters[j].contents.appliedCharacterStyle(myCStyle)) { 
           var myString = missingFind[listIndex].nestedStyles[i].parent.characters[j].contents;         

           if (typeof(myString) == "string"){ 
             var myNewString = myString.toLowerCase(); 
             missingFind[listIndex].nestedStyles[i].parent.characters[j].contents = myNewString; 
            } 
          } 

        } 

    } 

app.findTextPreferences = NothingEnum.nothing; 
app.changeTextPreferences = NothingEnum.nothing;  

}

J'ai alors essayé de jouer autour avec appliedNestedStyles, mais n'arrive pas à comprendre comment récupérer le texte auquel le style imbriqué est appliqué.

Quelqu'un peut-il m'aider?

Merci! John

Répondre

0

En fait, je pris une approche différente, et a compris quelque chose qui fonctionne:

function lowerCaseNest(myPStyle, myCStyle){ 

for (var i = 0; i < app.activeDocument.stories.length; i++){ 
       for (var j = 0; j < app.activeDocument.stories[i].paragraphs.length; j++){ 
         var myP = app.activeDocument.stories[i].paragraphs[j]; 
         if (myP.appliedParagraphStyle.name==myPStyle) { 
           for (k=0; k<myP.characters.length; k++) {          
             if(typeof(myP.characters[k].appliedNestedStyles[0]) != 'undefined'){ 
              if(myP.characters[k].appliedNestedStyles[0].name == myCStyle) { 
                var myC = myP.characters[k].contents; 
                if (typeof(myC)=='string'){ 
                 var myNewString = myC.toLowerCase(); 
                 myP.characters[k].contents = myNewString; 
                } 
              } 
            } 
          } 
        }     
      }  
    } 
} 

serait encore intéressé à savoir s'il y a un moyen plus facile de gérer cela, comme je l'ai bien peur que cela peut prendre plus long pour fonctionner sur de longs documents, car il s'agit de chaque paragraphe individuellement.

0

À moins que je me trompe le appliedNestedStyle peut être pris en charge dans la boîte de dialogue F/C en ciblant la characterStyle appliquée:

GREP 
Find : .+ 
Format : character style => myCharStyle 

puis

var found = doc.findGrep(); 

...