Adobe InCopy CS6 Mwongozo wa Marejeleo
PDF
Hati
Tangazo
Tangazo
ADOBE® INCOPY® CS6
2012 Adobe Systems Incorporated. All rights reserved.
更新
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is
furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any
such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note
that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user
license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as
a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or
inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law.
The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please
be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any
actual organization.
Adobe, the Adobe logo, Creative Suite, InCopy, InDesign, Illustrator, and Photoshop are registered trademarks or trademarks of Adobe
Systems Incorporated in the United States and/or other countries. Microsoft and Windows are registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Apple and Mac OS are trademarks of Apple Computer,
Incorporated, registered in the United States and other countries. All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software
and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer
Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as
applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer
Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as
Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein.
Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose,
CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if
appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance
Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1
through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be
incorporated by reference.
目次
1
2
15
15
18
21
「Hello World」への機能の追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3
25
26
26
26
3
目次
4
4
29
29
29
30
30
37
38
39
40
41
41
44
44
44
45
45
47
47
47
48
48
49
50
52
表 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
自動修正 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
脚注 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5
6
目次
5
7
8
9
81
81
81
81
81
82
82
83
83
10
85
85
85
85
11
87
88
88
89
89
89
89
目次
6
90
90
90
90
90
91
91
91
92
92
92
93
94
96
1
概要
変更なし
7
第 1 章 概要
8
第 1 章 概要
9
第 1 章 概要
10
はじめに
2
更新
ユーザ /< ユーザー名 >/ ライブラリ /Preferences/Adobe InCopy/
Version 8.0-J/ja_JP/Scripts/Scripts Panel
Windows® XP:
C:¥Documents and Settings¥< ユーザー名 >¥Application Data¥Adobe¥InCopy¥
Version 8.0-J¥ja_JP¥Scripts¥Scripts Panel
11
12
Windows® Vista: C:¥ ユーザー ¥< ユーザー名 >¥App Data¥Roaming¥Adobe¥InCopy¥
Version 8.0-J¥ja_JP¥Scripts¥Scripts Panel
13
3.
4.
14
ExtendScript Toolkit(またはテキストエディター)を起動します。次のスクリプトを入力します(または、
HelloWorld.jsx というチュートリアルスクリプトを開きます)
。
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "Hello World!";
2.
3.
4.
15
説明
例
Boolean
True
Integer
Number
13.9972
String
Array
["0p0", "0p0", "16p4", "20p6"]
16
//To convert from a number to a string:
myNumber = 2;
myString = myNumber + "";
//To convert from a string to an integer:
myString = "2";
myNumber = parseInt(myString);
//If your string contains a decimal value, use "parseFloat" rather than "parseInt":
myNumber = parseFloat(myString);
//You can also convert strings to numbers using the following:
myNumber = +myString;
17
//Given a variable of unknown type, "myMysteryVariable"...
myType = myMysteryVariable.constructor.name;
//myType will be a string corresponding to the JavaScript type (e.g., "Rectangle")
では、myWidth が myHeight よりも大きい場合には true(または 1)が、そうでない場合には false(0)が返
されます。
JavaScript では、プラス記号(+)を使用して 2 つの文字列を結合させることができます。
"Pride " + "and Prejudice"
//returns the string: "Pride and Prejudice"
18
application
documents
a document
libraries
document preferences
books
document defaults
application preferences
document events
application defaults
document properties
application events
document methods
application menus
document elements
application properties
pages or spreads
application methods
page
stories
page items
text objects
Application
InCopy。
Application
defaults
Application
events
Application
menus
Application
methods
Application
preferences
Application
properties
Books
Document
19
用語
Document
defaults
Document
elements
Document
events
20
Document
methods
Document
preferences
Document
properties
Documents
Libraries
Page
Page item
Pages or
spreads
Stories
Text objects
ExtendScript Toolkit を起動します。
2.
3.
21
「Hello World」への機能の追加
22
意味
例
c
1.4 c
cm
.635 cm
インチ
.25 i
mm
6.35 mm
p
1p6
pt
ポイント
18 pt
2.
新しいテキストファイルに、次の JavaScript を入力します。
//Get a reference to a font.
try{
//Enter the name of a font on your system, if necessary.
var myFont = app.fonts.item("Arial");
}
on(myError){}
//Get the active document and assign the result to the variable "myDocument"
var myDocument = app.documents.item(0);
with(myDocument.stories.item(0)){
//Change the font, size, and paragraph alignment.
try{
appliedFont = myFont;
}
on(myError){}
justification = Justification.centerAlign;
pointSize = 48;
//Enter the note at the last insertion point of the story.
var myNote = insertionPoints.item(-1).notes.add();
myNote.texts.item(0).contents = "This is a note."
}
「Hello World」への機能の追加
23
3.
4.
3
編集
説明
EnableRedraw
scriptsFolder
scriptsList
24
プロパティ
userInteractionLevel
version
25
26
Version 8.0 Scripts
CS6
Version 7.0 Scripts
Version 6.0 Scripts
CS4
Version 5.0 Scripts
CS3
Version 2.0 Scripts
CS2
27
の DoScriptParameters より)
。
var myParameters = ["Hello from DoScript", "Your message here."];
var myJavaScript = "alert(¥"First argument: ¥" + arguments[0] + ¥"¥¥rSecond argument: ¥" +
arguments[1]);";
app.doScript(myJavaScript, ScriptLanguage.javascript, myParameters);
if(File.fs == "Windows"){
var myVBScript = "msgbox arguments(1), vbOKOnly, ¥"First argument: ¥" & arguments(0)";
app.doScript(myVBScript, ScriptLanguage.visualBasic, myParameters);
}
else{
var myAppleScript = "tell application ¥"Adobe InCopy CS6¥"¥rdisplay dialog(¥"First argument:
¥" & item 1 of arguments & return & ¥"Second argument: ¥" & item 2 of arguments)¥rend tell";
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage, myParameters);
}
28
var myJavaScript = "app.scriptArgs.setValue(¥"ScriptArgumentA¥", ¥"This is the first script
argument value.¥");¥r";
myJavaScript += "app.scriptArgs.setValue(¥"ScriptArgumentB¥", ¥"This is the second script
argument value.¥")";
var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA");
var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB");
alert("ScriptArgumentA: " + myScriptArgumentA + "¥rScriptArgumentB: " + myScriptArgumentB);
if(File.fs == "Windows"){
var myVBScript = "Set myInCopy = CreateObject(¥"InCopy.Application¥")¥r";
myVBScript += "myInCopy.ScriptArgs.SetValue ¥"ScriptArgumentA¥", ¥"This is the first script
argument value.¥"¥r";
myVBScript += "myInCopy.ScriptArgs.SetValue ¥"ScriptArgumentB¥", ¥"This is the second script
argument value.¥"";
app.doScript(myVBScript, ScriptLanguage.visualBasic);
}
else{
var myAppleScript = "tell application ¥"Adobe InCopy CS6¥"¥r";
myAppleScript += "make script arg with properties{name:¥"ScriptArgumentA¥", value:¥"This is
the first script argument value.¥"}¥r";
myAppleScript += "make script arg with properties{name:¥"ScriptArgumentB¥", value:¥"This is
the second script argument value.¥"}¥r";
myAppleScript += "end tell¥r";
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);
}
var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA");
var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB");
alert("ScriptArgumentA: " + myScriptArgumentA + "¥rScriptArgumentB: " + myScriptArgumentB);
4
変更なし
29
30
var myDocument = app.documents.add();
//Add text to the default story.
var myStory = myDocument.stories.item(0);
myStory.contents = "This is the first paragraph of example text.";
//To add more text to the story, we'll use the last insertion point
//in the story. ("¥r" is a return character in JavaScript.)
var myInsertionPoint = myStory.insertionPoints.item(-1);
myInsertionPoint.contents = "¥rThis is the second paragraph.";
テキストの置換
次のスクリプトでは、適当なオブジェクトの内容を変更することで、1 つの単語をある語句に置換していま
す(完全なスクリプトについては、ReplaceWord を参照してください)。
//Enters text in the default story and then replaces
//a word in the story with a different phrase.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "This is some example text.";
//Replace the third word "some" with the phrase
//"a little bit of".
myStory.words.item(2).contents = "a little bit of";
次のスクリプトでは、段落内のテキストを置換しています(完全なスクリプトについては、ReplaceText を参
照してください)。
//Enters text in the default story, and then replaces
//the text in the second paragraph.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "Paragraph 1.¥rParagraph 2.¥rParagraph 3.¥r";
//Replace the text in the second paragraph without replacing
//the return character at the end of the paragraph. To do this,
//we'll use the ItemByRange method.
var myStartCharacter = myStory.paragraphs.item(1).characters.item(0);
var myEndCharacter = myStory.paragraphs.item(1).characters.item(-2);
myStory.texts.itemByRange(myStartCharacter, myEndCharacter).contents = "This text replaces the
text in paragraph 2.";
31
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";
テキストの配置とテキスト読み込み環境設定の指定
テキスト文字列の入力だけでなく、ワードプロセッサーやテキストエディターで作成したテキストファイル
を配置することもできます。新規ドキュメントのデフォルトストーリーにテキストファイルを配置する方法
を、次のスクリプトに示します(完全なスクリプトについては、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);
配置するテキストファイルの種類に応じた読み込みオプションを指定するには、対応する読み込み環境設定
オブジェクトを使用します。テキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全な
スクリプトについては、TextImportPreferences を参照してください)。スクリプトのコメントに、各プロパ
ティに指定可能な値を示します。
//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.utf8
//TextImportCharacterSet.utf16
//TextImportCharacterSet.windowsBaltic
//TextImportCharacterSet.windowsCE
//TextImportCharacterSet.windowsCyrillic
//TextImportCharacterSet.windowsEE
//TextImportCharacterSet.windowsGreek
32
//TextImportCharacterSet.windowsTurkish
characterSet = TextImportCharacterSet.utf16;
convertSpacesIntoTabs = true;
spacesIntoTabsCount = 3;
//The dictionary property can take any of the following
//language names (as strings):
//Bulgarian
//Catalan
//Croatian
//Czech
//Danish
//Dutch
//English: Canadian
//English: UK
//English: USA
//English: USA Legal
//English: USA Medical
//Estonian
//Finnish
//French
//French: Canadian
//German: Reformed
//German: Swiss
//German: Traditional
//Greek
//Hungarian
//Italian
//Latvian
//Lithuanian
//Neutral
//Norwegian: Bokmal
//Norwegian: Nynorsk
//Polish
//Portuguese
//Portuguese: Brazilian
//Romanian
//Russian
//Slovak
//Slovenian
//Spanish: Castilian
//Swedish
//Turkish
dictionary = "English: USA";
//platform options:
//ImportPlatform.macintosh
//ImportPlatform.pc
platform = ImportPlatform.macintosh;
stripReturnsBetweenLines = true;
stripReturnsBetweenParagraphs = true;
useTypographersQuotes = true;
}
タグ付きテキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、TaggedTextImportPreferences を参照してください)。
//Sets the tagged text import filter preferences.
with(app.taggedTextImportPreferences){
removeTextFormatting = false;
//styleConflict property can be:
//StyleConflict.publicationDefinition
//StyleConflict.tagFileDefinition
styleConflict = StyleConflict.publicationDefinition;
useTypographersQuotes = true;
}
Word および RTF 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、WordRTFImportPreferences を参照してください)。
//Sets the Word/RTF import filter preferences.
with(app.wordRTFImportPreferences){
//convertPageBreaks property can be:
//ConvertPageBreaks.columnBreak
//ConvertPageBreaks.none
//ConvertPageBreaks.pageBreak
convertPageBreaks = ConvertPageBreaks.none;
//convertTablesTo property can be:
//ConvertTablesOptions.unformattedTabbedText
//ConvertTablesOptions.unformattedTable
convertTablesTo = ConvertTablesOptions.unformattedTable;
importEndnotes = true;
importFootnotes = true;
importIndex = true;
importTOC = true;
importUnusedStyles = false;
preserveGraphics = false;
preserveLocalOverrides = false;
preserveTrackChanges = false;
removeFormatting = false;
//resolveCharacterSytleClash and resolveParagraphStyleClash properties can be:
//ResolveStyleClash.resolveClashAutoRename
//ResolveStyleClash.resolveClashUseExisting
//ResolveStyleClash.resolveClashUseNew
resolveCharacterStyleClash = ResolveStyleClash.resolveClashUseExisting;
resolveParagraphStyleClash = ResolveStyleClash.resolveClashUseExisting;
useTypographersQuotes = true;
}
Excel 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについては、
ExcelImportPreferences を参照してください)。
//Sets the Excel import filter preferences.
with(app.excelImportPreferences){
//alignmentStyle property can be:
//AlignmentStyleOptions.centerAlign
//AlignmentStyleOptions.leftAlign
//AlignmentStyleOptions.rightAlign
//AlignmentStyleOptions.spreadsheet
alignmentStyle = AlignmentStyleOptions.spreadsheet;
decimalPlaces = 4;
preserveGraphics = false;
//Enter the range you want to import as "start cell:end cell".
rangeName = "A1:B16";
sheetIndex = 1;
//You'll have to enter a valid worksheet name.
sheetName = "pathpoints";
showHiddenCells = false;
//tableFormatting property can be:
//TableFormattingOptions.excelFormattedTable
//TableFormattingOptions.excelUnformattedTabbedText
//TableFormattingOptions.excelUnformattedTable
tableFormatting = TableFormattingOptions.excelFormattedTable;
useTypographersQuotes = true;
viewName = "";
}
33
34
テキストの書き出しとテキスト書き出し環境設定の指定
InCopy ドキュメントからテキストを書き出す方法を、次のスクリプトに示します。テキストファイル形式で
書き出すには、テキストオブジェクトやストーリーオブジェクトを使用する必要があることに注意してくだ
さい。1 つの操作でドキュメント内のすべてのテキストを書き出すことはできません (完全なスクリプトに
ついては、ExportTextFile を参照してください)。
//Creates a story in an example document and then exports the text to a text file.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
//Fill the story with placeholder text.
var myTextFrame = myStory.textContainers[0];
myTextFrame.contents = TextFrameContents.placeholderText;
//Text exportFile method parameters:
//Format as ExportFormat
//To As File
//[ShowingOptions As Boolean = False]
//
//Format parameter can be:
//ExportFormat.inCopyCSDocument
//ExportFormat.inCopyDocument
//ExportFormat.rtf
//ExportFormat.taggedText
//ExportFormat.textType
//
//Export the story as text. You'll have to fill in a valid file path on your system.
myStory.exportFile(ExportFormat.textType, File("/c/test.txt"));
指定したテキスト範囲を書き出す方法を、次の例に示します (ここでは、myGetBounds 関数は省略していま
す。この関数については、ExportTextRange というチュートリアルスクリプトを参照してください)。
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
//Fill the story with placeholder text.
var myTextFrame = myStory.textContainers[0];
myTextFrame.contents = TextFrameContents.placeholderText;
var myStartCharacter = myStory.paragraphs.item(0).characters.item(0);
var myEndCharacter = myStory.paragraphs.item(1).characters.item(-1);
var myText = myStory.texts.itemByRange(myStartCharacter, myEndCharacter);
//Text exportFile method parameters:
//Format as ExportFormat
//To As File
//[ShowingOptions As Boolean = False]
//
//Format parameter can be:
//ExportFormat.inCopyCSDocument
//ExportFormat.inCopyDocument
//ExportFormat.rtf
//ExportFormat.taggedText
//ExportFormat.textType
//
//Export the text range. You must fill in a valid file path on your system.
myText.exportFile(ExportFormat.textType, File("/c/test.txt"));
35
//Sets the text export filter preferences.
with(app.textExportPreferences){
//Options for characterSet:
//TextExportCharacterSet.utf8
//TextExportCharacterSet.utf16
//TextExportCharacterSet.defaultPlatform
characterSet = TextExportCharacterSet.utf16;
//platform options:
//ImportPlatform.macintosh
//ImportPlatform.pc
platform = ImportPlatform.macintosh;
}
タグ付きテキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完全なスクリプトにつ
いては、TaggedTextExportPreferences を参照してください)。
//Sets the tagged text export filter preferences.
with(app.taggedTextExportPreferences){
//Options for characterSet:
//TagTextExportCharacterSet.ansi
//TagTextExportCharacterSet.ascii
//TagTextExportCharacterSet.gb18030
//TagTextExportCharacterSet.ksc5601
//TagTextExportCharacterSet.shiftJIS
//TagTextExportCharacterSet.utf8
//TagTextExportCharacterSet.utf16
characterSet = TagTextExportCharacterSet.utf16;
//tagForm options:
//TagTextForm.abbreviated
//TagTextForm.verbose
tagForm = TagTextForm.verbose;
}
既存の書き出しフィルターを使用しないでテキストを書き出すこともできます。JavaScript には、テキスト
ファイルをディスクに書き出す機能が用意されています。この機能を利用すれば、スクリプトでドキュメン
ト内のテキストをスキャンして、任意のテキストマークアップスキームを使用して任意の順序でテキストを
書き出すことができます。HTML 形式で InCopy テキストを書き出す簡単な例を次に示します(完全なスクリ
プトについては、ExportHTML を参照してください)。
function myExportHTML(){
var myStory, myParagraph, myString, myTag, myStartTag, myEndTag,
myTextStyleRange, myTable;
//Use the myStyleToTagMapping array to set up your paragraph style to tag mapping.
var myStyleToTagMapping = new Array;
//For each style to tag mapping, add a new item to the array.
myStyleToTagMapping.push(["body_text", "p"]);
myStyleToTagMapping.push(["heading1", "h1"]);
myStyleToTagMapping.push(["heading2", "h2"]);
myStyleToTagMapping.push(["heading3", "h3"]);
//End of style to tag mapping.
if(app.documents.length !=0){
if(app.documents.item(0).stories.length != 0){
//Open a new text file.
var myTextFile = File.saveDialog("Save HTML As", undefined);
//If the user clicked the Cancel button, the result is null.
if(myTextFile != null){
//Open the file with write access.
myTextFile.open("w");
//Iterate through the stories.
for(var myCounter = 0; myCounter <
app.documents.item(0).stories.length; myCounter ++){
myStory = app.documents.item(0).stories.item(myCounter);
for(var myParagraphCounter = 0; myParagraphCounter <
myStory.paragraphs.length; myParagraphCounter ++){
myParagraph = myStory.paragraphs.item(myParagraphCounter);
if(myParagraph.tables.length == 0){
if(myParagraph.textStyleRanges.length == 1){
//If the paragraph is a simple paragraph--no tables,
//no local formatting--simply export the text
//of the pararaph with the appropriate tag.
myTag = myFindTag(myParagraph.appliedParagraphStyle.
name, myStyleToTagMapping);
//If the tag comes back empty,
//map it to the basic paragraph tag.
if(myTag == ""){
myTag = "p";
}
myStartTag = "<" + myTag + ">";
myEndTag = "</" + myTag + ">";
//If the paragraph is not the last paragraph in the
//story, omit the return character.
if(myParagraph.characters.item(-1).contents == "¥r"){
myString = myParagraph.texts.itemByRange
(myParagraph.characters.item(0),
myParagraph.characters.item(-2)).contents;
}
else{
myString = myParagraph.contents;
}
//Write the paragraphs' text to the text file.
myTextFile.writeln(myStartTag + myString + myEndTag);
}
else{
//Handle text style range export by iterating
//through the text style ranges in the paragraph.
for(var myRangeCounter = 0; myRangeCounter <
myParagraph.textStyleRanges.length;
myRangeCounter ++){
myTextStyleRange = myParagraph.textStyleRanges.
item(myRangeCounter);
if(myTextStyleRange.characters.item(-1)=="¥r"){
myString = myTextStyleRange.texts.itemByRange
(myTextStyleRange.characters.item(1),
myTextStyleRange.characters.item(-2)).
contents;
}
else{
myString = myTextStyleRange.contents;
}
switch(myTextStyleRange.fontStyle){
case "Bold":
myString = "<b>" + myString + "</b>"
break;
case "Italic":
myString = "<i>" + myString + "</i>"
break;
}
myTextFile.write(myString);
}
myTextFile.write("¥r");
}
}
36
37
else{
//Handle table export (assumes that there is only
//one table per paragraph,and that the table is in the
//paragraph by itself).
myTable = myParagraph.tables.item(0);
myTextFile.writeln("<table border = 1>");
for(var myRowCounter = 0; myRowCounter <
myTable.rows.length; myRowCounter ++){
myTextFile.writeln("<tr>");
for(var myColumnCounter = 0; myColumnCounter <
myTable.columns.length; myColumnCounter++){
if(myRowCounter == 0){
myString = "<th>" + myTable.rows.item
(myRowCounter).cells.item(myColumnCounter).
texts.item(0).contents + "</th>";
}
else{
myString = "<td>" + myTable.rows.item
(myRowCounter).cells.item(myColumnCounter).
texts.item(0).contents + "</td>";
}
myTextFile.writeln(myString);
}
myTextFile.writeln("</tr>");
}
myTextFile.writeln("</table>");
}
}
}
//Close the text file.
myTextFile.close();
}
}
}
}
function myFindTag (myStyleName, myStyleToTagMapping){
var myTag = "";
var myDone = false;
var myCounter = 0;
do{
if(myStyleToTagMapping[myCounter][0] == myStyleName){
myTag = myStyleToTagMapping[myCounter][1];
break;
}
myCounter ++;
} while((myDone == false)||(myCounter < myStyleToTagMapping.length))
return myTag;
}
38
document
story
spread, page, layer
insertion points
characters
text containers
text frame
words
insertion points
lines
characters
paragraphs
words
text columns
lines
text style ranges
paragraphs
texts
text columns
notes
text style ranges
texts
notes
選択
InCopy のスクリプトでよく行われる操作の 1 つが、テキスト選択に対する操作です。現在選択されているも
のの種類を判別する方法を、次のスクリプトに示します。他の多くのサンプルスクリプトと異なり、このス
クリプトは実際には何も行いません。このスクリプトでは、選択をフィルタリングする方法のみが示されて
います (完全なスクリプトについては、TextSelection を参照してください)。
//Shows how to determine whether the current selection is a text selection.
//Check to see if any documents are open.
if (app.documents.length != 0){
//If the selection contains more than one item, the selection
//is not text selected with the Type tool.
if (app.selection.length != 0){
//Evaluate the selection based on its type.
switch (app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
39
case "Story":
//The object is a text object; display the text object type.
//A practical script would do something with the selection,
//or pass the selection on to a function.
alert("Selection is a " + app.selection[0].constructor.name);
//If the selection is inside a note, the parent of the selection
//will be a note object.
if(app.selection[0].parent.constructor.name == "Note"){
alert("Selection is inside a note.");
}
break;
default:
alert("The selected object is not a text object. Select some text and try again.");
break;
}
}
else{
alert("Please select some text and try again.");
}
}
else{
alert("No documents are open.");
}
スクリプトにその例を示します(完全なスクリプトについては、MoveText を参照してください)。
//Create an example document.
var myDocument = app.documents.add();
//Create a series of paragraphs in the default story.
var myStory = myDocument.stories.item(0);
myStory.contents = "WordA¥rWordB¥rWordC¥rWordD¥r";
//Move WordC before WordA.
myStory.paragraphs.item(2).move(LocationOptions.before, myStory.paragraphs.item(0));
//Move WordB after WordD (into the same paragraph).
myStory.paragraphs.item(2).move(LocationOptions.after,
myStory.paragraphs.item(-1).words.item(0));
//Note that moving text removes it from its original location.
フォーマットされたテキストをドキュメント間で転送する場合にも、move メソッドが使用できます。コピー
して貼り付けるよりも、move メソッドや duplicate メソッドを使用するほうが優れています。コピーして貼
り付けるためには、ドキュメントを表示して、コピーするテキストを選択しなければなりません。move や
duplicate を使用するほうが速くて確実です。move や duplicate を使用して、ドキュメント間でテキストを
移動する方法を、次のスクリプトに示します(完全なスクリプトについては、MoveTextBetweenDocuments
を参照してください)。
//Moves formatted text from one document to another.
var mySourceDocument = app.documents.add();
//Add text to the default story.
var mySourceStory = mySourceDocument.stories.item(0);
mySourceStory.contents = "This is the source text.¥rThis text is not the source text.";
mySourceStory.paragraphs.item(0).pointSize = 24;
//Create a new document to move the text to.
var myTargetDocument = app.documents.add();
var myTargetStory = myTargetDocument.stories.item(0);
myTargetStory.contents = "This is the target text. Insert the source text after this
paragraph.¥r";
mySourceStory.paragraphs.item(0).duplicate(LocationOptions.after,
myTargetStory.insertionPoints.item(-1));
40
フォーマットされていないテキストをテキストオブジェクト間でコピーする方法としては、コピーするテキ
ストオブジェクトの contents プロパティを取得して、その文字列を別のテキストオブジェクトの contents
プロパティに設定する方法があります。次のスクリプトにその例を示します(完全なスクリプトについては、
CopyUnformattedText を参照してください)。
//Shows how to remove formatting from text as you move it
//to other locations in a document.
//Create an example document.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "This is a formatted string.¥rText pasted after this text will retain its
formatting.¥r¥rText moved to the following line will take on the formatting of the insertion
point.¥rItalic: ";
//Apply formatting to the first paragraph.
myStory.paragraphs.item(0).fontStyle = "Bold";
//Apply formatting to the last paragraph.
myStory.paragraphs.item(-1).fontStyle = "Italic";
//Copy from one frame to another using a simple copy.
app.select(myStory.paragraphs.item(0).words.item(0));
app.copy();
app.select(myStory.paragraphs.item(1).insertionPoints.item(-1));
app.paste();
//Copy the unformatted string from the first word to the end of the story
//by getting and setting the contents of text objects. Note that this does
//not really copy the text; it replicates the text string from one text
//location to another.
myStory.insertionPoints.item(-1).contents = myStory.paragraphs.item(0).words.item(0).contents;
テキストオブジェクトと反復処理
一連のテキストオブジェクトに対して繰り返して処理を行っている間に、テキストの移動、削除、追加を行
うと、テキスト参照に問題が発生することがあります。このような問題が発生する例を、次のスクリプトに
示します(完全なスクリプトについては、TextIterationWrong を参照してください)。
//Shows how *not* to iterate through text.
var myDocument = app.documents.add();
var myString = "Paragraph 1.¥rDelete this paragraph.¥rParagraph 2.¥rParagraph 3.¥rParagraph
4.¥rParagraph 5.¥rDelete this paragraph.¥rParagraph 6.¥r";
var myStory = myDocument.stories.item(0);
myStory.contents = myString;
//The following for loop will fail to format all of the paragraphs.
for(var myParagraphCounter = 0; myParagraphCounter < myStory.paragraphs.length;
myParagraphCounter ++){
if(myStory.paragraphs.item(myParagraphCounter).words.item(0).contents == "Delete"){
myStory.paragraphs.item(myParagraphCounter).remove();
}
else{
myStory.paragraphs.item(myParagraphCounter).pointSize = 24;
}
}
41
//Shows the correct way to iterate through text.
var myDocument = app.documents.add();
var myString = "Paragraph 1.¥rDelete this paragraph.¥rParagraph 2.¥rParagraph 3.¥rParagraph
4.¥rParagraph 5.¥rDelete this paragraph.¥rParagraph 6.¥r";
var myStory = myDocument.stories.item(0);
myStory.contents = myString;
//The following for loop will format all of the paragraphs by iterating
//backwards through the paragraphs in the story.
for(var myParagraphCounter = myStory.paragraphs.length-1; myParagraphCounter >= 0;
myParagraphCounter --){
if(myStory.paragraphs.item(myParagraphCounter).words.item(0).contents == "Delete"){
myStory.paragraphs.item(myParagraphCounter).remove();
}
else{
myStory.paragraphs.item(myParagraphCounter).pointSize = 24;
}
}
テキストデフォルトの設定
テキストデフォルトは、アプリケーションとドキュメントの両方で設定できます。アプリケーションのテキ
ストデフォルトは、新しく作成されるすべてのドキュメントのテキストデフォルトとして使用されます。ド
キュメントのテキストデフォルトは、そのドキュメントで新しく作成されるすべてのテキストオブジェクト
のフォーマットとして使用されます (完全なスクリプトについては、TextDefaults を参照してください)。
//Sets the text defaults of the application, which set the default formatting
//for all new documents. Existing text frames are unaffected.
//Set the measurement units to points.
app.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
app.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
//To set the text formatting defaults for a document, replace "app"
//in the following lines with a reference to a document.
with(app.textDefaults){
alignToBaseline = true;
//Because the font might not be available, it's usually best
//to apply the font within a try...catch structure. Fill in the
//name of a font on your system.
try{
appliedFont = app.fonts.item("Minion Pro");
}
catch(e){}
//Because the font style might not be available, it's usually best
//to apply the font style within a try...catch structure.
try{
fontStyle = "Regular";
}
catch(e){}
//Because the language might not be available, it's usually best
//to apply the language within a try...catch structure.
try{
appliedLanguage = "English: USA";
}
catch(e){}
autoLeading = 100;
balanceRaggedLines = false;
baselineShift = 0;
capitalization = Capitalization.normal;
composer = "Adobe Paragraph Composer";
desiredGlyphScaling = 100;
desiredLetterSpacing = 0;
desiredWordSpacing = 100;
dropCapCharacters = 0;
if(dropCapCharacters != 0){
dropCapLines = 3;
//Assumes the application has a default character style named "myDropCap"
dropCapStyle = app.characterStyles.item("myDropCap");
}
fillColor = app.colors.item("Black");
fillTint = 100;
firstLineIndent = 14;
gridAlignFirstLineOnly = false;
horizontalScale = 100;
hyphenateAfterFirst = 3;
hyphenateBeforeLast = 4;
hyphenateCapitalizedWords = false;
hyphenateLadderLimit = 1;
hyphenateWordsLongerThan = 5;
hyphenation = true;
hyphenationZone = 36;
hyphenWeight = 9;
justification = Justification.leftAlign;
keepAllLinesTogether = false;
keepLinesTogether = true;
keepFirstLines = 2;
keepLastLines = 2;
keepWithNext = 0;
kerningMethod = "Optical";
kerningValue = 0;
leading = 14;
leftIndent = 0;
ligatures = true;
maximumGlyphScaling = 100;
maximumLetterSpacing = 0;
maximumWordSpacing = 160;
minimumGlyphScaling = 100;
minimumLetterSpacing = 0;
minimumWordSpacing = 80;
noBreak = false;
otfContextualAlternate = true;
otfDiscretionaryLigature = false;
otfFigureStyle = OTFFigureStyle.proportionalOldstyle;
otfFraction = true;
otfHistorical = false;
otfOrdinal = false;
otfSlashedZero = false;
otfSwash = false;
otfTitling = false;
overprintFill = false;
overprintStroke = false;
pointSize = 11;
position = Position.normal;
rightIndent = 0;
ruleAbove = false;
if(ruleAbove == true){
ruleAboveColor = app.colors.item("Black");
42
ruleAboveGapColor = app.swatches.item("None");
ruleAboveGapOverprint = false;
ruleAboveGapTint = 100;
ruleAboveLeftIndent = 0;
ruleAboveLineWeight = .25;
ruleAboveOffset = 14;
ruleAboveOverprint = false;
ruleAboveRightIndent = 0;
ruleAboveTint = 100;
ruleAboveType = app.strokeStyles.item("Solid");
ruleAboveWidth = RuleWidth.columnWidth;
}
ruleBelow = false;
if(ruleBelow == true){
ruleBelowColor = app.colors.item("Black");
ruleBelowGapColor = app.swatches.item("None");
ruleBelowGapOverprint = false;
ruleBelowGapTint = 100;
ruleBelowLeftIndent = 0;
ruleBelowLineWeight = .25;
ruleBelowOffset = 0;
ruleBelowOverprint = false;
ruleBelowRightIndent = 0;
ruleBelowTint = 100;
ruleBelowType = app.strokeStyles.item("Solid");
ruleBelowWidth = RuleWidth.columnWidth;
}
singleWordJustification = SingleWordJustification.leftAlign;
skew = 0;
spaceAfter = 0;
spaceBefore = 0;
startParagraph = StartParagraph.anywhere;
strikeThru = false;
if(strikeThru == true){
strikeThroughColor = app.colors.item("Black");
strikeThroughGapColor = app.swatches.item("None");
strikeThroughGapOverprint = false;
strikeThroughGapTint = 100;
strikeThroughOffset = 3;
strikeThroughOverprint = false;
strikeThroughTint = 100;
strikeThroughType = app.strokeStyles.item("Solid");
strikeThroughWeight = .25;
}
strokeColor = app.swatches.item("None");
strokeTint = 100;
strokeWeight = 0;
tracking = 0;
underline = false;
if(underline == true){
underlineColor = app.colors.item("Black");
underlineGapColor = app.swatches.item("None");
underlineGapOverprint = false;
underlineGapTint = 100;
underlineOffset = 3;
underlineOverprint = false;
underlineTint = 100;
underlineType = app.strokeStyles.item("Solid");
underlineWeight = .25
}
verticalScale = 100;
}
43
44
フォント
InCopy アプリケーションオブジェクトのフォントコレクションには、InCopy で利用できるすべてのフォント
が含まれています。これとは対照的に、ドキュメントのフォントコレクションには、そのドキュメントで使
用されているフォントのみが含まれています。ドキュメントのフォントコレクションには、環境に無いフォ
ント(ドキュメントで使用されているが InCopy では利用できないフォント)も含まれます。アプリケーショ
ンフォントとドキュメントフォントの違いを調べる方法を、次のスクリプトに示します(完全なスクリプト
については、FontCollections を参照してください)。
//Shows the difference between the fonts collection of the application
//and the fonts collection of a document.
var myApplicationFonts = app.fonts;
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
var myDocumentFonts = myDocument.fonts;
var myFontNames = myApplicationFonts.everyItem().name;
if(myDocumentFonts.length > 0){
var myDocumentFontNames = myDocumentFonts.everyItem().name;
var myString = "Document Fonts:¥r";
for(var myCounter = 0;myCounter<myDocumentFontNames.length; myCounter++){
myString += myDocumentFontNames[myCounter] + "¥r";
}
}
myString += "¥rApplication Fonts:¥r";
for(var myCounter = 0;myCounter<myFontNames.length; myCounter++){
myString += myFontNames[myCounter] + "¥r";
}
myStory.contents = myString;
45
//Shows how to set all read/write properties of a text object.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "x";
var myTextObject = myStory.characters.item(0);
myTextObject.alignToBaseline = false;
myTextObject.appliedCharacterStyle = myDocument.characterStyles.item("[None]");
myTextObject.appliedFont = app.fonts.item("Minion ProRegular");
myTextObject.appliedLanguage = app.languagesWithVendors.item("English: USA");
myTextObject.appliedNumberingList = myDocument.numberingLists.item("[Default]");
myTextObject.appliedParagraphStyle = myDocument.paragraphStyles.item("[No Paragraph Style]");
myTextObject.autoLeading = 120;
myTextObject.balanceRaggedLines = BalanceLinesStyle.noBalancing;
myTextObject.baselineShift = 0;
myTextObject.bulletsAlignment = ListAlignment.leftAlign;
myTextObject.bulletsAndNumberingListType = ListType.noList;
myTextObject.bulletsCharacterStyle = myDocument.characterStyles.item("[None]");
myTextObject.bulletsTextAfter = "^t";
myTextObject.capitalization = Capitalization.normal;
myTextObject.composer = "Adobe Paragraph Composer";
myTextObject.desiredGlyphScaling = 100;
myTextObject.desiredLetterSpacing = 0;
myTextObject.desiredWordSpacing = 100;
myTextObject.dropCapCharacters = 0;
myTextObject.dropCapLines = 0;
myTextObject.dropCapStyle = myDocument.characterStyles.item("[None]");
myTextObject.dropcapDetail = 0;
//More text properties in the tutorial script.
テキストカラーの変更
テキスト文字の塗りと線にカラーを適用できます。次のスクリプトにその例を示します(チュートリアルス
クリプトの TextColors より)。
//Given two colors "myColorA" and "myColorB"...
var myStory = myDocument.stories.item(0);
//Enter text in the text frame.
myStory.contents = "Text¥rColor"
var myText = myStory.paragraphs.item(0)
myText.pointSize = 72;
myText.justification = Justification.centerAlign;
//Apply a color to the fill of the text.
myText.fillColor = myColorA;
//Use the itemByRange method to apply the color to the stroke of the text.
myText.strokeColor = myColorB;
var myText = myStory.paragraphs.item(1)
myText.strokeWeight = 3;
myText.pointSize = 144;
myText.justification = Justification.centerAlign;
myText.fillColor = myColorB;
myText.strokeColor = myColorA;
myText.strokeWeight = 3;
46
段落スタイルや文字スタイルを作成して適用する方法を、次のスクリプトに示します(完全なスクリプトに
ついては、CreateStyles を参照してください)。
//Shows how to create and apply a paragraph style and a character style.
var myParagraphStyle, myCharacterStyle, myColor, myName;
//Create an example document.
var myDocument = app.documents.add();
//Create a color for use by one of the paragraph styles we'll create.
try{
myColor = myDocument.colors.item("Red");
//If the color does not exist, trying to get its name generates an error.
myName = myColor.name;
}
catch (myError){
//The color style did not exist, so create it.
myColor = myDocument.colors.add({name:"Red", model:ColorModel.process, colorValue:[0, 100,
100, 0]});
}
var myStory = myDocument.stories.item(0);
//Fill the text frame with placeholder text.
myStory.textContainers[0].contents = "Normal text. Text with a character style applied to it. More
normal text.";
//Create a character style named "myCharacterStyle" if
//no style by that name already exists.
try{
myCharacterStyle = myDocument.characterStyles.item("myCharacterStyle");
//If the style does not exist, trying to get its name generates an error.
myName = myCharacterStyle.name;
}
catch (myError){
//The style did not exist, so create it.
myCharacterStyle = myDocument.characterStyles.add({name:"myCharacterStyle"});
}
//At this point, the variable myCharacterStyle contains a reference to a
//character-style object, which you can now use to specify formatting.
myCharacterStyle.fillColor = myColor;
//Create a paragraph style named "myParagraphStyle" if
//no style by that name already exists.
try{
myParagraphStyle = myDocument.paragraphStyles.item("myParagraphStyle");
//If the paragraph style does not exist, trying to get its name generates
//an error.
myName = myParagraphStyle.name;
}
catch (myError){
//The paragraph style did not exist, so create it.
myParagraphStyle = myDocument.paragraphStyles.add({name:"myParagraphStyle"});
}
//At this point, the variable myParagraphStyle contains a reference to a
//paragraph-style object, which you can now use to specify formatting.
myStory.texts.item(0).applyParagraphStyle(myParagraphStyle, true);
var myStartCharacter = myStory.characters.item(13);
var myEndCharacter = myStory.characters.item(54);
myStory.texts.itemByRange(myStartCharacter,
myEndCharacter).applyCharacterStyle(myCharacterStyle);
47
先頭文字スタイル(Nested Style)を使用すると、文字スタイルのフォーマットを特定のパターンに従って段
落に適用することができます。先頭文字スタイルを含む段落スタイルの作成方法を、次のスクリプトに示し
ます(完全なスクリプトについては、NestedStyles を参照してください)。
//At this point, the variable myParagraphStyle contains a reference to a
//paragraph-style object, which you can now use to specify formatting.var myNestedStyle =
myParagraphStyle.nestedStyles.add({appliedCharacterStyle:myCharacterStyle, delimiter:".",
inclusive:true, repetition:1});
var myStartCharacter = myStory.characters.item(0);
var myEndCharacter = myStory.characters.item(-1);
//Use the itemByRange method to apply the paragraph to all text in the
//story. (Note the story object does not have the applyStyle method.)
myStory.texts.itemByRange(myStartCharacter,
myEndCharacter).applyParagraphStyle(myParagraphStyle, true);
段落スタイルと文字スタイルの読み込み
他の InCopy ドキュメントから文字スタイルや段落スタイルを読み込むことができます。次のスクリプトにそ
の例を示します(完全なスクリプトについては、ImportTextStyles を参照してください)。
//Import the styles from the saved document.
//importStyles parameters:
//Format as ImportFormat enumeration. Options for text styles are:
//
ImportFormat.paragraphStylesFormat
//
ImportFormat.characterStylesFormat
//
ImportFormat.textStylesFormat
//From as File
//GlobalStrategy as GlobalClashResolutionStrategy enumeration. Options are:
//
GlobalClashResolutionStrategy.doNotLoadTheStyle
//
GlobalClashResolutionStrategy.loadAllWithOverwrite
//
GlobalClashResolutionStrategy.loadAllWithRename
myDocument.importStyles(ImportFormat.textStylesFormat, File(myFilePath),
GlobalClashResolutionStrategy.loadAllWithOverwrite);
48
検索/変更の環境設定を消去します。検索/変更操作の種類に応じて、次の 3 つのいずれかを行います。
//find/change text preferences
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//find/change grep preferences
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//find/change glyph preferences
app.findGlyphPreferences = NothingEnum.nothing;
app.changeGlyphPreferences = NothingEnum.nothing;
2.
3.
4.
テキストの検索と変更
指定したテキスト文字列を検索する方法を、次のスクリプトに示します。このスクリプトではドキュメント
全体を検索していますが、ストーリー、テキストフレーム、段落、テキスト列などのテキストオブジェクト
を検索することもできます。findText メソッドとそのパラメーターは、すべてのテキストオブジェクトで共
通しています (完全なスクリプトについては、FindText を参照してください)。
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Search the document for the string "Text".
app.findTextPreferences.findWhat = "text";
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
var myFoundItems = app.documents.item(0).findText();
alert("Found " + myFoundItems.length + " instances of the search string.");
49
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
//Search the document for the string "copy" and change it to "text".
app.findTextPreferences.findWhat = "copy";
app.changeTextPreferences.changeTo = "text";
app.documents.item(0).changeText();
//Clear the find/change preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
フォーマットの検索と変更
テキストフォーマットの検索や変更を行うには、findTextPreferences オブジェクトや
changeTextPreferences オブジェクトのその他のプロパティを設定します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの FindChangeFormatting より)。
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
//Search the document for the 24 point text and change it to 10 point text.
app.findTextPreferences.pointSize = 24;
app.changeTextPreferences.pointSize = 10;
app.documents.item(0).changeText();
//Clear the find/change preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
50
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
app.findTextPreferences.findWhat = "WIDGET^9^9^9^9";
//The following line will only work if your default font
//has a font style named "Bold" if not, change the text to
//a font style used by your default font.
app.changeTextPreferences.fontStyle = "Bold";
//Search the document. In this example, we'll use the
//InCopy search metacharacter "^9" to find any digit.
var myFoundItems = app.documents.item(0).changeText();
alert("Changed " + myFoundItems.length + " instances of the search string.");
//Clear the find/change preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
grep の使用
InCopy の findGrep メソッドや changeGrep メソッドを使用すれば、正規表現を利用した検索/変更操作が行
えます。正規表現を利用した検索/変更操作では、指定したフォーマットのテキストを検索したり、テキス
トのフォーマットを changeGrepPreferences オブジェクトのプロパティで指定したフォーマットに置換する
ことができます。これらのメソッドや関係する環境設定オブジェクトの使用方法を、次のスクリプトに示し
ます(完全なスクリプトについては、FindGrep を参照してください)。
//Clear the find/change preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//Regular expression for finding an email address.
app.findGrepPreferences.findWhat = "(?i)[A-Z]*?@[A-Z]*?[.]...";
//Apply the change to 24-point text only.
app.findGrepPreferences.pointSize = 24;
app.changeGrepPreferences.underline = true;
app.documents.item(0).changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
51
<heading1>This is a heading.
<body_text>This is body text.
grep 検索とテキスト検索/変更を組み合わせれば、テキストにフォーマットを適用して、マークアップタグ
を削除することができます。次のスクリプトにその例を示します(チュートリアルスクリプトの ReadPMTags
より)。
function myReadPMTags(myStory){
var myName, myString, myStyle, myStyleName;
var myDocument = app.documents.item(0);
//Reset the findGrepPreferences to ensure that previous settings
//do not affect the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Find the tags (since this is a JavaScript string, backslashes must be escaped).
app.findGrepPreferences.findWhat = "(?i)^<¥¥s*¥¥w+¥¥s*>";
var myFoundItems = myStory.findGrep();
if(myFoundItems.length != 0){
var myFoundTags = new Array;
for(var myCounter = 0; myCounter<myFoundItems.length; myCounter++){
myFoundTags.push(myFoundItems[myCounter].contents);
}
myFoundTags = myRemoveDuplicates(myFoundTags);
//At this point, we have a list of tags to search for.
for(myCounter = 0; myCounter < myFoundTags.length; myCounter++){
myString = myFoundTags[myCounter];
//Find the tag using findWhat.
app.findTextPreferences.findWhat = myString;
//Extract the style name from the tag.
myStyleName = myString.substring(1, myString.length-1);
//Create the style if it does not already exist.
try{
myStyle = myDocument.paragraphStyles.item(myStyleName);
myName = myStyle.name;
}
catch (myError){
myStyle = myDocument.paragraphStyles.add({name:myStyleName});
}
//Apply the style to each instance of the tag.
app.changeTextPreferences.appliedParagraphStyle = myStyle;
myStory.changeText();
//Reset the changeTextPreferences.
app.changeTextPreferences = NothingEnum.nothing;
//Set the changeTo to an empty string.
app.changeTextPreferences.changeTo = "";
//Search to remove the tags.
myStory.changeText();
//Reset the find/change preferences again.
app.changeTextPreferences = NothingEnum.nothing;
}
}
//Reset the findGrepPreferences.
app.findGrepPreferences = NothingEnum.nothing;
}
表
52
function myRemoveDuplicates(myArray){
//Semi-clever method of removing duplicate array items; much faster
//than comparing every item to every other item!
var myNewArray = new Array;
myArray = myArray.sort();
myNewArray.push(myArray[0]);
if(myArray.length > 1){
for(var myCounter = 1; myCounter < myArray.length; myCounter ++){
if(myArray[myCounter] != myNewArray[myNewArray.length -1]){
myNewArray.push(myArray[myCounter]);
}
}
}
return myNewArray;
}
字形検索の使用
特定のフォントに含まれている個々の文字を検索/変更するには、findGlyph メソッドや changeGlyph メ
ソッドを使用します。パラメーターは findGlyphPreferences オブジェクトや changeGlyphPreferences オブ
ジェクトで設定します。次のスクリプトでは、サンプルドキュメントの中で字形を検索し、変更しています
(完全なスクリプトについては、FindChangeGlyphs を参照してください)。
//Clear glyph search preferences.
app.findGlyphPreferences = NothingEnum.nothing;
app.changeGlyphPreferences = NothingEnum.nothing;
var myDocument = app.documents.item(0);
//You must provide a font that is used in the document for the
//appliedFont property of the findGlyphPreferences object.
app.findGlyphPreferences.appliedFont = app.fonts.item("Minion ProRegular");
//Provide the glyph ID, not the glyph Unicode value.
app.findGlyphPreferences.glyphID = 500;
//The appliedFont of the changeGlyphPreferences object can be
//any font available to the application.
app.changeGlyphPreferences.appliedFont = app.fonts.item("Times New RomanRegular");
app.changeGlyphPreferences.glyphID = 374;
myDocument.changeGlyph();
//Clear glyph search preferences.
app.findGlyphPreferences = NothingEnum.nothing;
app.changeGlyphPreferences = NothingEnum.nothing;
表
53
var myStory = myDocument.stories.item(0);
var myStartCharacter = myStory.paragraphs.item(6).characters.item(0);
var myEndCharacter = myStory.paragraphs.item(6).characters.item(-2);
var myText = myStory.texts.itemByRange(myStartCharacter, myEndCharacter);
//The convertToTable method takes three parameters:
//[ColumnSeparator as string]
//[RowSeparator as string]
//[NumberOfColumns as integer] (only used if the ColumnSeparator
//and RowSeparator values are the same)
//In the last paragraph in the story, columns are separated by commas
//and rows are separated by semicolons, so we provide those characters
//to the method as parameters.
var myTable = myText.convertToTable(",",";");
var myStartCharacter = myStory.paragraphs.item(1).characters.item(0);
var myEndCharacter = myStory.paragraphs.item(4).characters.item(-2);
var myText = myStory.texts.itemByRange(myStartCharacter, myEndCharacter);
//In the second through the fifth paragraphs, colums are separated by
//tabs and rows are separated by returns. These are the default delimiter
//parameters, so we don't need to provide them to the method.
var myTable = myText.convertToTable();
//You can also explicitly add a table--you don't have to convert text to a table.
var myTable = myStory.insertionPoints.item(-1).tables.add();
myTable.columnCount = 3;
myTable.bodyRowCount = 3;
表セルの結合方法を、次のスクリプトに示します(完全なスクリプトについては、MergeTableCells を参照し
てください)。
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
var myString = "Table¥r";
myStory.contents = myString;
var myTable = myStory.insertionPoints.item(-1).tables.add();
myTable.columnCount = 4;
myTable.bodyRowCount = 4;
//Merge all cells in the first column.
myTable.cells.item(0).merge(myTable.columns.item(0).cells.item(-1));
//Convert column 2 into 2 cells (rather than 4).
myTable.columns.item(1).cells.item(-1).merge(myTable.columns.item(1).cells.item(-2));
myTable.columns.item(1).cells.item(0).merge(myTable.columns.item(1).cells.item(1));
//Merge the last two cells in row 1.
myTable.rows.item(0).cells.item(-2).merge(myTable.rows.item(0).cells.item(-1));
//Merge the last two cells in row 3.
myTable.rows.item(2).cells.item(-2).merge(myTable.rows.item(2).cells.item(-1));
表セルの分割方法を、次のスクリプトに示します(完全なスクリプトについては、SplitTableCells を参照して
ください)
。
myTable.cells.item(0).split(HorizontalOrVertical.horizontal);
myTable.columns.item(0).split(HorizontalOrVertical.vertical);
myTable.cells.item(0).split(HorizontalOrVertical.vertical);
myTable.rows.item(-1).split(HorizontalOrVertical.horizontal);
myTable.cells.item(-1).split(HorizontalOrVertical.vertical);
for(myRowCounter = 0; myRowCounter < myTable.rows.length; myRowCounter ++){
myRow = myTable.rows.item(myRowCounter);
for(myCellCounter = 0; myCellCounter < myRow.cells.length; myCellCounter ++){
myString = "Row: " + myRowCounter + " Cell: " + myCellCounter;
myRow.cells.item(myCellCounter).contents = myString;
}
}
表
54
var myTable = app.documents.item(0).stories.item(0).tables.item(0);
//Convert the first row to a header row.
myTable.rows.item(0).rowType = RowTypes.headerRow;
//Convert the last row to a footer row.
myTable.rows.item(-1).rowType = RowTypes.footerRow;
表にフォーマットを適用する方法を、次のスクリプトに示します(完全なスクリプトについては、
TableFormatting を参照してください)。
var myTable = myDocument.stories.item(0).tables.item(0);
//Convert the first row to a header row.
myTable.rows.item(0).rowType = RowTypes.headerRow;
//Use a reference to a swatch, rather than to a color.
myTable.rows.item(0).fillColor = myDocument.swatches.item("DGC1_446b");
myTable.rows.item(0).fillTint = 40;
myTable.rows.item(1).fillColor = myDocument.swatches.item("DGC1_446a");
myTable.rows.item(1).fillTint = 40;
myTable.rows.item(2).fillColor = myDocument.swatches.item("DGC1_446a");
myTable.rows.item(2).fillTint = 20;
myTable.rows.item(3).fillColor = myDocument.swatches.item("DGC1_446a");
myTable.rows.item(3).fillTint = 40;
//Use everyItem to set the formatting of multiple cells at once.
myTable.cells.everyItem().topEdgeStrokeColor = myDocument.swatches.item("DGC1_446b");
myTable.cells.everyItem().topEdgeStrokeWeight = 1;
myTable.cells.everyItem().bottomEdgeStrokeColor = myDocument.swatches.item("DGC1_446b");
myTable.cells.everyItem().bottomEdgeStrokeWeight = 1;
//When you set a cell stroke to a swatch, make certain you also set the
//stroke weight.
myTable.cells.everyItem().leftEdgeStrokeColor = myDocument.swatches.item("None");
myTable.cells.everyItem().leftEdgeStrokeWeight = 0;
myTable.cells.everyItem().rightEdgeStrokeColor = myDocument.swatches.item("None");
myTable.cells.everyItem().rightEdgeStrokeWeight = 0;
表に反復行フォーマットを追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
AlternatingRows を参照してください)。
//Given a table "myTable" containing at least four rows and a document
//"myDocument" containing the colors "DGC1_446a" and "DGC1_446b"...
//Convert the first row to a header row.
myTable.rows.item(0).rowType = RowTypes.headerRow;
//Applly alternating fills to the table.
myTable.alternatingFills = AlternatingFillsTypes.alternatingRows;
myTable.startRowFillColor = myDocument.swatches.item("DGC1_446a");
myTable.startRowFillTint = 60;
myTable.endRowFillColor = myDocument.swatches.item("DGC1_446b");
myTable.endRowFillTint = 50;
テキストや表セルが選択されている場合の選択の処理方法を、次のスクリプトに示します。このスクリプト
では、選択状況に応じて警告を表示していますが、実際のスクリプトでは選択されているアイテムに応じて
何らかの操作を行うことになります (完全なスクリプトについては、TableSelection を参照してください)。
if(app.documents.length != 0){
if(app.selection.length != 0){
switch(app.selection[0].constructor.name){
//When a row, a column, or a range of cells is selected,
//the type returned is "Cell"
case "Cell":
alert("A cell is selected.");
break;
case "Table":
alert("A table is selected.");
break;
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
自動修正
55
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
if(app.selection[0].parent.constructor.name == "Cell"){
alert("The selection is inside a table cell.");
}
else{
alert("The selection is not inside a table.");
}
break;
default:
alert("The selection is not inside a table.");
break;
}
}
}
自動修正
自動修正機能を使用すると、テキストが入力されたときにテキストを自動的に修正することができます。次
のスクリプトにその例を示します(完全なスクリプトについては、Autocorrect を参照してください)。
//The autocorrect preferences object turns the
//autocorrect feature on or off.
app.autoCorrectPreferences.autoCorrect = true;
app.autoCorrectPreferences.autoCorrectCapitalizationErrors = true;
//Add a word pair to the autocorrect list. Each AutoCorrectTable is linked
//to a specific language.
var myAutoCorrectTable = app.autoCorrectTables.item("English: USA");
//To safely add a word pair to the auto correct table, get the current
//word pair list, then add the new word pair to that array, and then
//set the autocorrect word pair list to the array.
var myWordPairList = myAutoCorrectTable.autoCorrectWordPairList;
//Add a new word pair to the array.
myWordPairList.push(["paragarph", "paragraph"]);
//Update the word pair list.
myAutoCorrectTable.autoCorrectWordPairList = myWordPairList;
//To clear all autocorrect word pairs in the current dictionary:
//myAutoCorrectTable.autoCorrectWordPairList = [[]];
var myWord, myFootnote;
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Add four footnotes at random locations in the story.
for(myCounter = 0; myCounter < 4; myCounter ++){
myWord = myStory.words.item(myGetRandom(0, myStory.words.length));
var myFootnote = myWord.insertionPoints.item(-1).footnotes.add();
//Note: when you create a footnote, it contains text--the footnote
//marker and the separator text (if any). If you try to set the text of
//the footnote by setting the footnote contents, you will delete the
//marker. Instead, append the footnote text, as shown below.
myFootnote.insertionPoints.item(-1).contents = "This is a footnote.";
//This function gets a random number in the range myStart to myEnd.
function myGetRandom(myStart, myEnd){
var myRange = myEnd - myStart;
return myStart + Math.floor(Math.random()*myRange);
}
脚注
56
5
変更なし
dialog column
static text
border panel
checkbox control
radiobutton group
radiobutton control
measurement editbox
dropdown
57
58
InCopy での名前
Text editbox control
Real editbox, integer editbox, measurement editbox,
percent editbox, angle editbox
Drop-down control
Combo-box control
Check-box control
Radio-button control
最初の InCopy ダイアログボックスの作成
InCopy ダイアログボックスは、簡単な手順で作成できます。ダイアログボックスを追加し、ダイアログボッ
クスにダイアログコラムを追加し、ダイアログコラムにコントロールを追加します。次のスクリプトにその
例を示します(完全なスクリプトについては、SimpleDialog を参照してください)。
var myDialog = app.dialogs.add({name:"Simple Dialog"});
//Add a dialog column.
with(myDialog.dialogColumns.add()){
staticTexts.add({staticLabel:"This is a very simple dialog box."});
}
//Show the dialog box.
var myResult = myDialog.show();
//Display a message.
if(myResult == true){
alert("You clicked the OK button.");
}
else{
alert("You clicked the Cancel button.");
}
//Remove the dialog box from memory.
myDialog.destroy();
59
「Hello World」へのユーザーインターフェイスの追加
次の例は、第 2 章「はじめに」で作成した Hello World チュートリアルスクリプトに、簡単なユーザーイン
ターフェイスを追加したものです。ダイアログボックスに表示されるオプションを使用して、表示するテキ
ストを指定したり、テキストのポイントサイズを変更したりすることができます。完全なスクリプトについ
ては、HelloWorldUI を参照してください。
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 = realEditboxes.add({editValue:72});
}
}
//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();
//Create a new document.
var myDocument = app.documents.add()
with(myDocument){
var myStory = myDocument.stories.item(0);
//Enter the text from the dialog box.
myStory.contents=myString;
//Set the size of the text to the size you entered in the dialog box.
myStory.texts.item(0).pointSize = myPointSize;
}
}
else{
//User clicked Cancel, so remove the dialog box from memory.
myDialog.destroy();
}
var myDialog = app.dialogs.add({name:"ComplexUI", canCancel:true});
with(myDialog){
var mySwatchNames = app.swatches.everyItem().name;
//Add a dialog column.
with(dialogColumns.add()){
//Create a border panel.
with(borderPanels.add()){
with(dialogColumns.add()){
with(dialogRows.add()){
//The following line shows how to set a property
//as you create an object.
staticTexts.add({staticLabel:"Message:"});
//The following line shows how to set multiple
//properties as you create an object.
var myTextEditField = textEditboxes.add(
{editContents:"Hello World!", minWidth:180});
}
}
}
//Create another border panel.
with(borderPanels.add()){
with(dialogColumns.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"Point Size:"});
//Create a number entry field. Note that this field uses
//editValue rather than editText (as a textEditBox would).
var myPointSizeField = measurementEditboxes.add({editValue:72,
editUnits:MeasurementUnits.points});
}
}
}
//Create another border panel.
with(borderPanels.add()){
with(dialogColumns.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"Paragraph Alignment:"});
var myRadioButtonGroup = radiobuttonGroups.add();
with(myRadioButtonGroup){
radiobuttonControls.add({staticLabel:"Left",
checkedState:true});
radiobuttonControls.add({staticLabel:"Center"});
radiobuttonControls.add({staticLabel:"Right"});
}
}
}
}
//Create another border panel.
with(borderPanels.add()){
with(dialogColumns.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"Text Color:"});
}
var mySwatchDropdown = dropdowns.add({stringList:mySwatchNames,
selectedIndex:4});
}
}
}
}
//Display the dialog box.
if(myDialog.show() == true){
var myParagraphAlignment, myString, myPointSize, myVerticalJustification;
//If the user didn't click the Cancel button,
//then get the values back from the dialog box.
//Get the example text from the text edit field.
var myString = myTextEditField.editContents
//Get the point size from the point size field.
60
ScriptUI の使用
61
var myPointSize = myPointSizeField.editValue;
//Get the paragraph alignment setting from the radiobutton group.
if(myRadioButtonGroup.selectedButton == 0){
myParagraphAlignment = Justification.leftAlign;
}
else if(myRadioButtonGroup.selectedButton == 1){
myParagraphAlignment = Justification.centerAlign;
}
else{
myParagraphAlignment = Justification.rightAlign;
}
var mySwatchName = mySwatchNames[mySwatchDropdown.selectedIndex];
//Remove the dialog box from memory.
myDialog.destroy();
//Now create the document and apply the properties to the text.
var myDocument = app.documents.add();
with(myDocument.stories.item(0)){
//Set the contents of the story to the string you entered
//in the dialog box.
contents = myString;
//Set the alignment of the paragraph.
texts.item(0).justification = myParagraphAlignment;
//Set the point size of the text.
texts.item(0).pointSize = myPointSize;
//Set the fill color of the text.
texts.item(0).fillColor = myDocument.swatches.item(mySwatchName);
}
}
else{
myDialog.destroy()
}
ScriptUI の使用
62
#targetengine "session"
var myProgressPanel;
var myMaximumValue = 300;
var myProgressBarWidth = 300;
var myIncrement = myMaximumValue/myProgressBarWidth;
myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
function myCreateProgressPanel(myMaximumValue, myProgressBarWidth){
myProgressPanel = new Window('window', 'Progress');
with(myProgressPanel){
myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0,
myMaximumValue);
}
}
前のスクリプトで作成したプログレスバーを別の JavaScript で呼び出す方法を、次のスクリプトに示します
(完全なスクリプトについては、CallProgressBar を参照してください)。
#targetengine "session"
myCreateProgressPanel(20, 400);
myProgressPanel.show();
var myStory = app.documents.item(0).stories.item(0);
for(var myCounter = 0; myCounter < 20; myCounter ++){
//Scale the value change to the maximum value of the progress bar.
myProgressPanel.myProgressBar.value = myCounter/myIncrement;
var myInsertionPoint = myStory.insertionPoints.item(-1);
myInsertionPoint.contents = "This is a paragraph¥r.";
}
myProgressPanel.myProgressBar.value = 0;
myProgressPanel.hide();
ScriptUI の使用
<buttons>
<button>
<buttonType>text</buttonType>
<buttonName>FindChangeByList</buttonName>
<buttonFileName>/c/buttons/FindChangeByList.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
<button>
<buttonType>text</buttonType>
<buttonName>SortParagraphs</buttonName>
<buttonFileName>/c/buttons/SortParagraphs.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
</buttons>
XML ファイルを読み込んでボタンバーをセットアップする関数は、次のとおりです。
#targetengine "session"
var myButtonBar;
main();
function main(){
myButtonBar = myCreateButtonBar();
myButtonBar.show();
}
function myCreateButtonBar(){
var myButtonName, myButtonFileName, myButtonType, myButtonIconFile, myButton;
var myButtons = myReadXMLPreferences();
if(myButtons != ""){
myButtonBar = new Window('window', 'Script Buttons', undefined,
{maximizeButton:false, minimizeButton:false});
with(myButtonBar){
spacing = 0;
margins = [0,0,0,0];
with(add('group')){
spacing = 2;
orientation = 'row';
for(var myCounter = 0; myCounter < myButtons.length(); myCounter++){
myButtonName = myButtons[myCounter].xpath("buttonName");
myButtonType = myButtons[myCounter].xpath("buttonType");
myButtonFileName = myButtons[myCounter].xpath("buttonFileName");
myButtonIconFile = myButtons[myCounter].xpath("buttonIconFile");
if(myButtonType == "text"){
myButton = add('button', undefined, myButtonName);
}
else{
myButton = add('iconbutton', undefined,
File(myButtonIconFile));
}
myButton.scriptFile = myButtonFileName;
myButton.onClick = function(){
myButtonFile = File(this.scriptFile)
app.doScript(myButtonFile);
}
}
}
}
}
63
return myButtonBar;
}
function myReadXMLPreferences(){
myXMLFile = File.openDialog("Choose the file containing your
button bar defaults");
var myResult = myXMLFile.open("r", undefined, undefined);
var myButtons = "";
if(myResult == true){
var myXMLDefaults = myXMLFile.read();
myXMLFile.close();
var myXMLDefaults = new XML(myXMLDefaults);
var myButtons = myXMLDefaults.xpath("/buttons/button");
}
return myButtons;
}
ScriptUI の使用
64
6
メニュー
変更なし
menuElements — メニューに表示されるすべての menuItems、menuSeparators、submenus
ナー
65
66
application
menuActions
menuAction
area
checked
enabled
eventListeners
eventListener
id
eventListener
...
index
label
name
events
event
parent
event
title
...
scriptMenuActions
scriptMenuAction
same as menuAction
表示可能なすべてのメニューアクションのリスト(テキストファイル)を作成するには、次のスクリプトを
実行します(チュートリアルスクリプトの GetMenuActions より)。
var myMenuActionNames = app.menuActions.everyItem().name;
//Open a new text file.
var myTextFile = File.saveDialog("Save Menu Action Names As", undefined);
//If the user clicked the Cancel button, the result is null.
if(myTextFile != null){
//Open the file with write access.
myTextFile.open("w");
for(var myCounter = 0; myCounter < myMenuActionNames.length; myCounter++){
myTextFile.writeln(myMenuActionNames[myCounter]);
}
myTextFile.close();
}
67
var myMenu;
//Open a new text file.
var myTextFile = File.saveDialog("Save Menu Action Names As", undefined);
//If the user clicked the Cancel button, the result is null.
if(myTextFile != null){
//Open the file with write access.
myTextFile.open("w");
for(var myMenuCounter = 0;myMenuCounter< app.menus.length; myMenuCounter++){
myMenu = app.menus.item(myMenuCounter);
myTextFile.writeln(myMenu.name);
myProcessMenu(myMenu, myTextFile);
}
myTextFile.close();
alert("done!");
}
function myProcessMenu(myMenu, myTextFile){
var myMenuElement;
var myIndent = myGetIndent(myMenu);
for(var myCounter = 0; myCounter < myMenu.menuElements.length; myCounter++){
myMenuElement = myMenu.menuElements.item(myCounter);
if(myMenuElement.getElements()[0].constructor.name != "MenuSeparator"){
myTextFile.writeln(myIndent + myMenuElement.name);
if(myMenuElement.getElements()[0].constructor.name == "Submenu"){
if(myMenuElement.menuElements.length > 0){
myProcessMenu(myMenuElement, myTextFile);
}
}
}
}
}
function myGetIndent(myObject){
var myString = "¥t";
var myDone = false;
do{
if((myObject.parent.constructor.name == "Menu")||
(myObject.parent.constructor.name == "Application")){
myDone = true;
}
else{
myString = myString + "¥t";
myObject = myObject.parent;
}
}while(myDone == false)
return myString;
}
68
var myString = "";
var myMenuAction = app.menuActions.item("$ID/Convert to Note");
var myKeyStrings = app.findKeyStrings(myMenuAction.name);
if(myKeyStrings.constructor.name == "Array"){
for(var myCounter = 0; myCounter < myKeyStrings.length; myCounter ++){
myString += myKeyStrings[myCounter] + "¥r";
}
}
else{
myString = myKeyStrings;
}
alert(myString);
69
var myMainMenu = app.menus.item("Main");
var myTypeMenu = myMainMenu.menuElements.item("Type");
var myFontMenu = myTypeMenu.menuElements.item("Font");
var myKozukaMenu = myFontMenu.submenus.item("Kozuka Mincho Pro ");
var mySpecialFontMenu = myMainMenu.submenus.add("Kozuka Mincho Pro");
for(myCounter = 0;myCounter < myKozukaMenu.menuItems.length; myCounter++){
var myAssociatedMenuAction = myKozukaMenu.menuItems.item(myCounter).associatedMenuAction;
mySpecialFontMenu.menuItems.add(myAssociatedMenuAction);
}
このスクリプトで追加したカスタムメニューを削除するには、RemoveSpecialFontMenu スクリプトを実行し
ます。
var myMainMenu = app.menus.item("Main");
var mySpecialFontMenu = myMainMenu.submenus.item("Kozuka Mincho Pro");
mySpecialFontMenu.remove();
イベント
説明
menu
beforeDisplay
menuAction
afterInvoke
beforeInvoke
afterInvoke
beforeInvoke
beforeDisplay
scriptMenuAction
beforeDisplay
70
プトについては、MakeScriptMenuAction を参照してください)。このスクリプトでは、メニュー項目が選択さ
れると、単に警告が表示されます。
var mySampleScriptAction = app.scriptMenuActions.add("Display Message");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", function(){alert("This
menu item was added by a script.");});
//If the submenu "Script Menu Action" does not already exist, create it.
try{
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item(
"Script Menu Action");
mySampleScriptMenu.title;
}
catch (myError){
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add
("Script Menu Action");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);
このスクリプトで作成した menu、submenu、menuItem、scriptMenuAction を削除するには、次のスクリプト
を実行します(チュートリアルスクリプトの RemoveScriptMenuAction より)
。
#targetengine "session"
var mySampleScriptAction = app.scriptMenuActions.item("Display Message");
mySampleScriptAction.remove();
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item
("Script Menu Action");
mySampleScriptMenu.remove();
現在のすべての scriptMenuAction のリストを作成することができます。次のスクリプトにその例を示します
(チュートリアルスクリプトの GetScriptMenuActions より)
。
var myScriptMenuActionNames = app.scriptMenuActions.everyItem().name;
//Open a new text file.
var myTextFile = File.saveDialog("Save Script Menu Action Names As", undefined);
//If the user clicked the Cancel button, the result is null.
if(myTextFile != null){
//Open the file with write access.
myTextFile.open("w");
for(var myCounter = 0; myCounter < myScriptMenuActionNames.length; myCounter++){
myTextFile.writeln(myScriptMenuActionNames[myCounter]);
}
myTextFile.close();
}
scriptMenuAction を使用して、beforeDisplay event の発生時にスクリプトを実行することもできます。こ
の場合は、scriptMenuAction の状態に対する内部要求が行われる前に(メニュー項目が表示される直前に)
スクリプトが実行されます。これは、スクリプトでメニュー名を変更したり、有効/チェックのステータス
を設定したりする場合に特に役立ちます。
71
無効化されます。アイテムが選択されている場合は、メニュー項目が有効化されます。メニュー項目を選択
すると、選択されている最初のアイテムの種類が表示されます (完全なスクリプトについては、
BeforeDisplay を参照してください)。
var mySampleScriptAction = app.scriptMenuActions.add("Display Message");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", myOnInvokeHandler,
false);
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("Script Menu Action");
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);
mySampleScriptMenu.eventListeners.add("beforeDisplay", myBeforeDisplayHandler, false);
//JavaScript function to run before the menu item is drawn.
function myBeforeDisplayHandler(myEvent){
var mySampleScriptAction = app.scriptMenuActions.item("Display Message");
if(app.documents.length > 0){
if(app.selection.length > 0){
mySampleScriptAction.enabled = true;
}
else{
mySampleScriptAction.enabled = false;
}
}
else{
mySampleScriptAction.enabled = false;
}
}
//JavaScript function to run when the menu item is selected.
function myOnInvokeHandler(myEvent){
myString = app.selection[0].constructor.name;
alert("The first item in the selection is a " + myString + ".");
}
7
イベント
変更なし
72
閉じる
書き出し
読み込み
新規
イベント名
説明
beforeDisplay
Event
beforeDisplay
Event
beforeInvoke
Event
afterInvoke
Event
onInvoke
Event
DocumentEvent
afterClose
DocumentEvent
beforeExport
ImportExportEvent
afterExport
ImportExportEvent
beforeImport
ImportExportEvent
afterImport
ImportExportEvent
beforeClose
beforeNew
afterNew
開く
beforeOpen
afterOpen
プリント
beforePrint
afterPrint
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
73
イベント名
復帰
beforeRevert
afterRevert
保存
beforeSave
afterSave
複製を保存
beforeSaveACopy
afterSaveACopy
別名で保存
beforeSaveAs
afterSaveAs
説明
74
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
DocumentEvent
eventListener の操作
75
プロパティ
説明
Bubbles
Cancelable
Captures
CurrentTarget
参照してください。
DefaultPrevented
EventPhase
EventType
PropagationStopped
Target
TimeStamp
event が発生した日時。
eventListener の操作
eventListener を作成するときには、イベントのタイプ(文字列)
、イベントハンドラー(JavaScript 関数ま
たはファイル参照)、イベントのキャプチャフェーズで eventListener を呼び出すかどうかを指定します。特
定のイベントに対して eventListener を追加する方法を、次のスクリプトに示します(完全なスクリプトに
ついては、AddEventListener を参照してください)。
#targetengine "session"
main();
function main(){
var myEventListener = app.addEventListener("afterNew", myDisplayEventType,
false);
}
function myDisplayEventType(myEvent){
alert("This event is the " + myEvent.eventType + " event.");
}
このスクリプトで作成した eventListener を削除するには、次のスクリプトを実行します(チュートリアル
スクリプトの RemoveEventListener より)。
app.removeEventListener("afterNew", myDisplayEventType, false);
eventListener の操作
76
このスクリプトを実行してファイルを配置すると、ドキュメントの名前を示す警告と、アプリケーションの
名前を示す警告が順に表示されます。
次のサンプルスクリプトでは、サポートされている各イベントの eventListener を作成して、簡単なダイア
ログボックスにイベントに関する情報を表示しています。完全なスクリプトについては、EventListenersOn を
参照してください。
main()
function main(){
app.scriptPreferences.version = 5.0;
var myEventNames = [
"beforeQuit", "afterQuit",
"beforeNew", "afterNew",
"beforeOpen", "afterOpen",
"beforeClose", "afterClose",
"beforeSave", "afterSave",
"beforeSaveAs", "afterSaveAs",
"beforeSaveACopy", "afterSaveACopy",
"beforeRevert", "afterRevert",
"beforePrint", "afterPrint",
"beforeExport", "afterExport",
"beforeImport", "afterImport"
] ;
for (var myCounter = 0; myCounter < myEventNames.length; myCounter ++){
app.addEventListener(myEventNames[myCounter], myEventInfo, false);
}
}
function myEventInfo(myEvent){
var myString = "Handling Event: " +myEvent.eventType;
myString += "¥r¥rTarget: " + myEvent.target + " " +myEvent.target.name;
myString += "¥rCurrent: " +myEvent.currentTarget + " "
myStirng += myEvent.currentTarget.name;
myString += "¥r¥rPhase: " + myGetPhaseName(myEvent.eventPhase );
「afterNew」eventListener の例
77
myString += "¥rCaptures: " +myEvent.captures;
myString += "¥rBubbles: " + myEvent.bubbles;
myString += "¥r¥rCancelable: " +myEvent.cancelable;
myString += "¥rStopped: " +myEvent.propagationStopped;
myString += "¥rCanceled: " +myEvent.defaultPrevented;
myString += "¥r¥rTime: " +myEvent.timeStamp;
alert(myString);
function myGetPhaseName(myPhase){
switch(myPhase){
case EventPhases.atTarget:
myPhaseName = "At Target";
break;
case EventPhases.bubblingPhase:
myPhaseName = "Bubbling";
break;
case EventPhases.capturingPhase:
myPhaseName = "Capturing";
break;
case EventPhases.done:
myPhaseName = "Done";
break;
case EventPhases.notDispatching:
myPhaseName = "Not Dispatching";
break;
}
return myPhaseName;
}
}
アプリケーションオブジェクトのすべての eventListener をオフにする方法を、次のサンプルスクリプトに
示します。完全なスクリプトについては、EventListenersOff を参照してください。
//EventListenersOff.jsx
//An InCopy CS6 JavaScript
#targetengine "session"
app.eventListeners.everyItem().remove();
「afterNew」eventListener の例
#targetengine "session"
//Creates an event listener that will run after a new document is created.
main();
function main(){
var myEventListener = app.eventListeners.add("afterNew",
myAfterNewHandler, false);
}
function myAfterNewHandler(myEvent){
var myDocument = myEvent.parent;
main(myDocument);
function main(myDocument){
app.userName = "Adobe";
myAddXMPData(myDocument);
}
function myAddXMPData(myDocument){
with(myDocument.metadataPreferences){
author = "Adobe Systems";
description = "This is a sample document with XMP metadata. Created:"
+ myEvent.timeStamp + "¥rby: " + app.userName;
}
}
}
78
8
注釈
変更なし
ストーリーへの注釈の追加
ストーリーに注釈を追加するには、add メソッドを使用します。次のサンプルでは、最後の挿入点に注釈を追
加しています。完全なスクリプトについては、InsertNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Add note to a default story. We'll use the last insertion point in the story.
var myNote = myStory.insertionPoints.item(-1).notes.add();
//Add text to the note
myNote.texts.item(0).contents = "This is a note."
注釈のテキストの置換
注釈のテキストを置換するには、contents プロパティを使用します。次のサンプルにその例を示します。完
全なスクリプトについては、Replace を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
var myNote = myStory.notes.item(0);
//Replace text of note with "This is a replaced note."
myNote.texts.item(0).contents = "This is a replaced note."
79
第 8 章 注釈
80
注釈からテキストへの変換およびテキストから注釈への変換
注釈からテキストへの変換
注釈をテキストに変換するには、convertToText メソッドを使用します。次のサンプルにその例を示します。
完全なスクリプトについては、ConvertToText を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Convert the note to text
myStory.notes.item(0).convertToText();
テキストから注釈への変換
テキストを注釈に変換するには、convertToNote メソッドを使用します。次のサンプルにその例を示します。
完全なスクリプトについては、ConvertToNote を参照してください。
var myDocument = app.documents.item(0);
myStory = myDocument.stories.item(0);
//Convert text to note
myStory.words.item(0).convertToNote();
注釈の展開と折りたたみ
注釈の折りたたみ
注釈を折りたたむ方法を、次のスクリプトに示します。完全なスクリプトについては、CollapseNote を参照し
てください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
var myNote = myStory.notes.item(0);
//Collapse a note
myNote.collapsed = true;
注釈の展開
注釈を展開する方法を、次のスクリプトに示します。完全なスクリプトについては、ExpandNote を参照して
ください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
var myNote = myStory.notes.item(0);
//Expand a note
myNote.collapsed = false;
注釈の削除
注釈を削除するには、remove メソッドを使用します。次のサンプルにその例を示します。完全なスクリプト
については、RemoveNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Remove the note
myStory.notes.item(0).remove(myStory.notes.item(0));
第 8 章 注釈
注釈間の移動
81
注釈間の移動
ストーリー内の最初の注釈への移動
ストーリー内の最初の注釈に移動する方法を、次のスクリプトに示します。完全なスクリプトについては、
FirstNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Get next note
var myNote = myStory.notes.firstItem();
//Add text to the note
myNote.texts.item(0).contents = "This is the first note."
ストーリー内の次の注釈への移動
ストーリー内の次の注釈に移動する方法を、次のスクリプトに示します。完全なスクリプトについては、
NextNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Get next note
var myNote = myStory.notes.nextItem(myStory.notes.item(0));
text to the note
myNote.texts.item(0).contents = "This is the next note."
ストーリー内の前の注釈への移動
ストーリー内の前の注釈に移動する方法を、次のスクリプトに示します。完全なスクリプトについては、
PreviousNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Get previous note
var myNote = myStory.notes.previousItem(myStory.notes.item(1));
//Add text to the note
myNote.texts.item(0).contents = "This is the prev note."
ストーリー内の最後の注釈への移動
ストーリー内の最後の注釈に移動する方法を、次のスクリプトに示します。完全なスクリプトについては、
LastNote を参照してください。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Get next note
var myNote = myStory.notes.lastItem();
//Add text to the note
myNote.texts.item(0).contents = "This is the last note."
9
変更なし
トラックされた変更への移動
トラックされた変更の記録がストーリーに含まれている場合、ユーザーはトラックされた変更に順次移動す
ることができます。トラックされた変更に移動する方法を、次のスクリプトに示します。
次のスクリプトでは、nextItem メソッドを使用して、挿入点の後の変更に移動します。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Story.trackChanges
If true, track changes is turned on.
if(myStory.trackChanges==true )
{
var myChangeCount =myStory.changes.length;
var myChange = myStory.changes.item(0);
if(myChangeCount>1)
{
var myChange0 = myStory.changes.nextItem(myChange);
}
}
82
83
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
//Story.trackChanges
If true, track changes is turned on.
if(myStory.trackChanges==true )
{
var myChangeCount =myStory.changes.length;
var myChange = myStory.changes.lastItem();
if(myChangeCount>1)
{
var myChange0 = myStory.changes.previousItem(myChange);
}
}
次のスクリプトでは、変更を取り消します。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
var myChange = myStory.changes.item(0);
myChange.reject() ;
トラックされた変更に関する情報
変更の情報には日付や時間などが含まれています。次のスクリプトでは、トラックされた変更の情報を表示
します。
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
var myChange = myStory.changes.item(0);
//ChangeTypes.DELETED_TEXT (Read Only) Deleted text.
//ChangeTypes.DELETED_TEXT (Read Only) Deleted text.
//ChangeTypes.MOVED_TEXT (Read Only) Moved text.
var myChangeTypes = myChange.changeType;
//Characters A collection of characters.
var myCharacters = myChange.characters;
//Character = myCharacters.item(0);
var myDate = myChange.date;
//InsertionPoints A collection of insertion points.
// insertpoint = myInsertionPoints.item(0);
var myInsertionPoints = myChange.insertionPoints;
//Change.lines (Read Only) A collection of lines.
var myLines = myChange.lines;
84
//Change.paragraphs (Read Only) A collection of paragraphs.
var myParagraphs =myChange.paragraphs;
//InsertionPoints A collection of insertion points.
// insertpoint = myInsertionPoints.item(0);
var myStoryOffset = myChange.storyOffset;
//Change.textColumns (Read Only) A collection of text columns.
var myTextColumns = myChange.textColumns;
//Change.textStyleRanges (Read Only) A collection of text style ranges.
var myTextStyleRanges = myChange.textStyleRanges;
//Change.textVariableInstances (Read Only) A collection of text variable instances.
var myTextVariableInstances = myChange.textVariableInstances;
//Change.texts (Read Only) A collection of text objects.
var myTexts = myChange.texts;
var myUserName = myChange.userName;
var myWords = myChange.words;
変更のトラックの環境設定
変更のトラックの環境設定とは、変更のトラックに関するユーザー設定です。例えば、トラックされる変更
の種類(テキストの追加や削除、移動)を定義できます。トラックされた変更の種類別の外観を指定したり、
マージンの色付きの変更バーで変更を識別したりできます。これらの環境設定を設定して取得する方法を、
次のスクリプトに示します。
var myTrackChangesPreference = app.trackChangesPreferences ;
with(myTrackChangesPreference)
{addedBackgroundColorChoice =
ChangeBackgroundColorChoices.CHANGE_BACKGROUND_USES_CHANGE_PREF_COLOR;
addedTextColorChoice = ChangeTextColorChoices.CHANGE_USES_CHANGE_PREF_COLOR ;
backgroundColorForAddedText = UIColors.gray;
var myColor = backgroundColorForDeletedText;
backgroundColorForDeletedText = UIColors.red;
backgroundColorForMovedText = UIColors.pink;
changeBarColor = UIColors.charcoal;
deletedBackgroundColorChoice
=ChangeBackgroundColorChoices.CHANGE_BACKGROUND_USES_CHANGE_PREF_COLOR;
deletedTextColorChoice =ChangeTextColorChoices.CHANGE_USES_CHANGE_PREF_COLOR ;
//ChangebarLocations.LEFT_ALIGN (Read Only) Change bars are in the left margin.
//ChangebarLocations.RIGHT_ALIGN (Read Only) Change bars are in the right margin
locationForChangeBar = ChangebarLocations.LEFT_ALIGN;
//ChangeMarkings.OUTLINE (Read Only)
Outlines changed text.
//ChangeMarkings.NONE (Read Only) Does not mark changed text.
//ChangeMarkings.STRIKETHROUGH (Read Only) Uses a strikethrough to mark changed text.
//ChangeMarkings.UNDERLINE_SINGLE (Read Only) Underlines changed text.
markingForAddedText =ChangeMarkings.OUTLINE;
markingForDeletedText = ChangeMarkings.STRIKETHROUGH;
markingForMovedText = ChangeMarkings.UNDERLINE_SINGLE;
movedBackgroundColorChoice
=ChangeBackgroundColorChoices.CHANGE_BACKGROUND_USES_CHANGE_PREF_COLOR;
movedTextColorChoice = ChangeTextColorChoices.CHANGE_USES_CHANGE_PREF_COLOR ;
showAddedText = true;
shhowDeletedText =true;
showMovedText = true;
spellCheckDeletedtext = true;
showChangeBar = true;
textColorForAddedText=UIColors.blue;
textColorForDeletedText=UIColors.yellow;
textColorForMovedText=UIColors.green;
}
10
アサイン
変更なし
アサインファイルを開く
既存のアサインファイルを開く方法を、次のスクリプトに示します。
//Open an exist assignment file
var myDocument = app.open(File("/c/a.icma"));
var myAssignement = myDocument.assignments.item(0);
アサインのプロパティに対する繰り返し処理
アサインのプロパティ(アサイン名、ユーザー名、アサインファイルの場所、アサインの書き出しオプショ
ンなど)を取得する方法を、次のスクリプトに示します。
var myName = myAssignement.name;
var myUserName = myAssignement.userName;
var myDocument = app.documents.item(0);
var myAssignement = myDocument.assignments.item(0);
var myFilePath = myAssignement.filePath;
var myFramecolor = myAssignement.frameColor;
// exportOptions property can be:
// AssignmentExportOptions.ASSIGNED_SPREADS
// AssignmentExportOptions.EMPTY_FRAMES
// AssignmentExportOptions.EVERYTHING
var myExportOptions = myAssignement.exportOptions;
85
86
var myDocument = app.documents.item(0);
var myAssignement = myDocument.assignments.item(0);
if(myAssignement.packaged==false)
{
var myFile= new File("/c/b.icap");
// PackageType.FORWARD_PACKAGE Creates an assignment package for export.
// PackageType.RETURN_PACKAGE Create a package to place in the main document.
myAssignement.createPackage(myFile,PackageType.FORWARD_PACKAGE);
}
document
1
1…*
assignment
1
0…*
assigned story
1
1
text/image story
アサインされたストーリーオブジェクト
アサインオブジェクトから、アサインされたストーリーを取得する方法を、次のスクリプトに示します。
var myDocument = app.documents.item(0);
var myAssignement = myDocument.assignments.item(0);
var myAssignmentStory = myAssignement.assignedStories.item(0);
アサインされたストーリーのプロパティに対する繰り返し処理
InCopy では、アサインされたストーリーオブジェクトにプロパティがあります。アサインされたストーリー
オブジェクトのすべてのプロパティを取得する方法を、次のスクリプトに示します。
var myDocument = app.documents.item(0);
var myAssignement = myDocument.assignments.item(0);
var myAssignmentStory = myAssignement.assignedStories.item(0);
if(myAssignmentStory != null)
{
var myName = myAssignmentStory.name;
var myIsvalid = myAssignmentStory.isValid;
var myFilePath = myAssignmentStory.filePath;
var myStoryReference = myAssignmentStory.storyReference;
}
11
XML
変更なし
87
第 11 章 XML
88
XML 環境設定の指定
XML ビュー環境設定オブジェクトを使用して、InCopy の構造パネルの外観を制御できます。次のスクリプト
にその例を示します(チュートリアルスクリプトの XMLViewPreferences より)。
var myDocument = app.documents.add();
var myXMLViewPreferences = myDocument.xmlViewPreferences;
myXMLViewPreferences.showAttributes = true;
myXMLViewPreferences.showStructure = true;
myXMLViewPreferences.showTaggedFrames = true;
myXMLViewPreferences.showTagMarkers = true;
myXMLViewPreferences.showTextSnippets = true;
また、XML 環境設定オブジェクトを使用して、XML タグ付きプリセット環境設定(表やストーリーのデフォ
ルトのタグ名やユーザーインターフェイスカラー)を指定することもできます。次のスクリプトにその例を
示します(チュートリアルスクリプトの XMLPreferences より)
。
var myDocument = app.documents.add();
var myXMLPreferences = myDocument.xmlPreferences;
myXMLPreferences.defaultCellTagColor = UIColors.blue;
myXMLPreferences.defaultCellTagName = "cell";
myXMLPreferences.defaultImageTagColor = UIColors.brickRed;
myXMLPreferences.defaultImageTagName = "image";
myXMLPreferences.defaultStoryTagColor = UIColors.charcoal;
myXMLPreferences.defaultStoryTagName = "text";
myXMLPreferences.defaultTableTagColor = UIColors.cuteTeal;
myXMLPreferences.defaultTableTagName = "table";
XML 読み込み環境設定の指定
XML ファイルを読み込む前に、XML 読み込み環境設定を指定することができます。この環境設定を使用すれ
ば、XSLT 変換を適用したり、XML ファイル内の空白文字の処理方法を制御したり、繰り返すテキスト要素を
作成したりすることができます。XML 読み込み環境設定オブジェクトの設定方法を、次のスクリプトに示し
ます(チュートリアルスクリプトの XMLImportPreferences より)
。
var myDocument = app.documents.add();
var myXMLImportPreferences = myDocument.xmlImportPreferences;
myXMLImportPreferences.allowTransform = false;
myXMLImportPreferences.createLinkToXML = false;
myXMLImportPreferences.ignoreUnmatchedIncoming = true;
myXMLImportPreferences.ignoreWhitespace = true;
myXMLImportPreferences.importCALSTables = true;
myXMLImportPreferences.importStyle = XMLImportStyles.mergeImport;
myXMLImportPreferences.importTextIntoTables = false;
myXMLImportPreferences.importToSelected = false;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.repeatTextElements = true;
//The following properties are only used when the
//AllowTransform property is set to True.
//myXMLImportPreferences.transformFilename = "c:¥myTransform.xsl"
//If you have defined parameters in your XSL file, then you can pass
//parameters to the file during the XML import process. For each parameter,
//enter an array containing two strings. The first string is the name of the
//parameter, the second is the value of the parameter.
//myXMLImportPreferences.transformParameters = [["format", "1"]];
第 11 章 XML
89
XML ファイルの内容を特定の XML 要素に読み込む必要がある場合は、ドキュメントではなく XML 要素の
importXML メソッドを使用します。次のスクリプトにその例を示します(チュートリアルスクリプトの
ImportXMLIntoElement より)。
var myXMLTag = myDocument.xmlTags.add("xml_element");
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.add(myXMLTag);
//Import into the new XML element.
myXMLElement.importXML(File("/c/completeDocument.xml"));
または、xmlImportPreferences オブジェクトの importToSelected プロパティを true に設定し、XML 要素を
選択した状態で XML ファイルを読み込む方法もあります。次のスクリプトにその例を示します(チュートリ
アルスクリプトの ImportXMLIntoSelectedXMLElement より)
。
var myXMLTag = myDocument.xmlTags.add("xml_element");
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.add(myXMLTag);
myDocument.select(myXMLElement);
myDocument.xmlImportPreferences.importToSelected = true;
//Import into the selected XML element.
myDocument.importXML(File("/c/test.xml"));
XML タグの作成
XML タグとは、ドキュメント内で使用する XML 要素の名前のことです。XML を読み込むと、XML ファイル内
の要素名が、ドキュメントの XML タグのリストに追加されます。また、XML タグを直接作成することもでき
ます。次のスクリプトにその例を示します(チュートリアルスクリプトの MakeXMLTags より)
。
//You can create an XML tag without specifying a color for the tag.
var myXMLTagA = myDocument.xmlTags.add("XML_tag_A");
//You can define the highlight color of the XML tag using the UIColors enumeration...
var myXMLTagB = myDocument.xmlTags.add("XML_tag_B", UIColors.gray);
//...or you can provide an RGB array to set the color of the tag.
var myXMLTagC = myDocument.xmlTags.add("XML_tag_C", [0, 92, 128]);
第 11 章 XML
90
XML 要素の作成
通常、XML 要素は XML ファイルを読み込んで作成しますが、InCopy スクリプティングを使用して XML 要素
を作成することもできます。次のスクリプトにその例を示します(チュートリアルスクリプトの
CreateXMLElement より)。
var myXMLTag = myDocument.xmlTags.add("myXMLTag");
var myRootElement = myDocument.xmlElements.item(0);
var myXMLElment = myRootElement.xmlElements.add(myXMLTag);
myXMLElement.contnets = "This is an XML element containing text."
XML 要素の移動
move メソッドを使用して、XML 構造内の XML 要素を移動できます。次のスクリプトにその例を示します
(チュートリアルスクリプトの MoveXMLElement より)
。
var myDocument = app.documents.add();
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLTag = myDocument.xmlTags.add("xml_element");
var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementA.contents = "A";
var myXMLElementB = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementB.contents = "B";
var myXMLElementC = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementC.contents = "C";
var myXMLElementD = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementD.contents = "D";
//Move the XML element containing "A" to after
//the XML element containing "C"
myXMLElementA.move(LocationOptions.after, myRootXMLElement.xmlElements.item(2));
//Move the XML element containing "D" to the beginning of its parent.
myRootXMLElement.xmlElements.item(-1).move(LocationOptions.atBeginning);
//Place the XML structure so that you can see the result.
myDocument.stories.item(0).placeXML(myRootXMLElement);
XML 要素の複製
XML 要素を複製すると、新しい XML 要素が、XML 構造内の元の XML 要素の直後に追加されます。次のスク
リプトにその例を示します(チュートリアルスクリプトの DuplicateXMLElement より)
。
var myDocument = app.documents.item(0);
var myRootXMLElement = myDocument.xmlElements.item(0);
//Duplicate the XML element containing "A"
var myNewXMLElement = myRootXMLElement.xmlElements.item(0).duplicate();
//Change the content of the duplicated XML element.
myNewXMLElement.contents = myNewXMLElement.contents + " duplicate";
第 11 章 XML
91
XML 処理命令を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
MakeProcessingInstruction を参照してください)。
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLProcessingInstruction = myRootXMLElement.xmlInstructions.add("xml-stylesheet
type=¥"text/css¥" ", "href=¥"generic.css¥"");
第 11 章 XML
92
新しい XML 要素に XML マークアップタグを指定することもできます。このパラメーターを省略すると、その
XML 属性が含まれている XML 要素と同じ XML タグを使用して新しい XML 要素が作成されます。
XML 要素を XML 属性に変換する方法を、次のスクリプトに示します(完全なスクリプトについては、
ConvertElementToAttribute というチュートリアルスクリプトを参照してください)。
var myDocument = app.documents.add();
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLTag = myDocument.xmlTags.add("myXMLElement");
var myXMLElement = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElement.contents = "This is content in an XML element.";
myXMLElement.convertToAttribute();
//Place the XML content so that you can see the result of the change.
var myStory = myDocument.stories.item(0);
myStory.placeXML(myRootXMLElement);
XML 属性を XML 要素に変換することもできます。次のスクリプトにその例を示します(チュートリアルスク
リプトの ConvertAttributeToElement より)。
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLElementB = myRootXMLElement.xmlElements.item(1);
//The "at" parameter can be either LocationOptions.atEnd or LocationOptions.atBeginning, but
cannot
//be LocationOptions.after or LocationOptions.before.
myXMLElementB.xmlAttributes.item(0).convertToElement(XMLElementLocation.elementEnd,
myDocument.xmlTags.item("myXMLElement"));
XML ストーリーの操作
レイアウト要素(ストーリーまたはページアイテム)に関連付けられていない XML 要素を読み込むと、その
要素は XML ストーリーに格納されます。テキストフレーム内のテキストと同じように、配置されていない
XML 要素内のテキストを操作することができます。次のスクリプトにその例を示します(完全なスクリプト
については、XMLStory を参照してください)。
var myXMLStory = myDocument.xmlStories.item(0);
//Though the text has not yet been placed in the layout, all text
//properties are available.
myXMLStory.texts.item(0).pointSize = 72;
//Place the XML element in the layout to see the result.
myDocument.xmlElements.item(0).xmlElements.item(0).placeXML(myDocument.pages.item(0).textFrames.
item(0));
第 11 章 XML
93
既存のテキストオブジェクトに既存の XML 要素を関連付けるには、markup メソッドを使用します。このメ
ソッドを使用すると、テキストオブジェクトの内容と XML 要素の内容(存在する場合)が結合されます。
markup メソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについては、Markup を
参照してください)。
var myDocument = app.documents.add();
var myRootXMLElement = myDocument.xmlElements.item(0);
var myStory = myDocument.stories.item(0);
myStory.placeXML(myRootXMLElement);
myString = "This is the first paragraph in the story.¥r";
myString += "This is the second paragraph in the story.¥r";
myString += "This is the third paragraph in the story.¥r";
myString += "This is the fourth paragraph in the story.¥r";
myStory.contents = myString;
var myXMLTag = myDocument.xmlTags.add("myXMLlement");
var myXMLElement = myRootXMLElement.xmlElements.add(myXMLTag);
myStory.paragraphs.item(2).markup(myXMLElement);
XML テキスト要素の内部や周囲へのテキストの挿入
XML データを InCopy ストーリーに配置する際に、空白文字(改行やタブ文字など)や静的テキスト(「名前」
や「住所」などのラベル)を XML 要素のテキストに追加したいことがあります。XML 要素の内部や周囲にテ
キストを追加する方法を、次のサンプルスクリプトに示します(完全なスクリプトについては、
InsertTextAsContent を参照してください)。
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(0);
//By inserting the return character after the XML element, the character
//becomes part of the content of the parent XML element, not of the element itself.
myXMLElement.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(1);
myXMLElement.insertTextAsContent("Static text: ", XMLElementPosition.beforeElement);
myXMLElement.insertTextAsContent("¥r", XMLElementPosition.afterElement);
//To add text inside the element, set the location option to beginning or end.
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(2);
myXMLElement.insertTextAsContent("Text at the start of the element: ",
XMLElementPosition.elementStart);
myXMLElement.insertTextAsContent(" Text at the end of the element.",
XMLElementPosition.elementEnd);
myXMLElement.insertTextAsContent("¥r", XMLElementPosition.afterElement);
//Add static text outside the element.
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(3);
myXMLElement.insertTextAsContent("Text before the element: ", XMLElementPosition.beforeElement);
myXMLElement.insertTextAsContent(" Text after the element.", XMLElementPosition.afterElement);
//To insert text inside the text of an element, work with the text
//objects contained by the element.
myXMLElement.words.item(2).insertionPoints.item(0).contents = "(the third word of) ";
第 11 章 XML
94
var myDocument = app.documents.item(0);
//Create a tag to style mapping.
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("heading_1"),
myDocument.paragraphStyles.item("heading 1"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("heading_2"),
myDocument.paragraphStyles.item("heading 2"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("para_1"),
myDocument.paragraphStyles.item("para 1"));
myDocument.xmlImportMaps.add(myDocument.xmlTags.item("body_text"),
myDocument.paragraphStyles.item("body text"));
//Apply the tag to style mapping.
myDocument.mapXMLTagsToStyles();
//Place the XML element in the layout to see the result.
myDocument.stories.item(0).placeXML(myDocument.xmlElements.item(0));
タグへのスタイルのマッピング
XML 要素が関連付けられていないフォーマットされたテキストを XML 構造に移動したい場合は、スタイルを
タグにマッピングします。これによって、段落スタイルや文字スタイルを XML タグに関連付けることができ
ます。これを行うには、xmlExportMaps オブジェクトを使用して、XML タグとスタイルの間にリンクを作成
し、mapStylesToTags メソッドを使用して該当する XML 要素を作成します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの MapStylesToTags より)。
var myDocument = app.documents.item(0);
//Create a style to tag mapping.
myDocument.xmlExportMaps.add(myDocument.paragraphStyles.item("heading 1"),
myDocument.xmlTags.item("heading_1"));
myDocument.xmlExportMaps.add(myDocument.paragraphStyles.item("heading 2"),
myDocument.xmlTags.item("heading_2"));
myDocument.xmlExportMaps.add(myDocument.paragraphStyles.item("para 1"),
myDocument.xmlTags.item("para_1"));
myDocument.xmlExportMaps.add(myDocument.paragraphStyles.item("body text"),
myDocument.xmlTags.item("body_text"));
//Apply the style to tag mapping.
myDocument.mapStylesToXMLTags();
別の方法としては、単純に、ドキュメント内のすべての段落スタイルや文字スタイルに対して新しい XML タ
グを作成して、スタイルをタグにマッピングする方法があります。次のスクリプトにその例を示します
(チュートリアルスクリプトの MapAllStylesToTags より)
。
var myDocument = app.documents.item(0);
//Create tags that match the style names in the document,
//creating an XMLExportMap for each tag/style pair.
for(var myCounter = 0; myCounter<myDocument.paragraphStyles.length; myCounter++){
var myParagraphStyle = myDocument.paragraphStyles.item(myCounter);
var myParagraphStyleName = myParagraphStyle.name;
var myXMLTagName = myParagraphStyleName.replace(/¥ /gi, "_")
myXMLTagName = myXMLTagName.replace(/¥[/gi, "")
myXMLTagName = myXMLTagName.replace(/¥]/gi, "")
var myXMLTag = myDocument.xmlTags.add(myXMLTagName);
myDocument.xmlExportMaps.add(myParagraphStyle, myXMLTag);
}
//Apply the tag to style mapping.
myDocument.mapStylesToXMLTags();
第 11 章 XML
var myDocument = app.documents.add();
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
//Create a series of XML tags.
var myHeading1XMLTag = myDocument.xmlTags.add("heading_1");
var myHeading2XMLTag = myDocument.xmlTags.add("heading_2");
var myPara1XMLTag = myDocument.xmlTags.add("para_1");
var myBodyTextXMLTag = myDocument.xmlTags.add("body_text");
//Create a series of paragraph styles.
var myHeading1Style = myDocument.paragraphStyles.add();
myHeading1Style.name = "heading 1";
myHeading1Style.pointSize = 24;
var myHeading2Style = myDocument.paragraphStyles.add();
myHeading2Style.name = "heading 2";
myHeading2Style.pointSize = 14;
myHeading2Style.spaceBefore = 12;
var myPara1Style = myDocument.paragraphStyles.add();
myPara1Style.name = "para 1";
myPara1Style.pointSize = 12;
myPara1Style.firstLineIndent = 0;
var myBodyTextStyle = myDocument.paragraphStyles.add();
myBodyTextStyle.name = "body text";
myBodyTextStyle.pointSize = 12;
myBodyTextStyle.firstLineIndent = 24;
//Create a character style.
var myCharacterStyle = myDocument.characterStyles.add();
myCharacterStyle.name = "Emphasis";
myCharacterStyle.fontStyle = "Italic";
//Add XML elements and apply paragraph styles.
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLElementA = myRootXMLElement.xmlElements.add(myHeading1XMLTag);
myXMLElementA.contents = "Heading 1";
myXMLElementA.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementA.applyParagraphStyle(myHeading1Style, true);
var myXMLElementB = myRootXMLElement.xmlElements.add(myPara1XMLTag);
myXMLElementB.contents = "This is the first paragraph in the article.";
myXMLElementB.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementB.applyParagraphStyle(myPara1Style, true);
var myXMLElementC = myRootXMLElement.xmlElements.add(myBodyTextXMLTag);
myXMLElementC.contents = "This is the second paragraph in the article.";
myXMLElementC.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementC.applyParagraphStyle(myBodyTextStyle, true);
var myXMLElementD = myRootXMLElement.xmlElements.add(myHeading2XMLTag);
myXMLElementD.contents = "Heading 2";
myXMLElementD.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementD.applyParagraphStyle(myHeading2Style, true);
var myXMLElementE = myRootXMLElement.xmlElements.add(myPara1XMLTag);
myXMLElementE.contents = "This is the first paragraph following the subhead.";
myXMLElementE.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementE.applyParagraphStyle(myPara1Style, true);
var myXMLElementF = myRootXMLElement.xmlElements.add(myBodyTextXMLTag);
myXMLElementF.contents = "This is the second paragraph following the subhead.";
myXMLElementF.insertTextAsContent("¥r", XMLElementPosition.afterElement);
myXMLElementF.applyParagraphStyle(myBodyTextStyle, true);
var myXMLElementG = myRootXMLElement.xmlElements.add(myBodyTextXMLTag);
myXMLElementG.contents = "Note:";
myXMLElementG = myXMLElementG.move(LocationOptions.atBeginning, myXMLElementF)
myXMLElementG.insertTextAsContent(" ", XMLElementPosition.afterElement);
myXMLElementG.applyCharacterStyle(myCharacterStyle, true);
// Associate the root XML element with the story.
myDocument.stories.item(0).placeXML(myRootXMLElement);
95
第 11 章 XML
96
XML 表の操作
HTML 標準の表タグでデータがマークアップされている場合、InCopy はその XML データを自動的に表セルに
読み込みます。デフォルトの表マークアップを使用できないか、使用を避けたい場合は、
convertElementToTable メソッドを使用して XML 要素を表に変換できます。
このメソッドを使用するには、表に変換する XML 要素が特定の構造になっている必要があります。表の各行
が特定の XML 要素に対応しており、その要素の中に、行内の各セルに対応する一連の XML 要素が含まれてい
る必要があります。このメソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについ
ては、ConvertXMLElementToTable を参照してください)。テーブル行を表すために使用されている XML 要素
は、このプロセスによって変換されます。
var myDocument = app.documents.add();
//Create a series of XML tags.
var myRowTag = myDocument.xmlTags.add("row");
var myCellTag = myDocument.xmlTags.add("cell");
var myTableTag = myDocument.xmlTags.add("table");
//Add XML elements.
var myRootXMLElement = myDocument.xmlElements.item(0);
with(myRootXMLElement){
var myTableXMLElement = xmlElements.add(myTableTag);
with(myTableXMLElement){
for(var myRowCounter = 1;myRowCounter < 7;myRowCounter++){
with(xmlElements.add(myRowTag)){
myString = "Row " + myRowCounter;
for(var myCellCounter = 1; myCellCounter < 5; myCellCounter++){
with(xmlElements.add(myCellTag)){
contents = myString + ":Cell " + myCellCounter;
}
}
}
}
}
}
var myTable = myTableXMLElement.convertElementToTable(myRowTag, myCellTag);
var myStory = myDocument.stories.item(0);
myStory.placeXML(myDocument.xmlElements.item(0));
XML 要素で構成されている表では、XML 要素に関連付けられている表やセルにスタイルを適用するのではな
く、XML 要素に表スタイルやセルスタイルを直接適用することができます。これを行うには、
applyTableStyle メソッドや applyCellStyle メソッドを使用します。次のスクリプトにその例を示します
(チュートリアルスクリプトの ApplyTableStyle より)
。
var myDocument = app.documents.add();
//Create a series of XML tags.
var myRowTag = myDocument.xmlTags.add("row");
var myCellTag = myDocument.xmlTags.add("cell");
var myTableTag = myDocument.xmlTags.add("table");
//Create a table style and a cell style.
var myTableStyle = myDocument.tableStyles.add({name:"myTableStyle"});
myTableStyle.startRowFillColor = myDocument.colors.item("Black");
myTableStyle.startRowFillTint = 25;
myTableStyle.endRowFillColor = myDocument.colors.item("Black");
myTableStyle.endRowFillTint = 10;
var myCellStyle = myDocument.cellStyles.add();
myCellStyle.fillColor = myDocument.colors.item("Black");
myCellStyle.fillTint = 45
//Add XML elements.
var myRootXMLElement = myDocument.xmlElements.item(0);
with(myRootXMLElement){
var myTableXMLElement = xmlElements.add(myTableTag);
with(myTableXMLElement){
for(var myRowCounter = 1;myRowCounter < 7;myRowCounter++){
with(xmlElements.add(myRowTag)){
第 11 章 XML
myString = "Row " + myRowCounter;
for(var myCellCounter = 1; myCellCounter < 5; myCellCounter++){
with(xmlElements.add(myCellTag)){
contents = myString + ":Cell " + myCellCounter;
}
}
}
}
}
}
var myTable = myTableXMLElement.convertElementToTable(myRowTag, myCellTag);
var myTableXMLElement = myDocument.xmlElements.item(0).xmlElements.item(0);
myTableXMLElement.applyTableStyle(myTableStyle);
myTableXMLElement.xmlElements.item(0).applyCellStyle(myCellStyle);
myTableXMLElement.xmlElements.item(5).applyCellStyle(myCellStyle);
myTableXMLElement.xmlElements.item(10).applyCellStyle(myCellStyle);
myTableXMLElement.xmlElements.item(15).applyCellStyle(myCellStyle);
myTableXMLElement.xmlElements.item(16).applyCellStyle(myCellStyle);
myTableXMLElement.xmlElements.item(21).applyCellStyle(myCellStyle);
myDocument.stories.item(0).placeXML(myDocument.xmlElements.item(0));
myTable.alternatingFills = AlternatingFillsTypes.alternatingRows;
97">
/
Pakua
Kikumbusho tu cha kirafiki. Unaweza kuona hati hapa hapa. Lakini muhimu zaidi, AI yetu tayari imesoma. Inaweza kuelezea mambo magumu kwa maneno rahisi, kujibu maswali yako katika lugha yoyote, na kukusaidia kuvinjari haraka hata hati ndefu au ngumu zaidi.
Tangazo