Highlighted

setting up a dialog box to get multiple page numbers and assign variables

Explorer ,
Mar 09, 2020

Copy link to clipboard

Copied

 

I'm setting up an input dialog box to get page numbers that eventually will be output to pdf's. Currently I have set up 4 boxes to get those variables but I'm wondering if there is a better way, a more flexible way? Maybe Someone might need 6 pages or 10. Does anyone know how this might be accomplished?

 

var myInputGroup3 = myWindow.add("group");
        myInputGroup3.alignment="right";
            myInputGroup3.add("statictext", undefined, "PAGE NUMBERS:");
            var myText3=myInputGroup3.add("edittext", undefined, "1");
                myText3.characters=14;
            var myText3b=myInputGroup3.add("edittext", undefined, "4-5");
                myText3b.characters=13;
            var myText3c=myInputGroup3.add("edittext", undefined, "8");
                myText3c.characters=13;
            var myText3d=myInputGroup3.add("edittext", undefined, "10");
                myText3d.characters=13;


pageNumber = (myText3.text);
pageNumberb = (myText3b.text);
pageNumberc = (myText3c.text);
pageNumberd = (myText3d.text);

 

Topics

Scripting

Views

220

Likes

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

setting up a dialog box to get multiple page numbers and assign variables

Explorer ,
Mar 09, 2020

Copy link to clipboard

Copied

 

I'm setting up an input dialog box to get page numbers that eventually will be output to pdf's. Currently I have set up 4 boxes to get those variables but I'm wondering if there is a better way, a more flexible way? Maybe Someone might need 6 pages or 10. Does anyone know how this might be accomplished?

 

var myInputGroup3 = myWindow.add("group");
        myInputGroup3.alignment="right";
            myInputGroup3.add("statictext", undefined, "PAGE NUMBERS:");
            var myText3=myInputGroup3.add("edittext", undefined, "1");
                myText3.characters=14;
            var myText3b=myInputGroup3.add("edittext", undefined, "4-5");
                myText3b.characters=13;
            var myText3c=myInputGroup3.add("edittext", undefined, "8");
                myText3c.characters=13;
            var myText3d=myInputGroup3.add("edittext", undefined, "10");
                myText3d.characters=13;


pageNumber = (myText3.text);
pageNumberb = (myText3b.text);
pageNumberc = (myText3c.text);
pageNumberd = (myText3d.text);

 

Topics

Scripting

Views

221

Likes

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
Adobe Community Professional ,
Mar 09, 2020

Copy link to clipboard

Copied

Lots of ways to skin this cat, depending on your ultimate needs. One solution could be to just use one text range field, then parse that field. You'd have to validate the input, of course. 

var myText3=myInputGroup3.add("edittext", undefined, "Insert range here");
var pages = [];
var splitText = myText3.split(",");
for (var i = 0; i < splitText.length; i++) {
    splitText[i] = splitText[i].replace(/ +/,"");
    if (splitText[i].match(/\d{1,}-\d{1,}/gi)) {
       //this is a range, like 4-5. You can then write some code to parse out the individual pages then push to the pages array
    }
    else if (isNaN(splitText[i])) {
        $.writeln((splitText[i] + "is not a valid input"));
    }
    else {
        pages.push(splitText[i]);
    }
}

Likes

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
Reply
Loading...
Enthusiast ,
Mar 09, 2020

Copy link to clipboard

Copied

Use a repeat loop to set up the input fields in the dialog box. Here are the steps:

1. Use a simple dialog to get the number of pages ("entries"). Pass this value to a function.
2. Inside the function: Set up an empty array for the entries (eList). Create a custom dialog with a single column.
3. Inside the column use a repeat loop to create a border panel (1 for each page)
4. Inside each border panel create a dialog column to hold the dialog rows.
5. In creating each border panel input field, assign a variable to capture the field's contents.
6. Create an associative array (name value pairs) for the border panel's field results. Add the associative array to the "entries" array.
7. The associative array for each border panel will look similar to:
[panelName:pName, pageName:edit contents of field1, numChar:edit contents of field2]
8. If user does not cancel the dialog, the "entries" array is passed back to the main function.

 

Hope this helps

Likes

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
Reply
Loading...