单词
app.activeDocument.textFrames[index].words
文本项中的单词集合,其中每个单词是一个 TextRange 对象。
元素没有名称;必须通过索引访问它们。
Words.length
Section titled “Words.length”app.activeDocument.textFrames[index].words.length
集合中对象的数量
数字;只读。
Words.parent
Section titled “Words.parent”app.activeDocument.textFrames[index].words.parent
此对象的父对象。
对象;只读。
Words.typename
Section titled “Words.typename”app.activeDocument.textFrames[index].words.typename
引用对象的类名。
字符串;只读。
Words.add()
Section titled “Words.add()”app.activeDocument.textFrames[index].words.add(contents[, relativeObject][, inseertLocation])
在指定位置向当前文档添加一个单词。
如果未指定位置,则将其添加到包含文本框架中当前单词选择或插入点之后。
参数 | 类型 | 描述 |
---|---|---|
contents | 字符串 | 要添加的单词 |
relativeObject | TextFrameItem,可选 | 要添加项的对象 |
insertionLocation | ElementPlacement,可选 | 插入文本的位置 |
Words.addBefore()
Section titled “Words.addBefore()”app.activeDocument.textFrames[index].words.addBefore(contents)
在当前单词选择或插入点之前添加一个单词。
参数 | 类型 | 描述 |
---|---|---|
contents | 字符串 | 要添加的单词 |
Words.index()
Section titled “Words.index()”app.activeDocument.textFrames[index].words.index(itemKey)
从集合中获取一个元素。
参数 | 类型 | 描述 |
---|---|---|
itemKey | 字符串, 数字 | 字符串或数字键 |
Words.removeAll()
Section titled “Words.removeAll()”app.activeDocument.textFrames[index].words.removeAll()
删除此集合中的所有元素。
无。
统计单词数量
Section titled “统计单词数量”// 统计当前文档中的所有单词并将总数存储在 numWords 中if ( app.documents.length > 0 ) { var numWords = 0;
for ( i = 0; i < app.activeDocument.textFrames.length; i++) { numWords += app.activeDocument.textFrames[i].words.length; }}
对单词应用属性
Section titled “对单词应用属性”// 创建一个新的洋红色并将其应用于符合特定条件的所有单词if (app.documents.length > 0 && app.activeDocument.textFrames.length > 0) { // 创建要应用于单词的颜色 var wordColor = new RGBColor(); wordColor.red = 255; wordColor.green = 0; wordColor.blue = 255;
// 设置要查找的单词的值 searchWord1 = "the"; var searchWord2 = "The"; var searchWord3 = "THE";
// 遍历文档中的所有单词 // 并为匹配 searchWord 的单词着色
for (var i = 0; i < app.activeDocument.textFrames.length; i++) { var textArt = activeDocument.textFrames[i];
for (var j = 0; j < textArt.words.length; j++) { var word = textArt.words[j];
if (word.contents == searchWord1 || word.contents == searchWord2 || word.contents == searchWord3) { word.filled = true; word.fillColor = wordColor; } } }}