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

What's wrong with this dialog box? I can't get the value.

Guide ,
Jul 29, 2025 Jul 29, 2025

Prompt: getCn ,GetCsp is undefined

The dialog box has been bothering me.

Can this mm be entered like this? How can I make the value in this dialog box be mm?

 

Thank you very much.

var getCn, getCsp;

makeDialog();
alert("columns:" + getCn)
alert("spacing:" + getCsp)
function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel: "number of columns:" });
        staticTexts.add({ staticLabel: "spacing:" });
    }
    with (theDialog.dialogColumns.add()) {
        var getCn = textEditboxes.add({ editContents: "4" });
        var getCsp = textEditboxes.add({ editContents: "6mm" });
    }

    if (theDialog.show() == true) {
        //dialog results preset and page range
        getCn = getCn.editContents.split(',');
        getCsp = getCsp.editContents.split(',');
        theDialog.destroy();
    }
}

 

TOPICS
Scripting
418
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 4 Correct answers

Valorous Hero , Jul 30, 2025 Jul 30, 2025

Prompt: getCn ,GetCsp is undefined

First, you define these variables in the 1st line as globals.

Then inside the makeDialog function, you redefine them as locals -- note var before them -- so they exist only in the function's scope. Finally, you use them (globals) in alerts, but global variables remain untouched -- undefined.

Translate
Valorous Hero , Jul 30, 2025 Jul 30, 2025

How about using measurementEditboxes instead of textEditBoxes?

var getCn, getCsp;

makeDialog();
alert("columns: " + getCn);
alert("spacing: " + getCsp);

function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel: "number of columns:" });
        staticTexts.add({ staticLabel: "spacing:" });
    }
    with (theDialog.d
...
Translate
Community Expert , Jul 30, 2025 Jul 30, 2025

Hi @dublove , Also, your alert() isn’t returning anything because the variables have not been defined yet. And your column field wants to be an integer, so use integerEditboxes. Call a function on the line before destroy():

 

var getCn, getCsp;

makeDialog();
function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel:
...
Translate
Community Expert , Aug 01, 2025 Aug 01, 2025

Keep in mind the measurementEditbox box expects editValue to be set as Points—the points are converted to the EditUnits or left as Points if no editUnit is provided.

 

So here the editValue is set to 17.008 but displays as 6mm in the dialog and returns Points no matter what value is entered:

 

var getCn, getCsp;
makeDialog();
function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (the
...
Translate
Guide ,
Jul 29, 2025 Jul 29, 2025

@rob day 

Please take a look at this for me, 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
Valorous Hero ,
Jul 30, 2025 Jul 30, 2025

Prompt: getCn ,GetCsp is undefined

First, you define these variables in the 1st line as globals.

Then inside the makeDialog function, you redefine them as locals -- note var before them -- so they exist only in the function's scope. Finally, you use them (globals) in alerts, but global variables remain untouched -- undefined.

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 ,
Jul 30, 2025 Jul 30, 2025

Hi Kasyan Servetsky.

I couldn't figure it out even after looking at it for a long time.
I'm too careless... I think I can still be saved.
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
Valorous Hero ,
Jul 30, 2025 Jul 30, 2025

How about using measurementEditboxes instead of textEditBoxes?

var getCn, getCsp;

makeDialog();
alert("columns: " + getCn);
alert("spacing: " + getCsp);

function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel: "number of columns:" });
        staticTexts.add({ staticLabel: "spacing:" });
    }
    with (theDialog.dialogColumns.add()) {
       getCn = measurementEditboxes.add({ editContents: "4", editUnits: MeasurementUnits.MILLIMETERS});
       getCsp = measurementEditboxes.add({ editContents: "6" , editUnits: MeasurementUnits.MILLIMETERS});
    }

    if (theDialog.show() == true) {
        getCn = getCn.editContents;
        getCsp = getCsp.editContents;
        theDialog.destroy();
    }
}

  

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 ,
Jul 30, 2025 Jul 30, 2025

Hi @dublove , Also, your alert() isn’t returning anything because the variables have not been defined yet. And your column field wants to be an integer, so use integerEditboxes. Call a function on the line before destroy():

 

var getCn, getCsp;

makeDialog();
function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel: "number of columns:" });
        staticTexts.add({ staticLabel: "spacing:" });
    }
    with (theDialog.dialogColumns.add()) {
        getCn = integerEditboxes.add({editValue:4});
        getCsp = measurementEditboxes.add({ editContents: "6" , editUnits: MeasurementUnits.MILLIMETERS});
    }

    if (theDialog.show() == true) {
        getCn = getCn.editContents;
        getCsp = getCsp.editContents;
        //run a function that uses the global results
        main()
        theDialog.destroy();
    }
}


