Adobe 65009333 Scripting Guide - Page 27

Placing text and setting text-import preferences

Page 27 highlights

Text and Type Placing text and setting text-import preferences 27 var myDocument = app.documents.add(); var myStory = myDocument.stories.item(0); //Entering special characters directly. myStory.contents = "Registered trademark: ®\rCopyright: ©\rTrademark: ™\r"; //Entering special characters by their Unicode glyph ID value: myStory.insertionPoints.item(-1).contents = "Not equal to: \u2260\rSquare root: \u221A\rParagraph: \u00B6\r"; //Entering InCopy special characters by their enumerations: myStory.insertionPoints.item(-1).contents = "Automatic page number marker:"; myStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber; myStory.insertionPoints.item(-1).contents = "\r"; myStory.insertionPoints.item(-1).contents = "Section symbol:"; myStory.insertionPoints.item(-1).contents = SpecialCharacters.sectionSymbol; myStory.insertionPoints.item(-1).contents = "\r"; myStory.insertionPoints.item(-1).contents = "En dash:"; myStory.insertionPoints.item(-1).contents = SpecialCharacters.enDash; myStory.insertionPoints.item(-1).contents = "\r"; The easiest way to find the Unicode ID for a character is to use the Glyphs palette in InCopy (choose Type > Glyphs to display the palette)-move the cursor over a character in the palette, and InCopy will display its Unicode value. You can find out more about Unicode by visiting http://www.unicode.org. Placing text and setting text-import preferences In addition to entering text strings, you can place text files created with word processors and text editors. The following script shows you how to place a text file in the default story of a new document (for the complete script, see PlaceTextFile): //Places a text file in the default story of a new document. var myDocument = app.documents.add(); //Parameters for InsertionPoint.place(): //File as File object, //[ShowingOptions as Boolean = False] //You'll have to fill in your own file path. myDocument.stories.item(0).insertionPoints.item(0).place(File("/c/test.txt"), false); To specify the import options for the specific type of text file you are placing, use the corresponding import-preferences object. The following script shows how to set text-import preferences (for the complete script, see TextImportPreferences). Comments in the script show the possible values for each property. //Sets the text import filter preferences. with(app.textImportPreferences){ //Options for characterSet: //TextImportCharacterSet.ansi //TextImportCharacterSet.chineseBig5 //TextImportCharacterSet.gb18030 //TextImportCharacterSet.gb2312 //TextImportCharacterSet.ksc5601 //TextImportCharacterSet.macintoshCE //TextImportCharacterSet.macintoshCyrillic //TextImportCharacterSet.macintoshGreek //TextImportCharacterSet.macintoshTurkish //TextImportCharacterSet.recommendShiftJIS83pv //TextImportCharacterSet.shiftJIS90ms //TextImportCharacterSet.shiftJIS90pv //TextImportCharacterSet.unicode //TextImportCharacterSet.windowsBaltic

  • 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

Text and Type
Placing text and setting text-import preferences
27
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
//Entering special characters directly.
myStory.contents = "Registered trademark: ®\rCopyright: ©\rTrademark: ™\r";
//Entering special characters by their Unicode glyph ID value:
myStory.insertionPoints.item(-1).contents = "Not equal to: \u2260\rSquare root:
\u221A\rParagraph: \u00B6\r";
//Entering InCopy special characters by their enumerations:
myStory.insertionPoints.item(-1).contents = "Automatic page number marker:";
myStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber;
myStory.insertionPoints.item(-1).contents = "\r";
myStory.insertionPoints.item(-1).contents = "Section symbol:";
myStory.insertionPoints.item(-1).contents = SpecialCharacters.sectionSymbol;
myStory.insertionPoints.item(-1).contents = "\r";
myStory.insertionPoints.item(-1).contents = "En dash:";
myStory.insertionPoints.item(-1).contents = SpecialCharacters.enDash;
myStory.insertionPoints.item(-1).contents = "\r";
The easiest way to find the Unicode ID for a character is to use the Glyphs palette in InCopy (choose Type >
Glyphs to display the palette)—move the cursor over a character in the palette, and InCopy will display its
Unicode value. You can find out more about Unicode by visiting
.
Placing text and setting text-import preferences
In addition to entering text strings, you can place text files created with word processors and text editors.
The following script shows you how to place a text file in the default story of a new document (for the
complete script, see PlaceTextFile):
//Places a text file in the default story of a new document.
var myDocument = app.documents.add();
//Parameters for InsertionPoint.place():
//File as File object,
//[ShowingOptions as Boolean = False]
//You'll have to fill in your own file path.
myDocument.stories.item(0).insertionPoints.item(0).place(File("/c/test.txt"), false);
To specify the import options for the specific type of text file you are placing, use the corresponding
import-preferences object. The following script shows how to set text-import preferences (for the
complete script, see TextImportPreferences). Comments in the script show the possible values for each
property.
//Sets the text import filter preferences.
with(app.textImportPreferences){
//Options for characterSet:
//TextImportCharacterSet.ansi
//TextImportCharacterSet.chineseBig5
//TextImportCharacterSet.gb18030
//TextImportCharacterSet.gb2312
//TextImportCharacterSet.ksc5601
//TextImportCharacterSet.macintoshCE
//TextImportCharacterSet.macintoshCyrillic
//TextImportCharacterSet.macintoshGreek
//TextImportCharacterSet.macintoshTurkish
//TextImportCharacterSet.recommendShiftJIS83pv
//TextImportCharacterSet.shiftJIS90ms
//TextImportCharacterSet.shiftJIS90pv
//TextImportCharacterSet.unicode
//TextImportCharacterSet.windowsBaltic