Adobe 65009333 Scripting Guide - Page 17

Adding features to “Hello World

Page 17 highlights

Getting Started Adding features to "Hello World" 17 "1p6," is returned as "1.5." InCopy does this because your scripting system would have trouble trying to perform arithmetic operations using measurement strings. For instance, trying to add "0p3.5" to "13p4" produces a script error, while adding .2916 to 13.333 (the converted pica measurements) does not. If your script depends on adding, subtracting, multiplying, or dividing specific measurement values, you might want to set the corresponding measurement units at the beginning of the script. At the end of the script, you can set the measurement units back to whatever they were before you ran the script. Alternately, you can use measurement overrides, like many of the sample scripts. A measurement override is a string containing a special character, as shown in the following table: Override p pt mm cm c i (or in) Meaning picas (add points after the p, if necessary) points millimeters centimeters ciceros (add didots after the c, if necessary) inches Example 1p6 18pt 6.35mm .635cm 1.4c .25i Adding features to "Hello World" Next, we create a new script that makes changes to the "Hello World" publication we created with our first script. Our second script demonstrates how to do the following: ➤ Get the active document. ➤ Change the formatting of the text in the first story. ➤ Add a note. Either open the ImprovedHelloWorld tutorial script or follow these steps to create the script: 1. Make sure you have the document you created earlier open. If you closed the document without saving it, simply run the HelloWorld.jsx script again to make a new document. 2. Enter the following JavaScript in a new text file:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

Getting Started
Adding features to “Hello World”
17
“1p6,” is returned as “1.5.” InCopy does this because your scripting system would have trouble trying to
perform arithmetic operations using measurement strings. For instance, trying to add “0p3.5” to “13p4”
produces a script error, while adding .2916 to 13.333 (the converted pica measurements) does not.
If your script depends on adding, subtracting, multiplying, or dividing specific measurement values, you
might want to set the corresponding measurement units at the beginning of the script. At the end of the
script, you can set the measurement units back to whatever they were before you ran the script.
Alternately, you can use measurement overrides, like many of the sample scripts. A measurement override
is a string containing a special character, as shown in the following table:
Adding features to “Hello World”
Next, we create a new script that makes changes to the “Hello World” publication we created with our first
script. Our second script demonstrates how to do the following:
Get the active document.
Change the formatting of the text in the first story.
Add a note.
Either open the ImprovedHelloWorld tutorial script or follow these steps to create the script:
1.
Make sure you have the document you created earlier open. If you closed the document without
saving it, simply run the
HelloWorld.jsx
script again to make a new document.
2.
Enter the following JavaScript in a new text file:
Override
Meaning
Example
p
picas (add points after the p, if necessary)
1p6
pt
points
18pt
mm
millimeters
6.35mm
cm
centimeters
.635cm
c
ciceros (add didots after the c, if necessary)
1.4c
i (or in)
inches
.25i