function main(){
    alert("columns: " + getCn + "      spacing: " + getCsp);
}

 

 

Screen Shot 25.png

 

Screen Shot 26.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 ,
Jul 30, 2025 Jul 30, 2025

Hi Kasyan Servetsky 

Hi rob day 

 

Thank you both very much.
I just jumped out of another “hole.”
Are the “holes” we step into our own doing?
What a painful day. I suffered all day because of my own “hole.”

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 ,
Jul 30, 2025 Jul 30, 2025

Also, here are the properties available with the InDesign ExtentScript DialogColumn class:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DialogColumn.html

 

An alternative way to make dialogs is with the ScriptUI classes—for simple dialogs I think the InDesign dialog class is easier to learn .

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 ,
Aug 01, 2025 Aug 01, 2025

Hi rob day.
It seems that after spacing, a number needs to be entered, with the default unit being mm.
The requirement is that mm cannot appear in the input box.

Modifying it this way doesn't seem right either.

 

Okay, you need to set the scale to mm before entering. Are the numbers you enter in mm?
I think I saw that somewhere.

 

var csp = getCsp;
This causes some strange errors.

But if I change it directly to
var csp = 6;

Everything works fine.

 

 getCsp = integerEditboxes.add({ editValue: 6 });
        //getCsp = measurementEditboxes.add({ editContents: “6”, editUnits: MeasurementUnits.MILLIMETERS });

012.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
Community Expert ,
Aug 01, 2025 Aug 01, 2025

Then use realEditBoxes.

 

Just be aware that you will have to consider what the ruler units are set to—6 could be inches, points, milimeters etc—you would need to set the expected ruler units at the beginnig of the script. With a measurementEditbox the user can set it in the dialog to anything—the current ruler units are not considered. Note that measurementEditbox always converts the unit used to points.

 

getCsp = realEditboxes.add({editValue:6});
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 ,
Aug 01, 2025 Aug 01, 2025

Thank you very much.

I just found it somewhere else.

var mm = 2.83465;
I just found it somewhere else.
getCsp = measurementEditboxes.add({ editValue: (6 * mm), editUnits: MeasurementUnits.millimeters });
}
    if (theDialog.show() == true) {
        getCn = getCn.editContents;
        getCsp = getCsp.editValue;
    }

 

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 ,
Aug 01, 2025 Aug 01, 2025

Keep in mind the measurementEditbox box expects editValue to be set as Points—the points are converted to the EditUnits or left as Points if no editUnit is provided.

 

So here the editValue is set to 17.008 but displays as 6mm in the dialog and returns Points no matter what value is entered:

 

var getCn, getCsp;
makeDialog();
function makeDialog() {
    var theDialog = app.dialogs.add({ name: "Column number and spacing settings", canCancel: true, minHeight: 600, minWidth: 400, });
    with (theDialog.dialogColumns.add()) {
        staticTexts.add({ staticLabel: "number of columns:" });
        staticTexts.add({ staticLabel: "spacing:" });
    }
    with (theDialog.dialogColumns.add()) {
        getCn = integerEditboxes.add({editValue:4});
        getCsp = measurementEditboxes.add({ editValue: 17.008  , editUnits: MeasurementUnits.MILLIMETERS });
    }

    if (theDialog.show() == true) {
        getCn = getCn.editContents;
        getCsp = getCsp.editValue;
        //run a function that uses the global results
        main()
        theDialog.destroy();
    }
}


function main(){
    alert("Returned spacing editValue: " + getCsp + " Points");
}

 

Screen Shot 5.png

 

Screen Shot 6.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 ,
Aug 02, 2025 Aug 02, 2025

I don't know why it was designed this way,
In the end, this is what I did.

        getCsp = measurementEditboxes.add({ editValue: (6 * mm), editUnits: MeasurementUnits.millimeters });
....
getCsp = getCsp.editValue / mm;

 

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 ,
Aug 02, 2025 Aug 02, 2025
LATEST

I don't know why it was designed this way,

 

When you are letting the user choose the unit there has to be a default return value —in this case it happens to be Points.

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 ,
Aug 01, 2025 Aug 01, 2025

Can you use a script to set the xy axis scale to mm?
Put it at the beginning of the script.

 

Go to sleep, good night.

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