[英]How to select all textframes in document, and retrieve the text in adobe indesign
I have multiple textframes in my document and i have created a script to replace specific words from a textframe as such: 我的文档中有多个文本框架,并且创建了一个脚本来替换文本框架中的特定单词,例如:
var linebreak = "<br/>";
if (string.indexOf(linebreak) >= 0) {
var string2 = string.replaceAll(linebreak, "\r");
} else {
alert("false");
}
myFrame = app.activeDocument.textFrames.itemByName("test");
myFrame.contents = string2;
But without having to choose the name of the textframe i would like to do it to all active textframes in the document 但是不必选择文本框的名称,我想对文档中所有活动的文本框进行命名
Untested, but something along these lines should work: 未经测试,但遵循以下原则的方法应该起作用:
var linebreak = "<br/>";
var myFrames = app.activeDocument.textFrames;
for (var i=0; i<myFrames.length; i++) {
var myFrame = myFrames[i];
var string = myFrame.contents;
if (string.indexOf(linebreak) >= 0) {
myFrame.contents = string.replaceAll(linebreak, "\r");
} else {
alert("false");
}
}
A different approach, also untested, but also should work: 同样未经测试的另一种方法也应该有效:
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "<br/>";
app.changeGrepPreferences.changeTo = "\\r"
activeDocument.changeGrep();
answer from OP OP的回答
Solved: 解决了:
var linebreak = "<br />";
var myFrames = app.activeDocument.textFrames;
for (var i = 0; i<myFrames.length; i++) {
var myFrame = myFrames[i];
var string = myFrame.contents;
if (string.indexOf(linebreak) >= 0) {
var string2 = string.replace(new RegExp(linebreak, 'g'), '\r');
} else {
alert("ERROR: Cant find linebreak");
}
myFrame.contents = string2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.