2014-01-22 36 views
0

的名字,我知道它可以刪除使用從腳本的指數在Photoshop中色樣,它看起來像這樣:刪除色板使用色板

function DeleteSwatch(index) 
{ 
    var idDlt = charIDToTypeID("Dlt "); 
    var desc11 = new ActionDescriptor(); 
    var idnull = charIDToTypeID("null"); 
    var ref5 = new ActionReference(); 
    var idClrs = charIDToTypeID("Clrs"); 
    ref5.putIndex(idClrs, index); 
    desc11.putReference(idnull, ref5); 
    executeAction(idDlt, desc11, DialogModes.NO); 
} 

不過,我不知道是否有人知道方法來使用顏色樣本的名稱而不是索引?

回答

0

我很幸運,想通了,所以分享。

function DeleteSwatch(name) 
{ 
    var ref = new ActionReference(); 
    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); 
    var desc = executeActionGet(ref);// get the app descriptor 
    var presetsList = desc.getList(stringIDToTypeID('presetManager'));// the presets list 
    var swatchDesc = presetsList.getObjectValue(1);// swatches is the second key 
    var nameList = swatchDesc.getList(charIDToTypeID("Nm "));// there is only one key in the swatch descriptor so get the list 
    var nameOfFirstSwatch = nameList.getString(0);// all the name list keys are strings data types so get the first swatch name 

    var indexToDelete = -1; 

    for (var i = 0; i < nameList.count; i++) 
    { 
     if(nameList.getString(i) === name) 
     { 
      indexToDelete = i + 1; 
      break; 
     } 
    } 

    if(indexToDelete != -1) 
    { 
     var idDlt = charIDToTypeID("Dlt "); 
     var ad1 = new ActionDescriptor(); 
     var idnull = charIDToTypeID("null"); 
     var ref5 = new ActionReference(); 
     var idClrs = charIDToTypeID("Clrs"); 
     ref5.putIndex(idClrs, indexToDelete); 
     ad1.putReference(idnull, ref5); 
     executeAction(idDlt, ad1, DialogModes.NO); 
    } 
}