2015-10-05 44 views
0

我試圖恢復過去使用過的舊版腳本和舊腳本。一旦InDesign腳本錯誤「ReferenceError:對象無效」

#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); 
    } 
} 

然而,由於我打的導入漫畫:該腳本將下載漫畫(我們有權利)使用的AutoHotkey和捲曲...然後在InDesign中,我們會從運行JavaScript腳本的面板下面按鈕,我得到「ReferenceError:Object is invalid」錯誤。我的目錄結構對我來說很好。有任何想法嗎?

謝謝!

+0

使用ExtendScript Toolkit進行調試可以幫助您識別問題。另外,發佈你的目標版本。 –

+0

您的實際問題與AHK有什麼關係? – Forivin

+0

該腳本是否可用於InDesign的舊版本,而不是當前正在使用的版本?嘗試[InDesignSecrets:在CS3中使用舊腳本](http://indesignsecrets.com/using-old-scripts-in-cs3.php)(不要介意標題中的低版本號,該特定功能也適用於較新版本)。 – usr2564301

回答

0

關注此行:

var myRect = myDocument.pageItems.item("comic" + i); 

在最新版本ID它不再調用 「item.label」,而是 「item.name」 (層面板中所示的一個)

如果內你的doc目標矩形有「label == comic + i」,你必須重複/移動這個值作爲矩形的名字。

否則 - 您的代碼需要在放置圖像前通過所有pageItems創建一個循環並檢查特定的item.label。

相關問題