Skip to content

Instantly share code, notes, and snippets.

@sacrifs
Last active February 19, 2018 06:07
Show Gist options
  • Save sacrifs/2396376 to your computer and use it in GitHub Desktop.
Save sacrifs/2396376 to your computer and use it in GitHub Desktop.
レイヤー名置換 JSX
/**
* レイヤー名置換 JSX
*
* @version 1.0.0
* @author sarifs
*/
var _layerList = [],
main = function(){
var dialog = createDialog();
dialog.btnOk.onClick = function(){
var document = activeDocument;
var layerList = document.layers;
getLayer(layerList);
var originalText = dialog.txtOriginal.text;
var replaceText = dialog.txtReplace.text;
for(var i = 0, num = _layerList.length; i < num; i++){
var layer = _layerList[i];
replaceLayerName(layer, originalText, replaceText);
}
dialog.close();
alert("処理が完了しました。");
};
dialog.show();
},
createDialog = function(){
var dialog = new Window("dialog", "レイヤー名を検索して置換", [200, 100, 500, 230]);
dialog.btnOk = dialog.add("button", [160, 90, 230, 90 + 25], "OK", {name:"ok"});
dialog.btnCancel = dialog.add("button", [70, 90, 140, 90 + 25], "Cancel", {name:"cancel"});
dialog.stxtOriginal = dialog.add("statictext", [20, 12, 100, 10 + 25], "検索文字列");
dialog.txtOriginal = dialog.add("edittext", [120, 10, 280, 10 + 25], "");
dialog.stxtReplace = dialog.add("statictext", [20, 52, 100, 50 + 25], "置換文字列");
dialog.txtReplace = dialog.add("edittext", [120, 50, 280, 50 + 25], "");
return dialog;
},
getLayer = function(layerList){
for(var i = 0, num = layerList.length; i < num; i++){
var layer = layerList[i];
if(layer.typename == "LayerSet"){
getLayer(layer.layers);
}
_layerList.push(layer);
}
},
replaceLayerName = function(layer, orgTxt, repTxt){
var reg = new RegExp(orgTxt, "g");
var name = layer.name;
if(reg.test(name)){
var isVisible = layer.visible;
layer.name = name.replace(reg, repTxt);
layer.visible = isVisible;
}
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment