2015-06-16 38 views
1

首先,我在桌面上使用OS X 10.9 &與OS X 10.10的Macbook以及最新版本的Photoshop & ESTK。其中現在是:Photoshop CC 2015529.r.88 x64,ESTK 4.0.0.1 - ExtendedScript 4.5.5 & ScriptUI 6.2.2。在任一系統上的結果都是相同的。Photoshop/ESTK - 預定義數值的處理方式與用戶輸入的不同

總之,我的問題不是設置變量本身。它與變量中的值稍後在腳本中正確使用。包括將變量從另一個傳遞給另一個。

例如

var dflt = 16 
    var z = dflt 

主要是我想要做的是將用戶輸入的數值傳遞給變量。然後在腳本的另一部分中準確使用該值。當變量在用戶輸入之外的腳本中定義時,一切正常。很快,隨着用戶輸入被添加,變量可以被準確地重複回來。

如使用:

alert('The variable is currently set to: ' + value); 

但是並不如預期的結果在Photoshop中運行時。

腳本做了什麼或應該做什麼。是把積極層&切成一個預定義的網格的整個事情。每個剪輯都放在它自己的圖層上。正如我已經說過的。當網格預定義時,一切都完美無瑕。但是當添加用戶輸入時。電網完全傾斜。只有網格的第一個單元格/圖層是準確的。儘管可預測,其他一切都會奇怪地被拼湊出來。

我已經嘗試使用:

document.getElementById("numb") 

其中在Chrome & Firefox的正常工作。但在Photoshop或ESTK中運行時會崩潰。

prompt 

這提供了傾斜/馬賽克結果。

除了作爲一個對話窗口:

// begin dialog layout 
    var GridLayersDialog = new Window('dialog'); 
    GridLayersDialog.text = 'Grid To Layers'; 
    GridLayersDialog.frameLocation = [70, 70]; 
    GridLayersDialog.alignChildren = 'center'; 


    GridLayersDialog.GridSizePnl = GridLayersDialog.add('panel', [2, 2, 200, 70], 'Grid Size'); 
    GridLayersDialog.GridSizePnl.add('statictext', [10, 16, 79, 48], 'Dimensions: '); 
    GridLayersDialog.GridSizePnl.aspectDimension = GridLayersDialog.GridSizePnl.add('edittext', [85, 13, 120, 34], dfltCs, {name:'cellSize'}); 
    GridLayersDialog.GridSizePnl.aspectDimension.helpTip = 'Width & Height in pixels'; 


    var buttons = GridLayersDialog.add('group'); 
    buttons.orientation = 'row'; 
    var okBtn = buttons.add('button'); 
    okBtn.text = 'OK'; 
    okBtn.properties = {name: 'ok'}; 
    var cancelBtn = buttons.add('button'); 
    cancelBtn.text = 'Cancel'; 
    cancelBtn.properties = {name: 'cancel'}; 


    // display dialog and only continues on OK button press (OK = 1, Cancel = 2) 
    if (GridLayersDialog.show() == 1) { 
     cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text); etc... 

也提供類似的結果。

原來,「無缺陷」,腳本如下:

// Size of cell in pixels 
    var cellSize = 16; 

    // Set the ruler type 
    if (app.preferences.rulerUnits != Units.PIXELS) 
    { 
     app.preferences.rulerUnits = Units.PIXELS; 
    } 

    var layerRef = docRef.activeLayer; 

    for (y = 0; y<docRef.height; y+=cellSize) 
    { 
     for (x = 0; x<docRef.width; x+=cellSize) 
     { 
      //activate the original layer 
      docRef.activeLayer = layerRef; 
      //make the selection 
      docRef.selection.select(Array (Array(x, y), Array(x, y+cellSize), Array(x+cellSize,y+cellSize), Array(x+cellSize,y)), SelectionType.REPLACE, 0, false); 

      //copy the selection 
      docRef.selection.copy(); 
      //create and paste new layer 
      docRef.artLayers.add(); 
      docRef.paste(); 
      } 
     } 
    } 

我沒有嘗試過做一個預定義的列表,下拉菜單或其他。我也沒有設置滑塊,複選框或任何類似的選擇。沒有一個是理想的。我希望能夠使用可打字輸入字段來設置單元格大小。

我不確定這是否是預期的行爲,我的代碼中存在缺陷或需要報告的錯誤。任何幫助或瞭解爲什麼會發生這種情況將不勝感激。

這會變得有點長,所以不要將我的腳本發佈到文本字段中。整個腳本的當前迭代可用here。對於那些希望看到它的人。

+0

今天發佈的Photoshop新版本。目前正在更新,將通知如果更新解決我的問題。 – Terus

+0

在OS X 10.9和10.10上,Photoshop CC 2015529.r.88中仍存在此問題。伴隨着與OS X 10.9.1的一些不兼容。這可能會迫使我更新。 – Terus

+0

那麼作爲一個平庸的工作,我扔在一起粗糙的AppleScript,用用戶輸入替換原始腳本中的預定義值。這是一個混亂的觸摸,調用一個動作,以正確執行.js文件。因爲它是一個複雜的,只適用於OS X&只是一個快速修復和/或解決。我不想作爲回答發佈。如果有人發生這種情況,需要周圍的工作。請問我會盡我所能提供幫助。 – Terus

回答

1

我已經超過你的腳本:這可能幫助:

var dfltCs = 16; 

    // begin dialog layout 
    var GridLayersDialog = new Window('dialog'); 
    GridLayersDialog.center(); 
    GridLayersDialog.text = 'Grid To Layers'; 
    GridLayersDialog.frameLocation = [70, 70]; 
    GridLayersDialog.alignChildren = 'center'; 


    GridLayersDialog.GridSizePnl = GridLayersDialog.add('panel', [2, 2, 200, 70], 'Grid Size'); 
    GridLayersDialog.GridSizePnl.add('statictext', [10, 16, 79, 48], 'Dimensions: '); 
    GridLayersDialog.GridSizePnl.aspectDimension = GridLayersDialog.GridSizePnl.add('edittext', [85, 13, 120, 34], dfltCs, {name:'cellSize'}); 
    GridLayersDialog.GridSizePnl.aspectDimension.helpTip = 'Width & Height in pixels'; 
    // Room left for additional data in future update. 
    cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text); if (cellSize=="") { cellSize = dfltCs;} // Set user input to variable 

    GridLayersDialog.add ("button", undefined, "OK"); 
    if (GridLayersDialog.show() == 1) 
    { 
    var v = GridLayersDialog.GridSizePnl.aspectDimension.text; 
    alert('The variable is currently set to: ' + v); 
    } 

所有的變化都在最後幾行。要獲得edittext(字符串)的值,你需要像這樣的東西:

var v = GridLayersDialog.GridSizePnl.aspectDimension.text 

我希望這可以幫助。

+0

感謝您的時間和意見。不過,我已經將輸入傳遞給以下變量: ** cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text);如果(cellSize ==「」){cellSize = dfltCs;} ** 雖然你的回答讓我意識到。我不小心把它放在錯誤的地方。 我的問題不在於設置變量本身。由於該腳本之前運行的方式,因此正在腳本的「網格層」部分中正確使用該變量的值 – Terus

+0

。該變量由預定義的默認值設置。它也不能與主腳本正常工作。感謝您幫助我認識到這個額外的缺陷。 – Terus