首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Photoshop中使用色板名称删除色板

在Photoshop中使用色板名称删除色板
EN

Stack Overflow用户
提问于 2014-01-22 17:23:29
回答 1查看 282关注 0票数 1

我知道使用脚本中的索引在photoshop中删除色板是可能的,它看起来像这样:

代码语言:javascript
复制
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 );
}

但是,我想知道是否有人知道使用色板名称而不是索引的方法?

EN

回答 1

Stack Overflow用户

发布于 2014-01-22 17:52:17

我很幸运,弄清楚了,所以就分享给大家吧。

代码语言:javascript
复制
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 );
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21278807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档