ScriptUI: Buttons not responsive

Community Beginner ,
Mar 25, 2019

Copy link to clipboard

Copied

I'm making a UI for my Framemaker script in which I have 21 checkboxes.  I have 2 buttons, Select All, and Deselect All, which I want use to programmatically check and uncheck all the boxes.  However, in the buttons currently do absolutely nothing.

Code in my .onClick functions isn't getting executed at all.  $.writeln ("test1"); isn't printing anything to the console.

var myWindow = new Window ("dialog");

 

    var BG = myWindow.add("checkbox", undefined, "BG_Bulgarian"); //1

    var CS = myWindow.add("checkbox", undefined, "CS_Czech"); //2

    var DA = myWindow.add("checkbox", undefined, "DA_Danish"); //3

    var DE = myWindow.add("checkbox", undefined, "DE_German"); //4

    var ES = myWindow.add("checkbox", undefined, "ES_Spanish"); //5

    var FI = myWindow.add("checkbox", undefined, "FI_Finnish"); //6

    var FR = myWindow.add("checkbox", undefined, "FR_French"); //7

    var HR = myWindow.add("checkbox", undefined, "HR_Croatian"); //8

    var HU = myWindow.add("checkbox", undefined, "HU_Hungarian"); //9

    var IT = myWindow.add("checkbox", undefined, "IT_Italian"); //10

    var JA = myWindow.add("checkbox", undefined, "JA_Japanese"); //11

    var KO = myWindow.add("checkbox", undefined, "KO_Korean"); //12

    var NL = myWindow.add("checkbox", undefined, "NL_Dutch"); //13

    var PL = myWindow.add("checkbox", undefined, "PL_Polish"); //14

    var PT = myWindow.add("checkbox", undefined, "PT_Portuguese"); //15

    var RO = myWindow.add("checkbox", undefined, "RO_Romanian"); //16

    var RU = myWindow.add("checkbox", undefined, "RU_Russian"); //17

    var SK = myWindow.add("checkbox", undefined, "SK_Slovak"); //18

    var SV = myWindow.add("checkbox", undefined, "SV_Swedish"); //19

    var TR = myWindow.add("checkbox", undefined, "TR_Turkish"); //20

    var ZH = myWindow.add("checkbox", undefined, "ZH_Chinese"); //21

   

    BG.value = true; //1

    CS.value = true; //2

    DA.value = true; //3

    DE.value = true; //4

    ES.value = true; //5

    FI.value = true; //6

    FR.value = true; //7

    HR.value = true; //8

    HU.value = true; //9

    IT.value = true; //10

    JA.value = true; //11

    KO.value = true; //12

    NL.value = true; //13

    PL.value = true; //14

    PT.value = true; //15

    RO.value = true; //16

    RU.value = true; //17

    SK.value = true; //18

    SV.value = true; //19

    TR.value = true; //20

    ZH.value = true; //21   

   

    var myButtonGroup1 = myWindow.add("group");

    myButtonGroup1.orientation = "row";

    var selectAllButton = myButtonGroup1.add("button", undefined, "Select All");

    var deselectAllButton = myButtonGroup1.add("button", undefined, "Deselect All");

    var generateFMbooks = myWindow.add("button", undefined, "Generate FM books");   

    myWindow.show ();

deselectAllButton.onClick = function () {

    $.writeln ("test1");

    BG.value = false; //1

    CS.value = false; //2

    DA.value = false; //3

    DE.value = false; //4

    ES.value = false; //5

    FI.value = false; //6

    FR.value = false; //7

    HR.value = false; //8

    HU.value = false; //9

    IT.value = false; //10

    JA.value = false; //11

    KO.value = false; //12

    NL.value = false; //13

    PL.value = false; //14

    PT.value = false; //15

    RO.value = false; //16

    RU.value = false; //17

    SK.value = false; //18

    SV.value = false; //19

    TR.value = false; //20

    ZH.value = false; //21

}

