InDesign CC 2017 ExtendScript - 无法覆盖 TextArea 中的文本
InDesign CC 2017 ExtendScript - Can't overwrite text in TextArea
在这一点上,我确信这是我所缺少的简单的东西,但我终其一生都无法弄清楚。
正在处理一个 InDesign 脚本,该脚本将传递到脚本中的文本写入当前选定的文本区域。
insertButton.onClick = function(){
var postIndex = postList.selection.index;
var postContent = posts[postIndex].content.rendered;
$.writeln(app.selection[0].parentStory.contents);
app.selection[0].parentStory.contents = postContent;
$.writeln(app.selection[0].parentStory.contents);
myWindow.close();
}
我已经确认该函数被正确调用,postContent 存在并且是我所期望的,并且第一个 writeln 调用转储了 TextArea 的当前值。第二个 $.writeln 永远不会触发,所以我知道错误在
app.selection[0].parentStory.contents = postContent;
是否有更新的方法来设置我在文档中没有找到的 TextArea 内容?
提前致谢!
...postContent exists and is what I expect it to be...
Indesign 在这里需要一个字符串 --> 它也是您所期望的吗?
什么是输入选择?文本?文本框?
你可以
alert(postContent.construction.name)
确保您所拥有的
亚雷克
在 ExtendScript Toolkit 中启用调试后,我能够找到抛出的错误:
"cannot handle the request because a modal dialog or alert is active"
这是指我启动脚本时打开的对话框。
延迟文本插入直到对话框实际关闭解决了这个问题。
insertButton.onClick = function(){
var postIndex = postList.selection.index;
postContent = posts[postIndex].content.rendered;
postContent = sanitizePostContent(postContent);
// The 1 here is the result that tells our code down below that
// the window has been closed by clicking the 'Insert' button
myWindow.close(1);
}
var result = myWindow.show();
// If the window has been closed by the insert button, insert the content
if (result == 1) {
app.selection[0].parentStory.contents = postContent;
}
我认为您的问题是您的 window 是模态的,因此阻止了与 inDesign 对象的任何交互。
您必须先退出对话框才能修改对象:
var w = new Window('dialog');
var btn = w.add('button');
btn.onClick = function() {
w.close(1);
}
if ( w.show()==1){
//"InDesign is no longer in modal state. So you can modify objects…")
}
在这一点上,我确信这是我所缺少的简单的东西,但我终其一生都无法弄清楚。
正在处理一个 InDesign 脚本,该脚本将传递到脚本中的文本写入当前选定的文本区域。
insertButton.onClick = function(){
var postIndex = postList.selection.index;
var postContent = posts[postIndex].content.rendered;
$.writeln(app.selection[0].parentStory.contents);
app.selection[0].parentStory.contents = postContent;
$.writeln(app.selection[0].parentStory.contents);
myWindow.close();
}
我已经确认该函数被正确调用,postContent 存在并且是我所期望的,并且第一个 writeln 调用转储了 TextArea 的当前值。第二个 $.writeln 永远不会触发,所以我知道错误在
app.selection[0].parentStory.contents = postContent;
是否有更新的方法来设置我在文档中没有找到的 TextArea 内容?
提前致谢!
...postContent exists and is what I expect it to be...
Indesign 在这里需要一个字符串 --> 它也是您所期望的吗?
什么是输入选择?文本?文本框?
你可以
alert(postContent.construction.name)
确保您所拥有的
亚雷克
在 ExtendScript Toolkit 中启用调试后,我能够找到抛出的错误:
"cannot handle the request because a modal dialog or alert is active"
这是指我启动脚本时打开的对话框。
延迟文本插入直到对话框实际关闭解决了这个问题。
insertButton.onClick = function(){
var postIndex = postList.selection.index;
postContent = posts[postIndex].content.rendered;
postContent = sanitizePostContent(postContent);
// The 1 here is the result that tells our code down below that
// the window has been closed by clicking the 'Insert' button
myWindow.close(1);
}
var result = myWindow.show();
// If the window has been closed by the insert button, insert the content
if (result == 1) {
app.selection[0].parentStory.contents = postContent;
}
我认为您的问题是您的 window 是模态的,因此阻止了与 inDesign 对象的任何交互。 您必须先退出对话框才能修改对象:
var w = new Window('dialog');
var btn = w.add('button');
btn.onClick = function() {
w.close(1);
}
if ( w.show()==1){
//"InDesign is no longer in modal state. So you can modify objects…")
}