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

Create a new document from a dialog

New Here ,
Apr 07, 2010 Apr 07, 2010

Our publication has Ads with set width sizes (1 to 7 columns)  35, 73, 110, 148, 186, 224, 262 mm wide.

the hieght goes from 10mm to 380mm

and i am using a VERY simple script to create them

// Ads size 200x7
var myDocument = app.documents.add();
with(myDocument.documentPreferences){
pageHeight = "200mm";
pageWidth = "262mm";
pageOrientation = PageOrientation.landscape;
pagesPerDocument = 1;
}

The probelm is i need an indivual script for every size. So 1 script would be better but i am struggling with user dialogs

does anyone know or have an old script that i can look at to get a better understanding of how to write my own.

My final goal is to have a dialog that ask 2 things

Height = user enters any value

width = 7 predefined choices only (radio buttons)

Using Idesign CS3  PC  javascript

TOPICS
Scripting
3.9K
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 1 Correct answer

Engaged , Apr 19, 2010 Apr 19, 2010

Here is your script with Radio Buttons:

var UIresult = myDisplayDialog(); // Ads size 200x7 if (UIresult.rb[0]){createDocument("35", UIresult.docHeight);} if (UIresult.rb[1]){createDocument("73", UIresult.docHeight);} if (UIresult.rb[2]){createDocument("110", UIresult.docHeight);} if (UIresult.rb[3]){createDocument("148", UIresult.docHeight);} if (UIresult.rb[4]){createDocument("186", UIresult.docHeight);} if (UIresult.rb[5]){createDocument("224", UIresult.docHeight);} if (UIresult.rb[6]){createD

...
Translate
Engaged ,
Apr 08, 2010 Apr 08, 2010

Why you want create document through javascript or dialog.

Just go File --> New, and use indesign New Document Windows and enter values that you want.

I have created dialog for your script.

Check below one

var UIresult = myDisplayDialog(); // Ads size 200x7 var myDocument = app.documents.add(); with(myDocument.documentPreferences){ pageHeight = UIresult[1] + "mm"; pageWidth = UIresult[0] + "mm"; pageOrientation = PageOrientation.landscape; pagesPerDocument = 1; } function myDisplayDialog()    {         var myDialog = new Window ('dialog', 'Create New Document');         myDialog.alignChildren = "left";         var rg0 = myDialog.add ('group');         rg0.add('statictext',undefined, 'Select Document Width:');         var docuWidth = rg0.add('dropdownList', undefined ,[35, 73, 110, 148, 186, 224, 262]);         docuWidth.selection = docuWidth[1];         rg0.add('statictext',undefined, 'mm');         var rg1 = myDialog.add ('group');         rg1.add('statictext',undefined, 'Enter Document Height:');         var docuHeight = rg1.add('edittext',undefined, '380');         rg1.add('statictext',undefined, 'mm');         var rg2 = myDialog.add ('group');         rg2.alignment = "right";         rg2.add('button', undefined, 'Cancel', {name: 'cancel'});         rg2.add('button', undefined, 'OK', {name: 'ok'}); var myResult = myDialog.show(); if (myResult == 1) {      return [docuWidth.selection.toString (), docuHeight.text]; } if (myResult == 2) {      exit(); } }

Shonky

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
New Here ,
Apr 19, 2010 Apr 19, 2010

Thankyou for your direction, i manage to get your script working with a little change(i think there might be a CS4 to CS3 issue).

and yes you are right i could just go file new but most of our work is for a newspaper and ad sizes are give in columns, eg 10 by 7 which translates to 100mm by 263mm, so everytime you create an ad you constantly have to check a chart. so having a script where the columns are already set is a big step forward.

anyway below is the script that works in CS3, i havnt got the radio button working yet, not from a lack of trying, but more from poor scripting references or my lack of being able to understand them.

var UIresult = myDisplayDialog();

