Help us understand the problem. What is going on with this article?

Adobe JSXでPhotoshopのレイヤーにカラーラベルをつける

More than 1 year has passed since last update.

こんなクラスを用意して、

#target photoshop

var PSLayerUtil = function() {
  this._colorRef = new ActionReference();
  this._colorRef.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
}
PSLayerUtil.LayerColors = {
  Red: 'Rd  ',
  Orange: 'Orng',
  Yellow: 'Ylw ',
  Green: 'Grn ',
  Blue: 'Bl  ',
  Violet: 'Vlt ',
  Gray: 'Gry ',
  None: 'None',
};
PSLayerUtil.prototype = {
  _colorRef: null,
  setLayerColor: function(layerColor) {
    var colorDescriptor = new ActionDescriptor();
    colorDescriptor.putEnumerated(charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID(layerColor));
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID('null'), this._colorRef);
    desc.putObject(charIDToTypeID('T   '), charIDToTypeID('Lyr '), colorDescriptor);
    executeAction(charIDToTypeID('setd'), desc, DialogModes.NO);
    return this.layerColor();
  },
  layerColor: function() {
    var desc = executeActionGet(this._colorRef);
    var charID = typeIDToCharID(desc.getEnumerationValue(charIDToTypeID('Clr ')));
    for(var key in PSLayerUtil.LayerColors) {
      var value = PSLayerUtil.LayerColors[key];
      if(value === charID) return key;
    }
    return 'None';
  },
}

こんな感じで実行すれば、

var util = new PSLayerUtil();
alert(util.setLayerColor(PSLayerUtil.LayerColors.Red));

選択してるレイヤーにカラーラベルが付くらしい。
で、せっかくなのでGitHubで公開してみた。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away