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

Help to applya function ina checkbox

Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

I am trying to put a function in a checkbox to execute a opentype feature.
This opentype feature isn't in Indesign UI but You can access using a script

I don't know what is wrong.
Please any help would be great:

/@targetengine "OpenTypeFeatures"
var palette = new Window("palette");
palette.text = "Character Variants";
palette.orientation = "column";
palette.alignChildren = ["center","top"];
palette.spacing = 30;
palette.margins = 60;

// GROUP1
// ======
var group1 = palette.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
group1.alignment = ["center","top"];

var checkbox1 = group1.add("checkbox", undefined, undefined, {name: "checkbox1"});
checkbox1.text = "CV01";
checkbox1.alignment = ["left","top"];
checkbox1.value = false

checkbox1.onClick = function () {
if (checkbox1.onClick() == true) {
checkbox1.value = true;
checkbox1.checked = true;
if( app.selection[0].hasOwnProperty("opentypeFeatures"))
app.selection[0].opentypeFeatures=[["cv01",1]];
}
else {

app.selection[0].opentypeFeatures = []; // reset to nothing
}
}
var convert_button1 = palette.add ("button", undefined, "OK");
convert_button1.onClick = function () { palette.close(0) }

palette.show();

TOPICS
Scripting

Views

218

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

Community Expert , Jan 10, 2022 Jan 10, 2022

Hi, Try below

#targetengine "session"

var palette = new Window("palette");
palette.text = "Character Variants";
palette.orientation = "column";
palette.alignChildren = ["center", "top"];
palette.spacing = 30;
palette.margins = 60;

// GROUP1
// ======
var group1 = palette.add("group", undefined, { name: "group1" });
group1.orientation = "row";
group1.alignChildren = ["left", "center"];
group1.spacing = 10;
group1.margins = 0;
group1.alignment = ["center", "top"];

var checkbox1 = group1.add("ch
...

Votes

Translate

Translate
Community Expert ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

Hi, Try below

#targetengine "session"

var palette = new Window("palette");
palette.text = "Character Variants";
palette.orientation = "column";
palette.alignChildren = ["center", "top"];
palette.spacing = 30;
palette.margins = 60;

// GROUP1
// ======
var group1 = palette.add("group", undefined, { name: "group1" });
group1.orientation = "row";
group1.alignChildren = ["left", "center"];
group1.spacing = 10;
group1.margins = 0;
group1.alignment = ["center", "top"];

var checkbox1 = group1.add("checkbox", undefined, undefined, { name: "checkbox1" });
checkbox1.text = "CV01";
checkbox1.alignment = ["left", "top"];
checkbox1.value = false

checkbox1.onClick = function () {
    if (checkbox1.value == true) {
        alert("Executed");
        if (app.selection[0].hasOwnProperty("opentypeFeatures"))
            app.selection[0].opentypeFeatures = [["cv01", 1]];
    }
    else {
        app.selection[0].opentypeFeatures = []; // reset to nothing
    }
}
var convert_button1 = palette.add("button", undefined, "OK");
convert_button1.onClick = function () { palette.close(0) }

palette.show();

 

The following statement is wrong

if (checkbox1.onClick() == true) {

instead of this you should check if value of checkbox is true then excute your code.

 

Best regards

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
Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

Thank You Charu, it works but I can't remove the opentype feature after checkbox is checked.
Could You help me one more time, please?
Best Regards
Sami

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
Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

LATEST

Please forget my last message.
It works perfectly!
Thank You very much!

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