// Ads size 200x7
var myDocument = app.documents.add();
with(myDocument.documentPreferences){
pageHeight = UIresult[1] + "mm";
pageWidth = UIresult[0] + "mm";
pagesPerDocument = 1;
}
function myDisplayDialog()
   {
        var myDialog = new Window ('dialog', 'New Document 7 columns');
        myDialog.alignChildren = "left";
        var rg0 = myDialog.add ('group');
        rg0.add('statictext',undefined, 'name of company');
            rg0.add('statictext',undefined, 'Select Column Width:');
     var docuWidth = rg0.add('dropdownlist',undefined,[35, 73, 110, 148, 186, 224, 262]);
  docuWidth.selection = docuWidth[1];
        rg0.add('statictext',undefined, 'mm');
var rg1 = myDialog.add ('group');
        rg1.add('statictext',undefined, 'Enter Document Height:');
        var docuHeight = rg1.add('edittext',undefined, '380');
        rg1.add('statictext',undefined, 'mm');
        var rg2 = myDialog.add ('group');
        rg2.alignment = "right";
        rg2.add('button', undefined, 'Cancel', {name: 'cancel'});
        rg2.add('button', undefined, 'OK', {name: 'ok'});

var myResult = myDialog.show();
if (myResult == 1)
{
     return [docuWidth.selection.toString (), docuHeight.text];
}
if (myResult == 2)
{
     exit();
}
}

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
Engaged ,
Apr 19, 2010 Apr 19, 2010

Here is your script with Radio Buttons:

var UIresult = myDisplayDialog(); // Ads size 200x7 if (UIresult.rb[0]){createDocument("35", UIresult.docHeight);} if (UIresult.rb[1]){createDocument("73", UIresult.docHeight);} if (UIresult.rb[2]){createDocument("110", UIresult.docHeight);} if (UIresult.rb[3]){createDocument("148", UIresult.docHeight);} if (UIresult.rb[4]){createDocument("186", UIresult.docHeight);} if (UIresult.rb[5]){createDocument("224", UIresult.docHeight);} if (UIresult.rb[6]){createDocument("262", UIresult.docHeight);} function createDocument(docHeight, docWidth) { var myDocument = app.documents.add(); with(myDocument.documentPreferences){ pageHeight = docHeight + "mm"; pageWidth = docWidth + "mm"; pagesPerDocument = 1;} } function myDisplayDialog()    {         var myDialog = new Window ('dialog', 'New Document 7 columns');         myDialog.alignChildren = "left";         var rg0 = myDialog.add ('group');         rg0.add('statictext',undefined, 'Select Column Width:');           var rb1 = rg0.add('radiobutton',undefined, '35');           var rb2 = rg0.add('radiobutton',undefined, '73');           var rb3 = rg0.add('radiobutton',undefined, '110');           var rb4 = rg0.add('radiobutton',undefined, '148');           var rb5 = rg0.add('radiobutton',undefined, '186');           var rb6 = rg0.add('radiobutton',undefined, '224');           var rb7 = rg0.add('radiobutton',undefined, '262');           rg0.add('statictext',undefined, 'mm');           rb1.value = true;           var rg1 = myDialog.add ('group');         rg1.add('statictext',undefined, 'Enter Document Height:');         var docuHeight = rg1.add('edittext',undefined, '380');         rg1.add('statictext',undefined, 'mm');         var rg2 = myDialog.add ('group');         rg2.alignment = "right";         rg2.add('button', undefined, 'Cancel', {name: 'cancel'});         rg2.add('button', undefined, 'OK', {name: 'ok'}); var myResult = myDialog.show(); if (myResult == 1) {      return {rb : [rb1.value, rb2.value, rb3.value, rb4.value, rb5.value, rb6.value, rb7.value], docHeight : docuHeight.text}; } if (myResult == 2) {      exit(); } }

Shonky

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
New Here ,
Apr 19, 2010 Apr 19, 2010
LATEST

Wow thanks, i can see where i was going wrong now, i wasnt returning the variables afterwards.

just one small thing if anyone else is going to use this great script that shonkyin wrote.

just swap around the height and width in the below line.

function createDocument(docHeight, docWidth) { var myDocument = app.documents.add();

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