• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to find text with appliedCharacterStyle inside CharacterStyleGroup?

Engaged ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

var doc = app.activeDocument;
var doc_allParaStyles = doc.allParagraphStyles;
for(var p = 0 ; p < doc_allParaStyles.length ; p++){ 
    var AllNestedStyles = doc_allParaStyles[p].nestedStyles;
     for(var n=0; n<AllNestedStyles.length;n++){
            var NestedStyleName=AllNestedStyles[n].appliedCharacterStyle.name;
            app.findTextPreferences = NothingEnum.nothing;
            app.findTextPreferences.appliedCharacterStyle = NestedStyleName;
      //here how to find text with aplliedCharacterStyle inside characterStyleGroups!
            var found_txt = app.activeDocument.findText();
            app.findTextPreferences = NothingEnum.nothing;
            for(var a =0 ; a < found_txt.length ; a++)
             {
                var foundCon = found_txt[a].contents;
            } 
        }
    }

In the above code, when I try to find any characterStyleName inside the characterStyleGroup, it is shows following error:

Error: Invalid value for set property 'appliedCharacterStyle'. Expected String, CharacterStyle or NothingEnum enumerator, but received "c4H".

Is there anyother way to find with allCharacterStyles (including groups)! 

TOPICS
Bug , How to

Views

123

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jul 22, 2022 Jul 22, 2022

found the way! its working now..

var doc = app.activeDocument;
var doc_allParaStyles = doc.allParagraphStyles;
for(var p = 0 ; p < doc_allParaStyles.length ; p++){ 
    var AllNestedStyles = doc_allParaStyles[p].nestedStyles;
     for(var n=0; n<AllNestedStyles.length;n++){
        if(AllNestedStyles[n].appliedCharacterStyle.parent == "[object CharacterStyleGroup]"){
            var charStyleGroupName = AllNestedStyles[n].appliedCharacterStyle.parent;
            var NestedStyleName=AllNestedStyl
...

Votes

Translate

Translate
Engaged ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

LATEST

found the way! its working now..

var doc = app.activeDocument;
var doc_allParaStyles = doc.allParagraphStyles;
for(var p = 0 ; p < doc_allParaStyles.length ; p++){ 
    var AllNestedStyles = doc_allParaStyles[p].nestedStyles;
     for(var n=0; n<AllNestedStyles.length;n++){
        if(AllNestedStyles[n].appliedCharacterStyle.parent == "[object CharacterStyleGroup]"){
            var charStyleGroupName = AllNestedStyles[n].appliedCharacterStyle.parent;
            var NestedStyleName=AllNestedStyles[n].appliedCharacterStyle.name;
            cstylegroup = app.activeDocument.characterStyleGroups.itemByName(charStyleGroupName.name);
            app.findTextPreferences = NothingEnum.nothing;
            app.findTextPreferences.appliedCharacterStyle = cstylegroup.characterStyles.itemByName(NestedStyleName);
            var found_txt = app.activeDocument.findText();
            app.findTextPreferences = NothingEnum.nothing;
            for(var a =0 ; a < found_txt.length ; a++)
             {
                var foundCon = found_txt[a].contents;
            }
        }
        else{
            var NestedStyleName=AllNestedStyles[n].appliedCharacterStyle.name;
            app.findTextPreferences = NothingEnum.nothing;
            app.findTextPreferences.appliedCharacterStyle = NestedStyleName;
            var found_txt = app.activeDocument.findText();
            app.findTextPreferences = NothingEnum.nothing;
            for(var a =0 ; a < found_txt.length ; a++)
             {
                var foundCon = found_txt[a].contents;
            } 
        }
        }
    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines