2014-03-19 55 views
1

我試圖訪問腳本中當前打開的文檔,但它是未定義的。但我已經在Photoshop中打開文檔。我應該初始化它嗎? 這裏是我的代碼Photoshop腳本:app.activeDocument未定義

function ProcessDocumentWithoutXML() 
{ 
g_rootDoc  = app.activeDocument; 
g_progBar  = new ProgressBar(); 

if (app.activeDocument != null) 
{ 
    ProcessLayersWithoutXML(g_rootDoc); 
    alert("Done!"); 
} else { 
    alert("Missing active document"); 
} 
} 

ProcessDocumentWithoutXML(); 

回答

1

爲了它的工作

g_rootDoc  = app.activeDocument; 

需求是功能外(除非你的源文件中給該函數)。

修訂代碼:

if (documents.length != 0) 
{ 
    g_rootDoc = app.activeDocument; 
    // g_progBar = new ProgressBar(); // no worky in cs2 
    ProcessLayersWithoutXML(g_rootDoc); 
    alert("Done!"); 
} 
else 
{ 
    alert("Missing active document"); 
} 


function ProcessDocumentWithoutXML() 
{ 

} 

ProcessDocumentWithoutXML(); 

function ProcessLayersWithoutXML() 
{ 
} 
+0

這並不重要,問題在於app.activeDocument = null – arkhy

+0

嘗試使用documents.length!= 0。腳本已更新。 –

+0

無論如何,爲什麼它是空的,如果我已經打開文檔?另外 - 我有ProcessLayersWithoutXML和ProgressBar,但這裏也沒關係 – arkhy

0

如果在一個窗口中運行的Photoshop和ExtendedScript在其他窗口中運行你的代碼,你需要添加的第一行

「#target Photoshop的」

(沒有雙重標記)在您的js腳本。