selectAllButton.onClick = function () {

    $.writeln ("test2");

     BG.value = true; //1

    CS.value = true; //2

    DA.value = true; //3

    DE.value = true; //4

    ES.value = true; //5

    FI.value = true; //6

    FR.value = true; //7

    HR.value = true; //8

    HU.value = true; //9

    IT.value = true; //10

    JA.value = true; //11

    KO.value = true; //12

    NL.value = true; //13

    PL.value = true; //14

    PT.value = true; //15

    RO.value = true; //16

    RU.value = true; //17

    SK.value = true; //18

    SV.value = true; //19

    TR.value = true; //20

    ZH.value = true; //21

   

}

generateFMbooks.onClick = function () {

     myWindow.close();

}

TOPICS
Scripting

Views

2.7K

Likes

Translate

Translate

Report

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

1 Correct Answer

Community Beginner , Mar 26, 2019
gabriels33895177 Community Beginner , Mar 26, 2019
You are both right.  I let my frustration with this problem get to me.  The only thing wrong with my first implementation was the placement of myWindow.show();All of the button functions must be between var myWindow = new Window ("dialog")andmyWindow.show();ScriptUI for Dummies is legit and I was just missed this rule.

Likes

Translate

Translate
Jump to answer Jump to answer
Enthusiast ,
Mar 25, 2019

Copy link to clipboard

Copied

Hi,

you are adding lots of checkboxes, but you only need one.

To that one you can add, remove/removeAll or change  "items"

But first of all you have to add agroup to myWindow !

something like that:

var DropDownGroup = myWindow.add("group")

DropDown = DropDownGroup.add("dropdownlist",undefined, ["ABC","DEF","GHJ"]);  //

// to add further item

DropDown.add("item","KLM");

But in your case you'd better use a listbox

like that:

SvgTextListe =

    myGroup.MyWindow.add("group");

   MyList = MyGroup.add("listbox",undefined,[],{multiselect:true});

You should have a look at the Javascript Tools Guide in chapter Common properties

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Mar 25, 2019

Copy link to clipboard

Copied

I figured it out.  I was using the parent child hierarchy wrong.  This version now behaves correctly.

By the way this guide that everyone points to is full of lies.

var myWindow = new Window ("dialog");

    myWindow.BG = myWindow.add("checkbox", undefined, "BG_Bulgarian"); //1

    myWindow.CS = myWindow.add("checkbox", undefined, "CS_Czech"); //2

    myWindow.DA = myWindow.add("checkbox", undefined, "DA_Danish"); //3

    myWindow.DE = myWindow.add("checkbox", undefined, "DE_German"); //4

    myWindow.ES = myWindow.add("checkbox", undefined, "ES_Spanish"); //5

    myWindow.FI = myWindow.add("checkbox", undefined, "FI_Finnish"); //6

    myWindow.FR = myWindow.add("checkbox", undefined, "FR_French"); //7

    myWindow.HR = myWindow.add("checkbox", undefined, "HR_Croatian"); //8

    myWindow.HU = myWindow.add("checkbox", undefined, "HU_Hungarian"); //9

    myWindow.IT = myWindow.add("checkbox", undefined, "IT_Italian"); //10

    myWindow.JA = myWindow.add("checkbox", undefined, "JA_Japanese"); //11

    myWindow.KO = myWindow.add("checkbox", undefined, "KO_Korean"); //12

    myWindow.NL = myWindow.add("checkbox", undefined, "NL_Dutch"); //13

    myWindow.PL = myWindow.add("checkbox", undefined, "PL_Polish"); //14

    myWindow.PT = myWindow.add("checkbox", undefined, "PT_Portuguese"); //15

    myWindow.RO = myWindow.add("checkbox", undefined, "RO_Romanian"); //16

    myWindow.RU = myWindow.add("checkbox", undefined, "RU_Russian"); //17

    myWindow.SK = myWindow.add("checkbox", undefined, "SK_Slovak"); //18

    myWindow.SV = myWindow.add("checkbox", undefined, "SV_Swedish"); //19

    myWindow.TR = myWindow.add("checkbox", undefined, "TR_Turkish"); //20

    myWindow.ZH = myWindow.add("checkbox", undefined, "ZH_Chinese"); //21

    myWindow.BG.value = true; //1

    myWindow.CS.value = true; //2

    myWindow.DA.value = true; //3

    myWindow.DE.value = true; //4

    myWindow.ES.value = true; //5

    myWindow.FI.value = true; //6

    myWindow.FR.value = true; //7

    myWindow.HR.value = true; //8

    myWindow.HU.value = true; //9

    myWindow.IT.value = true; //10

    myWindow.JA.value = true; //11

    myWindow.KO.value = true; //12

    myWindow.NL.value = true; //13

    myWindow.PL.value = true; //14

    myWindow.PT.value = true; //15

    myWindow.RO.value = true; //16

    myWindow.RU.value = true; //17

    myWindow.SK.value = true; //18

    myWindow.SV.value = true; //19

    myWindow.TR.value = true; //20

    myWindow.ZH.value = true; //21

    myWindow.myButtonGroup1 = myWindow.add("group");

    myWindow.myButtonGroup1.selectAllButton = myWindow.myButtonGroup1.add("button", undefined, "Select All");

    myWindow.myButtonGroup1.deselectAllButton = myWindow.myButtonGroup1.add("button", undefined, "Deselect All");

    myWindow.myButtonGroup1.orientation = "row";

    myWindow.generateFMbooks = myWindow.add("button", undefined, "Generate FM books");  

myWindow.myButtonGroup1.deselectAllButton.onClick = function () {

    myWindow.BG.value = false; //1

    myWindow.CS.value = false; //2

    myWindow.DA.value = false; //3

    myWindow.DE.value = false; //4

    myWindow.ES.value = false; //5

    myWindow.FI.value = false; //6

    myWindow.FR.value = false; //7

    myWindow.HR.value = false; //8

    myWindow.HU.value = false; //9

    myWindow.IT.value = false; //10

    myWindow.JA.value = false; //11

    myWindow.KO.value = false; //12

    myWindow.NL.value = false; //13

    myWindow.PL.value = false; //14

    myWindow.PT.value = false; //15

    myWindow.RO.value = false; //16

    myWindow.RU.value = false; //17

    myWindow.SK.value = false; //18

    myWindow.SV.value = false; //19

    myWindow.TR.value = false; //20

    myWindow.ZH.value = false; //21

}

myWindow.myButtonGroup1.selectAllButton.onClick = function () {

    myWindow.BG.value = true; //1

    myWindow.CS.value = true; //2

    myWindow.DA.value = true; //3

    myWindow.DE.value = true; //4

    myWindow.ES.value = true; //5

    myWindow.FI.value = true; //6

    myWindow.FR.value = true; //7

    myWindow.HR.value = true; //8

    myWindow.HU.value = true; //9

    myWindow.IT.value = true; //10

    myWindow.JA.value = true; //11

    myWindow.KO.value = true; //12

    myWindow.NL.value = true; //13

    myWindow.PL.value = true; //14

    myWindow.PT.value = true; //15

    myWindow.RO.value = true; //16

    myWindow.RU.value = true; //17

    myWindow.SK.value = true; //18

    myWindow.SV.value = true; //19

    myWindow.TR.value = true; //20

    myWindow.ZH.value = true; //21

  

}

myWindow.generateFMbooks.onClick = function () {

    myWindow.close();

}

myWindow.show ();

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Mar 25, 2019

Copy link to clipboard

Copied

There may be some inaccuracies in Peter's ScriptUI Guide (I haven't seen any yet), but I wouldn't call them "lies". Peter has provided a great free resource and he should be commended for that.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mentor ,
Mar 26, 2019

Copy link to clipboard

Copied

Agreed. It is free help, the same thing that people come here for. Criticism of free help does not encourage people to give it.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Mar 26, 2019

Copy link to clipboard

Copied

You are both right.  I let my frustration with this problem get to me.  The only thing wrong with my first implementation was the placement of

myWindow.show();

All of the button functions must be between

var myWindow = new Window ("dialog")

and

myWindow.show();

ScriptUI for Dummies is legit and I was just missed this rule.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Mar 26, 2019

