読者です 読者をやめる 読者になる 読者になる

CGメソッド

CG制作に関してのヒント

MENU

【Photoshop】レイヤー名の前や後ろに文字を追加する方法

f:id:min0124:20160828093050p:plain

Photoshopのデータ整理、もといLive2dの素材分け等で使えるかなと思います。

レイヤー名の前や後ろに文字を追加する方法

やり方はレイヤーを選択して(複数可)下記のスクリプトを実行。

用途としては、「目」「腕」とかのパーツ名はアクションスクリプトにし、

命名を記述後に、このスクリプトをショートカット登録して、「左右」や「線画・塗り」等の情報を追加してやるイメージです。

レイヤー名の前に文字を追加

f:id:min0124:20161209080039j:plain

#target photoshop;  
app.bringToFront();  
if(documents.length){  
var prefix = "塗り_"  
var selLayers = getSelectedLayersIdx();  
for (var a in selLayers){  
    selectLayerByIndex(selLayers[a]);  
    activeDocument.activeLayer.name = prefix + activeDocument.activeLayer.name;  
    }  
}  
function selectLayerByIndex(index,add){   
var ref = new ActionReference();  
ref.putIndex(charIDToTypeID("Lyr "), index);  
var desc = new ActionDescriptor();  
desc.putReference(charIDToTypeID("null"), ref );  
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );   
desc.putBoolean( charIDToTypeID( "MkVs" ), false );   
try{  
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );  
}catch(e){}  
};  
function getSelectedLayersIdx(){   
      var selectedLayers = new Array;   
      var ref = new ActionReference();   
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
      var desc = executeActionGet(ref);   
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){   
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));   
          var c = desc.count   
          var selectedLayers = new Array();   
          for(var i=0;i<c;i++){   
            try{   
               activeDocument.backgroundLayer;   
               selectedLayers.push(  desc.getReference( i ).getIndex() );   
            }catch(e){   
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );   
            }   
          }   
       }else{   
         var ref = new ActionReference();   
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));   
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
         try{   
            activeDocument.backgroundLayer;   
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);   
         }catch(e){   
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));   
         }   
     var vis = app.activeDocument.activeLayer.visible;  
        if(vis == true) app.activeDocument.activeLayer.visible = false;  
        var desc9 = new ActionDescriptor();  
    var list9 = new ActionList();  
    var ref9 = new ActionReference();  
    ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
    list9.putReference( ref9 );  
    desc9.putList( charIDToTypeID('null'), list9 );  
    executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );  
    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();  
        app.activeDocument.activeLayer.visible = vis;  
      }   
      return selectedLayers;   
}; 

レイヤー名の後ろに文字を追加

f:id:min0124:20161209080047j:plain

#target photoshop;  
app.bringToFront();  
if(documents.length){  
var prefix = "_右"  
var selLayers = getSelectedLayersIdx();  
for (var a in selLayers){  
    selectLayerByIndex(selLayers[a]);  
    activeDocument.activeLayer.name =activeDocument.activeLayer.name + prefix;  
    }  
}  
function selectLayerByIndex(index,add){   
var ref = new ActionReference();  
ref.putIndex(charIDToTypeID("Lyr "), index);  
var desc = new ActionDescriptor();  
desc.putReference(charIDToTypeID("null"), ref );  
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );   
desc.putBoolean( charIDToTypeID( "MkVs" ), false );   
try{  
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );  
}catch(e){}  
};  
function getSelectedLayersIdx(){   
      var selectedLayers = new Array;   
      var ref = new ActionReference();   
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
      var desc = executeActionGet(ref);   
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){   
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));   
          var c = desc.count   
          var selectedLayers = new Array();   
          for(var i=0;i<c;i++){   
            try{   
               activeDocument.backgroundLayer;   
               selectedLayers.push(  desc.getReference( i ).getIndex() );   
            }catch(e){   
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );   
            }   
          }   
       }else{   
         var ref = new ActionReference();   
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));   
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
         try{   
            activeDocument.backgroundLayer;   
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);   
         }catch(e){   
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));   
         }   
     var vis = app.activeDocument.activeLayer.visible;  
        if(vis == true) app.activeDocument.activeLayer.visible = false;  
        var desc9 = new ActionDescriptor();  
    var list9 = new ActionList();  
    var ref9 = new ActionReference();  
    ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
    list9.putReference( ref9 );  
    desc9.putList( charIDToTypeID('null'), list9 );  
    executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );  
    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();  
        app.activeDocument.activeLayer.visible = vis;  
      }   
      return selectedLayers;   
}; 

参考

Prefix layer names |Adobe Community