-
-
Save nariakiiwatani/5b89e98dc78bc1ff3f24 to your computer and use it in GitHub Desktop.
レイヤー名置換 JSX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* レイヤー名置換 JSX | |
*/ | |
var _layers = []; | |
function main(dialog){ | |
var document = activeDocument; | |
var layers = document.layers; | |
getLayer(layers); | |
var originalText = dialog.txtOriginal.text; | |
var replaceText = dialog.txtReplace.text; | |
var num = _layers.length; | |
for(var i = 0; i < num; i++){ | |
renameIfMatches(_layers[i], originalText, replaceText); | |
} | |
} | |
function showDialog(){ | |
var dialog = new Window("dialog", "レイヤー名を検索して置換", [200, 100, 500, 230]); | |
dialog.btnOk = dialog.add("button", [160, 90, 230, 90 + 25], "OK"); | |
dialog.btnCancel = dialog.add("button", [70, 90, 140, 90 + 25], "Cancel"); | |
dialog.stxtOriginal = dialog.add("statictext", [20, 15, 100, 10 + 25], "検索文字列"); | |
dialog.txtOriginal = dialog.add("edittext", [120, 10, 280, 10 + 25], ""); | |
dialog.stxtReplace = dialog.add("statictext", [20, 55, 100, 50 + 25], "置換文字列"); | |
dialog.txtReplace = dialog.add("edittext", [120, 50, 280, 50 + 25], ""); | |
dialog.btnOk.onClick = (function(dialog) { | |
return function() { | |
main(dialog); | |
dialog.close(); | |
} | |
})(dialog); | |
dialog.btnCancel.onClick = (function(dialog) { | |
return function() { | |
dialog.close(); | |
} | |
})(dialog); | |
dialog.show(); | |
return dialog; | |
} | |
function getLayer(layers){ | |
var num = layers.length; | |
for(var i = 0; i < num; i++){ | |
var layer = layers[i]; | |
if(layer.typename == "LayerSet"){ | |
getLayer(layer.layers); | |
} | |
_layers.push(layer); | |
} | |
} | |
function renameIfMatches(layer, orgTxt, repTxt){ | |
var reg = new RegExp(orgTxt, "g"); | |
if(reg.test(layer.name)) { | |
var visible = layer.visible; | |
layer.name = layer.name.replace(reg, repTxt); | |
layer.visible = visible; | |
} | |
} | |
showDialog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Photoshop CCで動作確認済み