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

How can I select my target character style from the dropdown list of the panel?

Guide ,
Jun 21, 2025 Jun 21, 2025

Hi @rob day 

The panel is still a bit difficult for me to really figure out.


I want to select my target character style from a dropdown list,and I don't know how to build the panel and get the selected character style.

Thank you very much.

app.findGrepPreferences.appliedCharacterStyle
    = app.activeDocument.characterStyles.item(mySeleChaStyle);

 

TOPICS
Bug , Feature request , How to , Performance , Scripting
522
Translate
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

Community Expert , Jun 22, 2025 Jun 22, 2025

target character style from a dropdown list

 

There are many ways to make a dialog—this is how I would do a drop down:

 

//call the makeDialog function
makeDialog();
//cs will hold the result
var cs;   
function makeDialog(){
    //the dialog object
    var theDialog = app.dialogs.add({name:"Choose a Style", canCancel:true});
    //add a dropdown list object, stringList gets the name of every available character style
    //note this would not get grouped styles
    with(theDialog.dialogColumns
...
Translate
Community Expert ,
Jun 21, 2025 Jun 21, 2025

Why not use the feature called Quick Apply? Are you familiar with it?

Mike Witherell
Translate
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
Community Expert ,
Jun 21, 2025 Jun 21, 2025

We can't keep track of all the various snippets you've pasted across posts. If you are having a problem with the dropdown ui, post the relevant snippet, or better yet, reply in the existing post so we can see what else has been offered. And I do hope you spent some time attempting to debug before coming here again, as we have advised you on numerous occasions. You will never get better if you continue to use us as a crutch.

Translate
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
Community Expert ,
Jun 21, 2025 Jun 21, 2025

If you have no snippet of the panel at all, then read Peter Kahrel's scriptUI book, play around with AI, and/or use this excellent panel building tool: scriptui.joonas.me

Translate
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
Guide ,
Jun 21, 2025 Jun 21, 2025

Hi @brian_p_dts 

You have great ideas, always lots of great ideas.
I'll think about it.
I apologize for wasting so much of your time.

 

Looking forward to you share more valuable information about this subject.

Thank you.

Translate
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
Guide ,
Jun 21, 2025 Jun 21, 2025

Find a complex reference.
Hard to read and use it in a short time.

 

    textCharacterStyleGroup = textPanel.add("group");
    textCharacterStyleGroup.orientation = "row";
    textCharacterStyleGroup.enabled = processTextCheckBox.value
    var characterStyleText = textCharacterStyleGroup.add("statictext", undefined, "Handling character styles");
    characterStyleText.preferredSize.width = "150";
    var characterStyleDropDown = textCharacterStyleGroup.add("dropdownlist");
    characterStyleDropDown.preferredSize.width = "300";
    characterStyleDropDown.alignment = ["fill", "fill"];
    var item = characterStyleDropDown.add('item', "[All]");
    item.characterStyle = "[All]";
    item.selected = true;
    for (var i = 0; i < dok.allCharacterStyles.length; i++) {
        item = characterStyleDropDown.add('item', getStyleString(dok.allCharacterStyles[i]));
        if (dok.allCharacterStyles[i].name == px.clearCharacterStyle) {
            item.selected = true;
        }
        item.characterStyle = dok.allCharacterStyles[i];
    }

 

Translate
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
Guide ,
Jun 22, 2025 Jun 22, 2025

@brian_p_dts @Mike Witherell 

Found another example, but still don't know how to represent a character style dropdown list.

myDisplayDialog();
function myDisplayDialog() {
    var myDialog = app.dialogs.add({ name: "ABC column Fla" });
    with (myDialog.dialogColumns.add()) {
        with (dialogRows.add()) {
            with (dialogColumns.add()) {
                staticTexts.add({ staticLabel: "targetCharaStyle" });
            }
            with (dialogColumns.add()) {
                var charaDropList = dropdowns.add({ characterStyle, selectedIndex: 0 });
            }
        }
    }
    var myResult = myDialog.show();
}

 

Translate
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
Guide ,
Jun 22, 2025 Jun 22, 2025

Didn't wait for the great one to come.
I integrated one.
It feels like another level of awesome.

function buildListSub(scope, type, groupType, list, str) {
    var styles = scope[type].everyItem().getElements();
    for (var i = 0; i < styles.length; i++) {
        temp = list.add('item', styles[i].name + (str == '' ? '' : ' (' + str + ')'));
        temp.style = styles[i]; // Add property so we can easily get a handle on the style later
    }
    for (var j = 0; j < scope[groupType].length; j++) {
        buildListSub(scope[groupType][j], type, groupType, list, scope[groupType][j].name + (str == '' ? '' : ': ') + str);
    }
}

function buildList(list, type) {
    // paragraphStyles > paragraphStyleGroups
    buildListSub(app.documents[0], type, type.replace(/s$/, 'Groups'), list, '');
    // Delete the first item, [None], [No paragraph style], etc.
    list.remove(list.items[0]);
    // Delete the [Basic Grid] object style too.
    if (type === 'objectStyles') {
        try {
            list.remove(list.find(app.documents[0].objectStyles.item('$ID/[Normal Grid]').name));
        } catch (_) {
        };
    }
}


var w1 = new Window('dialog', '为字符样式标注ABC列', undefined, { closeButton: false });
var panel = w1.add('panel {alignChildren: "fill"}');
var cstylegroup = panel.add('group {orientation: "row"}');
cstylegroup.add('statictext {text: "选择字符样式"}');
var cstyle = cstylegroup.add('dropdownlist');
buildList(cstyle, 'characterStyles');
cstyle.selection = 0;
w1.buttons = w1.add('group {alignment: "right"}');
var ok = w1.buttons.add('button', undefined, 'OK', { name: 'ok' });
w1.buttons.add('button', undefined, 'Cancel', { name: 'cancel' });
ok.enabled = true;
w1.show();

//if (w1.show() == 1) {
//var gr = encode_grep(GREPeditor.editWindow.text);
//var cs = cstyle.selection.style;
//for (var i = 0; i < cstyle.selection.length; i++) {
//try {
alert(cstyle.selection);
//}
//catch (e) {
//    alert(e.message);
//}
//}
//}
//w1.close();

 

Translate
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
Community Expert ,
Jun 22, 2025 Jun 22, 2025

target character style from a dropdown list

 

There are many ways to make a dialog—this is how I would do a drop down:

 

//call the makeDialog function
makeDialog();
//cs will hold the result
var cs;   
function makeDialog(){
    //the dialog object
    var theDialog = app.dialogs.add({name:"Choose a Style", canCancel:true});
    //add a dropdown list object, stringList gets the name of every available character style
    //note this would not get grouped styles
    with(theDialog.dialogColumns.add()){
        cs = dropdowns.add({stringList:app.activeDocument.characterStyles.everyItem().name, selectedIndex:0, minWidth:80});
    }
    if(theDialog.show() == true){
        //get the result
        cs = app.activeDocument.characterStyles.item(cs.selectedIndex);
        //call the main() function
        main();
        theDialog.destroy();
	}
}


function main(){
    alert("Chosen Style’s name: " + cs.name);
    //Do something with the preset here
}

 

Screen Shot 4.png

 

 

Screen Shot 5.png

Translate
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
Guide ,
Jun 22, 2025 Jun 22, 2025

Hi rob day.

Thank you very much.

I'll take a look at this right away, I made this and it won't contain [none]

Translate
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
Guide ,
Jun 22, 2025 Jun 22, 2025
LATEST

Thank you very much

Translate
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