#target photoshop /** * 增加 批量替换名称如: * 头,身体,大手臂,小手臂,手掌,大腿,小腿 * head,body,bigarm,forearm,palm,thigh,calf * **/ var cacheValue = new Map (); var win; var res ="dialog { \ text:'图层批量重命名 ',\ group: Group{orientation: 'column',alignChildren:'left',\ mode:Panel{orientation: 'row', text:'作用范围:',\ selected:RadioButton {text:'选中图层' },\ all:RadioButton {text:'所有图层' },\ }\ whichType:Panel{orientation: 'row', text:'类型:',\ whole:RadioButton {text:'整体' },\ rep:RadioButton {text:'替换' },\ add_del:RadioButton {text:'添加/删除' },\ }\ allGroup:Panel {orientation:'stack', alignChildren:'top',text: '整体', \ renameall: Group { orientation: 'column',alignChildren:'left',text: '命名规则',\ name: Group { orientation: 'row', \ txt: StaticText { text:'命名规则:' }, \ edit: EditText { preferredSize: [240, 20] } ,\ }, \ helpTip: Group{orientation: 'column',alignChildren:'left',\ txt1: StaticText{ text:'在此处输入“A_#” 则图层名为“A_<数字编号>'},\ txt2: StaticText{ text:'使用 * 插入原始图层名称'},\ txt3: StaticText{ text:'使用 # 以数字插入指定位置'},\ }\ paramGroup: Group{orientation: 'column',alignChildren:'left',\ beginId: Group { orientation: 'row', \ txt: StaticText { text:'开始于:' }, \ edit: EditText { text:'0',preferredSize: [50, 20]} ,\ }, \ incremental: Group { orientation: 'row', \ txt: StaticText { text:'增量: ' }, \ edit: EditText { text:'1', preferredSize: [50, 20]} ,\ }, \ bits: Group { orientation: 'row', \ txt: StaticText { text:'位数: ' }, \ dropdownlist:DropDownList { alignment:'left', itemSize: [34,16] },\ }, \ }\ prefabGroup: Panel{orientation: 'column',alignChildren:'top',text: '属性预设',\ prefab1: Group { orientation: 'row', alignment:'left', \ btnButton: Button { text:'btn',size:{width:72,height:22}}, \ btnToggle: Button { text:'toggle'} \ btnCheck: Button { text:'toggle@check'} \ }, \ prefab2: Group { orientation: 'row',alignment:'left', \ btnPng9: Button { text:'.9',size:{width:60,height:22}} \ btnProgressBar: Button { text:'progressBar'} \ btnBar: Button { text:'progressBar@bar'} \ }, \ prefab3: Group { orientation: 'row',alignment:'left', \ btnSize: Button { text:'size'} \ btnScale: Button { text:'scale'} \ btnFull: Button { text:'full'} \ }, \ prefab4: Group { orientation: 'row', alignment:'left',\ btnFlip: Button { text:'flip'} \ btnFlipX: Button { text:'flipX'} \ btnFlipY: Button { text:'flipY'} \ }, \ prefab5: Group { orientation: 'row',alignment:'left', \ btnIgnore: Button { text:'ignore'} \ btnIgnoreImg: Button { text:'ignoreimg'} \ btnIgnoreNode: Button { text:'ignorenode'} \ }, \ prefab6: Group { orientation: 'row', alignment:'left',\ btnImg: Button { text:'img'} \ btnAR: Button { text:'ar'} \ }, \ }\ }, \ repGroup: Group { orientation: 'column',alignChildren:'left',text: '命名规则',\ helpTip: Group{orientation: 'column',alignChildren:'left',\ txt1: StaticText{ text:'替换文件名中的字符 '},\ },\ oldStr: Group { orientation: 'row', \ txt: StaticText { text:'把: ' }, \ edit: EditText { preferredSize: [160, 20] } ,\ }, \ newStr: Group { orientation: 'row', \ txt: StaticText { text:'替换成:' }, \ edit: EditText { preferredSize: [160, 20] } ,\ }, \ }, \ add_del: Group { orientation: 'column',alignChildren:'left',text: '添加/删除',\ frontadd: Group { orientation: 'row', \ txt: StaticText { text:'文件名前添加: ' }, \ edit: EditText { preferredSize: [200, 20] } ,\ }, \ backtoadd: Group{ orientation: 'row', \ txt: StaticText { text:'文件名后添加: ' }, \ edit: EditText { preferredSize: [200, 20] } ,\ }, \ del: Group{ orientation: 'row', \ txt: StaticText { text:'删除文件名中的:' }, \ edit: EditText { preferredSize: [200, 20] } ,\ }, \ extensionadd: Checkbox{text:'扩展添加'},\ addGroup: Group{orientation: 'column',alignChildren:'left',\ beginId: Group { orientation: 'row', \ txt: StaticText { text:'从文件名第:' }, \ edit: EditText { text:'0',preferredSize: [50, 20]} ,\ txt: StaticText { text:'个字符开始' }, \ }, \ extensionaddStr: Group { orientation: 'row', \ txt: StaticText { text:'添加字符串:' }, \ edit: EditText { text:'', preferredSize: [80, 20]} ,\ }, \ }\ extensiondel: Checkbox{text:'扩展删除'},\ delGroup: Group{orientation: 'column',alignChildren:'left',\ beginId: Group { orientation: 'row', \ txt: StaticText { text:'从文件名第:' }, \ edit: EditText { text:'0',preferredSize: [50, 20]} ,\ txt: StaticText { text:'个字符开始' }, \ }, \ totalNum: Group { orientation: 'row', \ txt: StaticText { text:'共删除:' }, \ edit: EditText { text:'1', preferredSize: [50, 20]} ,\ txt: StaticText { text:'字符' }, \ }, \ }\ }, \ }\ },\ buttons: Group { orientation: 'row', alignment: 'right',\ btnOK: Button { text:'确定', properties:{name:'ok'} }, \ btnCancel: Button { text:'取消', properties:{name:'cancel'} } \ }, \ }"; var prefabBtns = [['btnButton','@btn'],['btnToggle','@toggle'],['btnCheck','@check'],['btnPng9','@.9{l:0,r:0,b:0,t:0}'],['btnProgressBar','@progressBar'],['btnBar','@bar'],['btnSize','@size{w:100,h:100}'],['btnScale','@scale{x:1,y:1}'],['btnFull','@full'],['btnFlip','@flip{bind: 0, x: 0, y: 0}'],['btnFlipX','@flipX{bind: 0}'],['btnFlipY','@flipY{bind: 0}'],['btnIgnore','@ignore'],['btnIgnoreImg','@ignoreimg'],['btnIgnoreNode','@ignorenode'],['btnImg','@img{name: *,id: 0,bind: 0}'],['btnAR','@ar{x:0.5,y:0.5}']]; app.bringToFront(); if (documents.length == 0) { alert("没有可处理的文档"); }else { main(); } function main(){ initWin(); } function initWin(){ win = new Window (res); var whichType = win.group.whichType; var repGroup = win.group.allGroup.repGroup; var add_del = win.group.allGroup.add_del; var renameall = win.group.allGroup.renameall; whichType.whole.value = true; add_del.visible = false; repGroup.visible = false; whichType.whole.onClick = function(){ renameall.visible = true; add_del.visible = false; repGroup.visible = false; win.group.allGroup.text = "整体"; } whichType.rep.onClick = function(){ renameall.visible = false; add_del.visible = false; repGroup.visible = true; win.group.allGroup.text = "替换"; } whichType.add_del.onClick = function(){ renameall.visible = false; add_del.visible = true; repGroup.visible = false; win.group.allGroup.text = "添加/删除"; } //整体 checkNum(renameall.paramGroup.beginId.edit,0); checkNum(renameall.paramGroup.incremental.edit,1); //checkNum(renameall.paramGroup.bits.renameall,1); renameall.paramGroup.bits.enabled = false; // ====================================================暂时不能选择位数 等待补全==================================================== win.group.mode.selected.value = true; var dropDownList = renameall.paramGroup.bits.dropdownlist; for(var i = 0; i < 5; i++){//给下拉列表添加元素 dropDownList.add("item",i+1); } dropDownList.items[0].selected=true;//使第一个被选中 //添加/删除 add_del.addGroup.enabled = false; add_del.delGroup.enabled = false; checkNum(add_del.addGroup.beginId.edit,0); checkNum(add_del.delGroup.beginId.edit,0); checkNum(add_del.delGroup.totalNum.edit,1); add_del.extensiondel.onClick = function(){ add_del.delGroup.enabled = !add_del.delGroup.enabled; } add_del.extensionadd.onClick = function(){ add_del.addGroup.enabled = !add_del.addGroup.enabled; } win.buttons.btnCancel.onClick = function () { win.close(); } win.buttons.btnOK.onClick = function () { var isSucc = false; if(renameall.visible){ isSucc = exeRename(); }else if(add_del.visible){ isSucc = exeAdd_Del(); }else if(repGroup.visible){ isSucc = exeReplace(); } isSucc && win.close(); } for(var i=0;i 1){ var str = Number.toString (num); var form=''; for(var i = 0;i < bits-1;i++){ form+='0'; } return form+num; } return num; } function checkNum(editText,defaultNum){ cacheValue.set(editText,defaultNum); editText.onChanging = function(){ if(isNaN(editText.text)){//非数字 editText.text = cacheValue.get(editText); }else{ cacheValue.set(editText,editText.text); } } } function getSelectedLayers(){ var idGrp = stringIDToTypeID( "groupLayersEvent" ); var descGrp = new ActionDescriptor(); var refGrp = new ActionReference(); refGrp.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" )); descGrp.putReference(charIDToTypeID( "null" ), refGrp ); executeAction( idGrp, descGrp, DialogModes.ALL ); var resultLayers=new Array(); for (var ix=0;ix