Skip to main content
John_Kordas
Inspiring
April 20, 2009
Answered

JS CS3 Simple Dialog to change doc starting page.

  • April 20, 2009
  • 2 replies
  • 1129 views

This example presents the user a dialog telling them the what their current document starting page is. The user can then change the value and update the starting page number. For some reason I'm getting a error Cannot handle the request because a modal dialog or alert is active. I have set myDialog.close(); before the if statement so should this not stop this error?

I have not added any checks to ensure a doc is open in ID yet.

var myDialog = new Window('dialog', ' Starting Pg No');

    myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
    myDialog.dPgNo.alignChildren = 'left';
    myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
    myDialog.dPgNo.myPgNo.group = myDialog.dPgNo.myPgNo.add('group');
    myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
    with (myDialog.dPgNo){
    myPgNo.group.orientation = 'column';
    myPgNo.group.alignChildren = 'right';
    myPgNo.group.preferredSize = [90,15];
    myPgNo.group.st  = myPgNo.group.add('statictext',undefined,'Your Doc starting page is:');
    myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
    btnGroup.btn = btnGroup.add('button', undefined, 'Update');
    btnGroup.alignment = 'right';
    }

myDialog.dPgNo.btnGroup.btn.onClick = function() {
myDialog.close();
var myPagestart = myDialog.dPgNo.myPgNo.et.text;
if (app.activeDocument.pages[0].name != myPagestart){
app.activeDocument.pages[0].appliedSection.continueNumbering = false; //<-----------ESTK stops here with the error mentioned before.
app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
alert("Your document start page has been changed to "+myPagestart+".");
}
myDialog.show();
}

myDialog.show();

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Hi John,


You don't need to close and reopen the window. Instead of dialog use 'palette' type of the window and run the script in a persistent engine, e.g. #targetengine "session".

Kasyan


#targetengine "session"
var myDialog = new Window('palette','Starting Pg No');
    myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
    myDialog.dPgNo.alignChildren = 'left';
    myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
    myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
    myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
    with (myDialog.dPgNo){
        myPgNo.myGroup.orientation = 'column';
        myPgNo.myGroup.alignChildren = 'right';
        myPgNo.myGroup.preferredSize = [90,15];
        myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
        myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
        btnGroup.btn = btnGroup.add('button', undefined, 'Update');
        btnGroup.alignment = 'right';
    }
myDialog.show();

myDialog.dPgNo.btnGroup.btn.onClick = function() {
    var myPagestart = myDialog.dPgNo.myPgNo.et.text;
    if (app.activeDocument.pages[0].name != myPagestart){
        app.activeDocument.pages[0].appliedSection.continueNumbering = false;
        app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
        app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
        alert("Your document start page has been changed to "+myPagestart+".");
    }
}

2 replies

Harbs.
Legend
April 20, 2009

In scripting, modal dialogs can not make any changes until they are

closed. The way I handle these situations when I want modal dialogs is

save the settings to a variable, and then after the dialog is closed I

make the changes.

Something like this:

Harbs

http://www.in-tools.com

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Legend
April 20, 2009

Hi John,


You don't need to close and reopen the window. Instead of dialog use 'palette' type of the window and run the script in a persistent engine, e.g. #targetengine "session".

Kasyan


#targetengine "session"
var myDialog = new Window('palette','Starting Pg No');
    myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
    myDialog.dPgNo.alignChildren = 'left';
    myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
    myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
    myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
    with (myDialog.dPgNo){
        myPgNo.myGroup.orientation = 'column';
        myPgNo.myGroup.alignChildren = 'right';
        myPgNo.myGroup.preferredSize = [90,15];
        myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
        myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
        btnGroup.btn = btnGroup.add('button', undefined, 'Update');
        btnGroup.alignment = 'right';
    }
myDialog.show();

myDialog.dPgNo.btnGroup.btn.onClick = function() {
    var myPagestart = myDialog.dPgNo.myPgNo.et.text;
    if (app.activeDocument.pages[0].name != myPagestart){
        app.activeDocument.pages[0].appliedSection.continueNumbering = false;
        app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
        app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
        alert("Your document start page has been changed to "+myPagestart+".");
    }
}

John_Kordas
Inspiring
April 20, 2009

Thanks Kasyan,

For some reason when I tried to run the script from ESTK I kept getting an error could not run session. I ran it form ID and it worked fine. I then went back to ESTK and now it works. Don't know what happened there but it's working now.

Much appreciated.

Kasyan Servetsky
Legend
April 20, 2009
For some reason when I tried to run the script from ESTK I kept getting an error could not run session.

Create a persistent engine at start up: e.g. place a scipt containing #targetengine "session" into 'Adobe InDesign CS3\Scripts\Startup Scripts' folder.

For example:

#targetengine "session"

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;