Javascript InDesign脚本错误“;ReferenceError:对象无效";
我正试图让我的生活和旧的脚本,我曾经使用的工作在过去。该脚本将下载漫画(我们有权)使用自动热键和卷曲。。。然后在InDesign中,我们将从javascript脚本面板运行以下命令:Javascript InDesign脚本错误“;ReferenceError:对象无效";,javascript,templates,curl,autohotkey,adobe-indesign,Javascript,Templates,Curl,Autohotkey,Adobe Indesign,我正试图让我的生活和旧的脚本,我曾经使用的工作在过去。该脚本将下载漫画(我们有权)使用自动热键和卷曲。。。然后在InDesign中,我们将从javascript脚本面板运行以下命令: #targetengine "session" var date, month, year, myDocument; var curDate = new Date(); var myTemplatePath = "/c/Comic/ComicImport.indd"; var myComicsPath = "/c/
#targetengine "session"
var date, month, year, myDocument;
var curDate = new Date();
var myTemplatePath = "/c/Comic/ComicImport.indd";
var myComicsPath = "/c/Comic/Comics/";
var myTemplate = new File(myTemplatePath);
if (myTemplate.exists) {
try {
myDocument = app.open(myTemplate);
} catch (e) {
alert("Could not open template, exiting\n" + e);
exit();
}
var win = showDialog();
} else {
alert("Could not locate template at:\n" + myTemplatePath + "\nexiting");
}
function showDialog() {
var win = new Window('palette');
with(win){
win.Pnl = add('panel', undefined, 'Date / Month / Year');
win.Pnl.orientation = 'row';
with(win.Pnl) {
win.Pnl.day = add('edittext');
win.Pnl.day.text = curDate.getDate();
win.Pnl.day.preferredSize = [30,20];
win.Pnl.month = add('edittext');
win.Pnl.month.text = curDate.getMonth() + 1;
win.Pnl.month.preferredSize = [30,20];
win.Pnl.year = add('edittext');
win.Pnl.year.text = curDate.getFullYear();
win.Pnl.year.preferredSize = [50,20];
}
win.btnOk = add('button', undefined, 'Import Comic');
win.btnOk.onClick = setDate;
};
win.center();
win.show();
return win;
}
function setDate() {
date = win.Pnl.day.text;
month = win.Pnl.month.text;
year = win.Pnl.year.text;
// OK we close the window and do the import
//win.close();
importComics();
}
function importComics() {
try {
//set comic1 to "macintosh Hd:users:marshall:documents:comics:" & DYear & Dmonth & Dday & "pzjud-a.tif"
var comics = new Array();
// REPLACE with own filepaths, could be
//comics.push(new File("/c/comics/" + year + month + date + "pzjud- a.tif"));
comics.push(new File(myComicsPath + "comic1-" + year + "-" + month + "-" + date + ".tif"));
comics.push(new File(myComicsPath + "comic2-" + year + "-" + month + "-" + date + ".tif"));
comics.push(new File(myComicsPath + "comic3-" + year + "-" + month + "-" + date + ".tif"));
comics.push(new File(myComicsPath + "comic4-" + year + "-" + month + "-" + date + ".tif"));
comics.push(new File(myComicsPath + "comic5-" + year + "-" + month + "-" + date + ".tif"));
} catch (e) {
alert("Error assigning images for import, stopping script\n" + e);
exit();
}
for (i = 1; i <= comics.length; i++) {
// Script label of the rectangles/pageitems to place the graphics into
var myRect = myDocument.pageItems.item("comic" + i);
try {
myRect.place(comics[i-1]);
} catch (e) {
alert(e);
}
myRect.fit(FitOptions.CONTENT_TO_FRAME);
}
}
#目标发动机“会话”
var日期、月份、年份、myDocument;
var curDate=新日期();
var myTemplatePath=“/c/Comic/ComicImport.indd”;
var myComicsPath=“/c/Comic/Comics/”;
var myTemplate=新文件(myTemplatePath);
if(myTemplate.exists){
试一试{
myDocument=app.open(myTemplate);
}捕获(e){
警报(“无法打开模板,正在退出\n”+e);
退出();
}
var win=showDialog();
}否则{
警报(“在以下位置找不到模板:\n”+myTemplatePath+“\nexiting”);
}
函数showDialog(){
var win=新窗口(“调色板”);
有(赢){
win.Pnl=add('panel',未定义,'Date/Month/Year');
win.Pnl.orientation='row';
使用(win.Pnl){
win.Pnl.day=添加('edittext');
win.Pnl.day.text=curDate.getDate();
win.Pnl.day.preferredSize=[30,20];
win.Pnl.month=添加('edittext');
win.Pnl.month.text=curDate.getMonth()+1;
win.Pnl.month.preferredSize=[30,20];
win.Pnl.year=添加('edittext');
win.Pnl.year.text=curDate.getFullYear();
win.Pnl.year.preferredSize=[50,20];
}
win.btnOk=add('button',未定义,'Import Comic');
win.btnOk.onClick=设置日期;
};
win.center();
win.show();
回归胜利;
}
函数setDate(){
日期=win.Pnl.day.text;
月份=win.Pnl.month.text;
年份=win.Pnl.year.text;
//好的,我们关闭窗口并进行导入
//win.close();
进口经济学();
}
函数importComics(){
试一试{
//将comic1设置为“macintosh Hd:users:marshall:documents:comics:&DYear&Dmonth&Dday&“pzjud-a.tif”
var comics=新数组();
//替换为自己的文件路径,可能是
//push(新文件(“/c/comics/”+年+月+日+pzjud-a.tif”);
comics.push(新文件(myComicsPath+“comic1-”+年+“-”+月+“-”+日期+”.tif));
comics.push(新文件(myComicsPath+“comic2-”+年+“-”+月+“-”+日期+”.tif));
push(新文件(myComicsPath+“comic3-”+年+“-”+月+“-”+日期+”.tif));
push(新文件(myComicsPath+“comic4-”+年+“-”+月+“-”+日期+”.tif));
push(新文件(myComicsPath+“comic5-”+年+“-”+月+“-”+日期+”.tif));
}捕获(e){
警报(“为导入分配图像时出错,正在停止脚本\n”+e);
退出();
}
对于(i=1;i注意这条线:
var myRect = myDocument.pageItems.item("comic" + i);
在最新的ID版本中,它不再调用“item.label”,而是调用“item.name”
(图层面板中显示的一个)
如果在您的文档目标矩形中有“label==comic+i”,那么您也必须重复/移动该值作为矩形的名称
否则-您的代码需要在所有pageItems中创建一个循环,并在放置图像之前检查特定的item.label。使用ExtendScript Toolkit进行调试可以帮助您确定问题。此外,发布您的目标版本。您的实际问题与AHK有关吗?脚本是否可能是为旧版本的In设计比您当前使用的版本低?请尝试(不要介意标题中的版本号低,该特定功能也适用于较新版本)。