我的文档中有多个文本框架,我创建了一个脚本来替换文本框架中的特定单词:
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;
但是,无需选择文本框架的名称,我想对文档中的所有活动文本框架执行此操作
答案 0 :(得分:2)
未经测试,但这些内容应该有效:
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");
}
}
答案 1 :(得分:0)
一种不同的方法,也是未经测试的,但也应该有效:
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "<br/>";
app.changeGrepPreferences.changeTo = "\\r"
activeDocument.changeGrep();
答案 2 :(得分:0)
回答
<强>解决:强>
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;
}