Adding A User Interface To "Hello World; Creating A More Complex User Interface - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
7: User Interfaces
HAPTER

Adding a User Interface to "Hello World"

In this example, we add a simple user interface to the Hello World tutorial script presented in Adobe
InDesign CS5 Scripting Tutorial. The options in the dialog box provide a way for you to specify the sample
text and change the point size of the text:
var myDialog = app.dialogs.add({name:"Simple User Interface Example
Script",canCancel:true});
with(myDialog){
//Add a dialog column.
with(dialogColumns.add()){
//Create a text edit field.
var myTextEditField = textEditboxes.add({editContents:"Hello World!",
minWidth:180});
//Create a number (real) entry field.
var myPointSizeField = measurementEditboxes.add({editValue:72,
editUnits:MeasurementUnits.points});
}
}
//Display the dialog box.
var myResult = myDialog.show();
if(myResult == true){
//Get the values from the dialog box controls.
var myString = myTextEditField.editContents;
var myPointSize = myPointSizeField.editValue;
//Remove the dialog box from memory.
myDialog.destroy();
myMakeDocument(myString, myPointSize);
}
else{
myDialog.destroy();
}
Here is the
function myMakeDocument(myString, myPointSize){
//Create a new document.
var myDocument = app.documents.add()
with(myDocument){
//Create a text frame.
var myTextFrame = pages.item(0).textFrames.add();
//Resize the text frame to the "live" area of the page
//(using the function "myGetBounds").
var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
myTextFrame.geometricBounds=myBounds;
//Enter the text from the dialog box in the text frame.
myTextFrame.contents=myString;
//Set the size of the text to the size you entered in the dialog box.
myTextFrame.texts.item(0).pointSize = myPointSize;
}
}

Creating a More Complex User Interface

In the next example, we add more controls and different types of controls to the sample dialog box. The
example creates a dialog box that resembles the following:
function referred to in the above fragment:
myMakeDocument
Adding a User Interface to "Hello World" 113

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents