Skip to main content
Participating Frequently
March 15, 2018
Answered

Run a Particular Function as per Radio Button Selection

  • March 15, 2018
  • 3 replies
  • 454 views

Hello Guys.

Thank you in advance for your help.

I have a code in which I  created a Dialogue Box from which user needs to select the option.

As per the selected Radio Button/CheckBox I want to run particular function.

main();

function main()

{

    preCheck();

    myDialogueMenu();

    objectType1();

    objectType2();

}

function myDialogueMenu()

{

   // Activating the user Interaction  with the Application

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

   

    var myDoc = app.activeDocument;

  

    //User Interaction Adding Main Dialog Box

    var myDialog = app.dialogs.add({name:"Choose your options", canCancel:true});

   

    with(myDialog)

    {

        with(dialogColumns.add())

        {

            with(borderPanels.add())

            {

                staticTexts.add({staticLabel:"Object Type:"});

                var myObjectTypeButtons = radiobuttonGroups.add();

                with(myObjectTypeButtons)

                {

                    radiobuttonControls.add({staticLabel:"Without Bleed", checkedState:true});

                    radiobuttonControls.add({staticLabel:"With Bleed"});

                }

            }

       

            with(borderPanels.add())

            {

                with (dialogColumns.add())

                {

                    with (dialogRows.add())

                    {

                        with (dialogColumns.add())

                        {

                            staticTexts.add({staticLabel:"Bleed Offset :", minWidth:0});

                        }

                        with (dialogColumns.add())

                        {

                            var myOffset = measurementEditboxes.add({editValue:0.125});

                        }

                    }

                }

            }

        }

    }

    var myReturn = myDialog.show();

}

Kindly guide me.

This topic has been closed for replies.
Correct answer Loic.Aigon

If you mean running a function after dialog is closed but specific to a user selection in the UI, you need to track the value of the object such as

if ( myDialog.show() ) {

               if(myRadioButtonGroup.selectedButton == ) …

}

If you want a function to be run when the user clicks on the radio button element, I don't think it's feasible with teh Dialog Class. You would need ScriptUI.

3 replies

JIANIMAuthor
Participating Frequently
March 16, 2018

Thank you so much. That worked perfectly.

JIANIMAuthor
Participating Frequently
March 16, 2018

Thank you for your response.

I am a beginner in InDesign scripting. How to get the selectedButton?

Whether by the Static text name which is in the dialogue box?

with(myObjectTypeButtons)

                {

                    radiobuttonControls.add({staticLabel:"Without Bleed", checkedState:true});

                    radiobuttonControls.add({staticLabel:"With Bleed"});

                }

....

if ( myDialog.show() ) {

               if(myRadioButtonGroup.selectedButton == ["Without Bleed"] )

                   {

                         alert("Run a Function");

                    }

}

Kindly let me know.

Loic.Aigon
Legend
March 16, 2018

== [index] as in ==0 or == 1 where the index is the radio button position in the parent group.

Loic.Aigon
Loic.AigonCorrect answer
Legend
March 15, 2018

If you mean running a function after dialog is closed but specific to a user selection in the UI, you need to track the value of the object such as

if ( myDialog.show() ) {

               if(myRadioButtonGroup.selectedButton == ) …

}

If you want a function to be run when the user clicks on the radio button element, I don't think it's feasible with teh Dialog Class. You would need ScriptUI.