EasyManua.ls Logo

Adobe 0046100128056 - InDesign - Mac - Adding a User Interface to Hello World; Creating a more Complex User Interface

Adobe 0046100128056 - InDesign - Mac
209 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER 7: User Interfaces Adding a User Interface to “Hello World” 113
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 myMakeDocument function referred to in the above fragment:
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:

Table of Contents