Copy link to clipboard

Copied

No problem. This stuff can definitely be frustrating.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Advocate ,
Mar 26, 2019

Copy link to clipboard

Copied

Understanding a little about how Javascript is executed may help. In fact, your observation that moving the window.show( ) method solved the problem is related to just that. Javascript uses lookup tables for all the properties and methods of any object, and these tables are built on the fly - whenever a line of code tells the Javascript engine to do so. And the show( ) method of a window object waits until a window.hide( ) event is called before it resumes with the next line below.

All your window object methods, such as the onClick attached to a button, will not be created until after your window has closed - which is not very useful of course. That is why the window.show( ) should always be the last thing you do on a window object. You found it out the hard way. The good news is that you will never forget this 🙂 

FYI: We (= a group of experienced scripters, most of whom you see answering questions on this forum regularly) are planning to create a resource for beginning scripters. We're still getting ourselves ready for this but there should be posts starting soon. The end result will be an extensive series of blog posts, lots of sample script snippets and eventually a book (plus hopefully some web presence where all of this useful knowledge can be shared and augmented by users).

Kind regards

4everJang aka the Frame Tamer

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Enthusiast ,
Apr 02, 2019

Copy link to clipboard

Copied

Sorry for my delayed answer, but I was out of order for some days.

Here's a little snippet that may help you:

You can extend the array and that will append more checkboxes.

BTW: I was talking about this documentation: https://wwwimages2.adobe.com/content/dam/acom/en/devnet/scripting/pdfs/javascript_tools_guide.pdf

Please have in mind, that Peters excellent documentation is developed for Indesign and not all is usable for FrameMaker. But it is a great help, if you adapt things from it!

var myWindow = new Window ("dialog");
var gaLanguages = ["BG_Bulgarian","CS_Czech", "DA_Danish", "DE_German","ES_Spanish","FI_Finnish","FR_French","HR_Croatian","HU_Hungarian","IT_Italian","JA_Japanese"

,"KO_Korean","NL_Dutch","PL_Polish","PT_Portuguese","RO_Romanian","RU_Russian","SK_Slovak","SV_Swedish","TR_Turkish","ZH_Chinese"];

  

var CheckBoxGroup = myWindow.add("group");
CheckBoxGroup.orientation = "column";
CheckBoxGroup.alignChildren = "left";
myWindow.myButtonGroup1 = myWindow.add("group");
myWindow.myButtonGroup1.selectAllButton = myWindow.myButtonGroup1.add("button", undefined, "Select All");
myWindow.myButtonGroup1.deselectAllButton = myWindow.myButtonGroup1.add("button", undefined, "Deselect All");
myWindow.myButtonGroup1.orientation = "row";
myWindow.generateFMbooks = myWindow.add("button", undefined, "Generate FM books");
myWindow.myButtonGroup1.deselectAllButton.onClick = UnSelectAll;
myWindow.myButtonGroup1.selectAllButton.onClick = SelectAll;
myWindow.generateFMbooks.onClick = CloseWindow;
CreateCheckBoxes();
SelectAll();
myWindow.show ();

  

  

function CreateCheckBoxes()

{

for (var i = 0; i < gaLanguages.length; i++)
{
CheckBoxGroup.add("checkbox",undefined,gaLanguages);
}

function UnSelectAll()

{

for (var i = 0; i < CheckBoxGroup.children.length; i++)
{
CheckBoxGroup.children.value = false; 
}

}

function SelectAll()

{

for (var i = 0; i < CheckBoxGroup.children.length; i++)
{
CheckBoxGroup.children.value = true; 
}

}

function CloseWindow()

{

for (var i = 0; i < CheckBoxGroup.children.length; i++)
{
if (CheckBoxGroup.children.value == true)
{
$.writeln("Checked: " + CheckBoxGroup.children.text)  
}
}
myWindow.close();

}

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Apr 02, 2019

Copy link to clipboard

Copied

Thanks! I knew there had to be a way to address the UI elements using a loop, but couldn't find it.  This will make maintaining the script easier.

Likes

Translate

Translate

Report

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