2017-03-24 33 views
0

我是這裏的新品牌,也是腳本編寫的新手。我正在爲我們的圖像處理團隊編寫一個腳本,其中包含一個要求用戶在關閉文檔前確認前景色和背景色的組件。 我似乎無法過去的問題是腳本正在處理所有的功能,並在最後寫入警報,但用戶應該看到的用於驗證警告框的最終圖像不會在警報框彈出之前呈現並暫停代碼。以下是完整代碼的示例。任何幫助或建議將不勝感激。Photoshop Javascript圖像在顯示警告框之前不在屏幕上呈現

#target photoshop 
app.bringToFront(); 
var docRef = app.activeDocument; 
var selRefMain = docRef.selection; 
checkColors(); 

function checkColors() 
    docRef.resizeImage(800, 800, 72, ResampleMethod.BICUBIC); 
    var selBoundsFg = Array(Array(0, 0), Array(800, 800), Array(0, 800)); //creates bounds for Foreground color selection 
    var selBoundsBg = Array(Array(0, 0), Array(800, 800), Array(800, 0));//creates bounds for background color selection 
    selRefMain.select (selBoundsFg); 
    selRefMain.fill(app.foregroundColor); 
    selRefMain.select (selBoundsBg); 
    selRefMain.fill(app.backgroundColor); 
    selRefMain.deselect(); 
}; 
alert ("Please check Foredround and Background colors"); 
+0

在猜測我會說填寫圖像的時間比繪製代碼的時間要長,因此警報首先顯示。我不認爲有一個重繪()函數,但你可以放入一個人工延遲。 –

+0

我試過使用$ .sleep(300);函數來延遲警報框,但圖像保持不渲染(全黑色),直到警報框被確認。 – AOK

回答

0

一種方法是等待重繪:

var desc = new ActionDescriptor(); 
desc.putEnumerated(charIDToTypeID("Stte"), charIDToTypeID("Stte"), charIDToTypeID("RdCm")); 
executeAction(charIDToTypeID("Wait"), desc, DialogModes.NO); 

這是從stdlib.js 8273線拉出。