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

Results of Checkbox Displayed as Text in Document

Explorer ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Trying to make a dialog box that depending on the Option Checked would display that text in a Document... I've got the dialog box to successfully display and allow me to check... but doesn't add the results as a text element... Any help figuring out what's missing or how to fix...

Thanks

var dlg=new Window("dialog{text:'Test Panel'}"); 

dlg.pS=dlg.add('panel',undefined,'Select Option'); 

dlg.pS.alignChildren=['Left','Top']; 

dlg.pS.orientation='column'; 

dlg.pS.cb=dlg.pS.add('group'); 

dlg.pS.cb.orientation='Row'; 

dlg.pS.cb.c1=dlg.pS.cb.add('checkbox',undefined,'Opt 1'); 

dlg.pS.cb.c2=dlg.pS.cb.add('checkbox',undefined,'Opt 2'); 

dlg.pS.cb.c3=dlg.pS.cb.add('checkbox',undefined,'Opt 3'); 

dlg.pS.cb.c4=dlg.pS.cb.add('checkbox',undefined,'Opt 4');

dlg.pS.cb.btnCANCEL=dlg.pS.cb.add('button',undefined,'Ok'); 

dlg.pS.cb.btnCANCEL.onClick=function(){dlg.close();return this.value=true;} 

dlg.show(); 

// get the values of the checked check boxes 

dlg.pS.cb.onClick = function()  

     { 

          var msg = '\r'; 

          for (j=0; j<dlg.pS.cb.length-1;j++) 

               { 

                    if (dlg.pS.cb.value == true) 

                         msg = msg + dlg.pS.cb.text + '\r'; 

                   

var textRef = msg.textFrames.add();

textRef.contents = msg;

textRef.top = 400;

textRef.left = 100;

textRef.textRange.characterAttributes.size = 20;                   

                   

               } 

     } 

TOPICS
Scripting

Views

511

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 , Dec 09, 2016 Dec 09, 2016

Here you go. This should do what you want. I did find some other issues along the way that hadn't shown themselves to you because the script was never actually getting to the onClick function. It was merely closing the dialog and moving on. One of the other issues you had was that you were attempting to add a textFrame to the "msg" variable which was merely a string and thus, textFrame.add() is not an available method. I also added a cancel button so you can exit the dialog without making any ch

...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

you set the variable name for the "ok" button as the "cancel" button (even though there isn't one). So when you click on the ok button, it runs the function that closes the dialog and returns.

change this line:

dlg.pS.cb.btnCANCEL=dlg.pS.cb.add('button', undefined,'OK');

to this:

dlg.pS.cb.btnOK=dlg.pS.cb.add('button', undefined,'OK');

and remove this line:

dlg.pS.cb.btnCANCEL.onClick=function(){dlg.close();return this.value=true;}

the other issue is that the onClick function you're trying to run is assigned to the 'group' rather than the correct button. In testing, i also had an issue getting this to work, and it looks like the way you're defining variables for the groups/checkboxes/buttons doesn't allow for an onClick event to be fired properly. You'd do well to declare variables normally and then things tend to get easier. I'm in the process of rewriting this right now because that's easier than trying to fix it. i'll send it over in a minute.

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
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Here you go. This should do what you want. I did find some other issues along the way that hadn't shown themselves to you because the script was never actually getting to the onClick function. It was merely closing the dialog and moving on. One of the other issues you had was that you were attempting to add a textFrame to the "msg" variable which was merely a string and thus, textFrame.add() is not an available method. I also added a cancel button so you can exit the dialog without making any changes if you need to.

Let me know if this works well for you.

function container()

{

    var docRef = app.activeDocument;

    var dlg = new Window("dialog", "Test Panel");

        var pS = dlg.add("panel", undefined, "Select Option");

            pS.alignChildren=["Left", "Top"];

            pS.orientation="column";

            //define the checkbox group

            //cbg = Check Box Group

            var cbg = pS.add("group");

                //define the checkboxes

                var cb1 = cbg.add("checkbox", undefined, "Opt 1");

                var cb2 = cbg.add("checkbox", undefined, "Opt 2");

                var cb3 = cbg.add("checkbox", undefined, "Opt 3");

                var cb4 = cbg.add("checkbox", undefined, "Opt 4");

            //make a group for the buttons

            var btnGroup = pS.add("group");

                //define the buttons

                var okButton = btnGroup.add("button", undefined, "OK");

                //set the onClick function

                okButton.onClick = function()

                {

                    var msg = '\r';

                    for (var j=0; j<cbg.children.length; j++)

                    {

                        if(cbg.children.value == true)

                        {

                            msg += cbg.children.text + '\r';

                        }

                        var textRef = docRef.textFrames.add();

                        textRef.contents = msg;

                        textRef.top = 400;

                        textRef.left = 100;

                        textRef.textRange.characterAttributes.size = 20;

                    }

                    dlg.close();

                }

                var cancelButton = btnGroup.add("button", undefined, "Cancel");

                //set cancel onClick function

                cancelButton.onClick = function()

                {

                    dlg.close();

                }

    dlg.show();

}

container();

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
Community Expert ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

was this helpful at all? did it work for you?

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
Explorer ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Yes... Thanks for Helping... this mixed with your other recent assistance... is helping a ton....

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
Community Expert ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

LATEST

If you could, please mark the answers correct whenever your question is answered. That helps people in the future to know that a solution was the correct one. Otherwise they may be trying to duplicate something that didn't work in the first place.

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