#target photoshop //Variables var aDoc = app.activeDocument; var aDocName = app.activeDocument.name; var AllDocs = app.documents; var actLay = aDoc.activeLayer.name; var selectedGroup = aDoc.activeLayer; var thisFile = new File($.fileName); var basePath = thisFile.path; var groupname = aDoc.activeLayer.name; var thisFile = new File($.fileName); var basePath = thisFile.path; var prefix = ""; var surfix = ""; var startvan = 1; var numbernottext = 0; var check1 = false; var nameArray = new Array(); var numberOfFinds = 0; var positionarray = 0; var newname; var myIDversion = app.version.split(".")[0]; //New window var w = new Window("dialog","Search and replace"); //var w = new Window("dialog"); //White background //w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [1.0, 1.0, 1.0]); //Black background //w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [0.5, 0.5, 0.5]); if(myIDversion == 18) { var myIcon = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\u0099\x00\x00\x00%\b\x06\x00\x00\x00QTK\u00B4\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x03&iTXtXML:com.adobe.xmp\x00\x00\x00\x00\x00 \u0093\u0084\u00B6\u00F7\x00\x00\x04]IDATx\u00DA\u00EC\\\u00CD\u0095\u009B0\x10\u0096\u00F3\u00B6\x01R\u0082\u00B7\x04rK\u008E\u00A4\x04R\u0082\u00F7\u009A\u00E4\u00A2-\u0081\x1C\u0092\u009C\u00D9\x12\u00BC%\u00B0\u00C7\x1CI\t\u00B8\x04(\u0081\u00C0[\u0091(z#iFH\u00F6\u00B2\u009Eyo\u009E\u009F\rh\u00A4\u00D1\u00A7\u00F9\u0093\u00F0n\x1CGq.\u00FA\u00F2\u00E1\u00C7\u00FC\u0081\x15\u00B8\u00FB\u00F9\u00EB\u00AB`\u00DA>\u00BDa\x1501\u00C8\u0098\x18dLL>\u00BA\u00D9\u00EDvr\u00FA\u00ACV\u00B6\u00F3\u00A4x\u0098\u00F8\u00C1v\u00D3\u00E7\u00F7\u00DFI\u008DN}{-z\u00DEO\u00DC\u0099\u00C3\u00BB\x06\u0080\u00CD1\x7F,KV(\u00A0\u00D6*\u00B0\u0097\u00BC~\u0099R\u00BB\u00CB\x19p\r\u00AB\u0097)uL6[\u00B7#\u00AB\u0098\t\x02\u00D9i\u00F2\u00A3\u00BB\u0085U\u00EC\u00E0\u00E3;\x15\u0093\u0099TN|`53\u00C8b\u00D0\x1C\u00EC\x7F\u009C\u00F8\x1E\u00B8\u00C6\u00F1\x19\u0083,*}\x03,\u00DA\u009CY\u00E5FV\u0085a\u00A6WDRe\u0084\x0Bws\u00DA\u00B9p`,6\x1A|\u00ED\u00D6l\x0F\u00E8\u00E4*(f\tC\u00A7\u00A5^f*yK\u0094\u00AB\u0085\u00D1\x01\u00E0\u00A8y\u00D1\\\u00DE\u0092\t`rlY\u00A69\u0081&\x18\u008F\u00C0=9\x01(\x10@|\u00CF4\u00C0s6\u00C6&5Wm\u00C9\u00CE\x05\u00B2:\x10d\u00D9\u00C4\u00BDqO\x1B\u00D8\u0087N\u00B5g\u00A3\u0092\x00.\u00CC\x02b\u0090%t\u0097\x02\u0098\u00CC!\u00B0\u009DA\u0095G W\u00E6\u00A2\n\x00\u00EC'G?J\x11^\u00D3[\u00F3,\u00BB\u00CB@KV\x12\x02\x7F\u009F%\u00D3A\u0083u\u009B\u0090\u00FC\u008AheF\u00E56\x0F\u00C0\u00E2\u00B1\u00C5j\u0092-\u00D9\u00F9\u00DCe\x0B(4[\t\u00B2\f\u0098\u00D8v\u00C5}:A1X\u0089\x18\u00A7\x19/\u00F6\u008Eq2\u00C8\"\u0082\u00ECH\u008CY\u00B0 \u00B3\x05\u00F2re\u00A2\x00\u00B5Y\u00AC\x18\u00AF|E +b\u00F45\x16\u00C8J\u00A0\r,p(\u00F7\n\u008B\u009C<\u00C0M\u00DB\u00DCpM\u00D4\u00E1\x1EH.\x18d\b\u0090\u00C5d\u00DF$SA\x06\u00B9\u00E3F=\u00D7\x03\u00BFS\u00DB\u00CA\x03\u00F4\u0088i\u0083\u00DD\u00E5\u0085\x00\x16\n2\bP\u00D0w_[Y\u00A4\u0089\u00AF\x10\u00F1\u00DCU\u0083\u00EC&A\u00BB\u00BF\u00C5\u00F3F\u00F9S\u00A2~\u009F\u00C4\u00F3\x1Ei\u00E5(\u0099\u00DC\u00A9\u00FB|`\u0085@\u00BF\u0096\u00F6\u0082\u00E9?\u008AU'\u00BBW|;\u00F1\u00BB\u0084\x00[h\x06\u00D9\u00A3\u00E5\u00DA\u00A3\u00E3\u009A\u00AB\u0096\u0097\u00AAFH)#\u00F5\u009E\u00FBl'\u008F\u0097\u00DAa\x0F\u00C4\u00886\u008F\u00D2i\u0089\u008E\x04\\\u00BE/&#\u00C9LQ\u00F1G[\u00D3\x00w\u00E9rw#a\u0092\u008BDaB\x1D\u00E0.3Dv\u00AB\u00EF~\u00E8c< \u00FA\x04\u00EDvtZ\u00F6\x0F\u00E9\u00D0\x052\u00B4\u00CC\u0094\x15\u00FFs\u0090$\u00FE\u00FE\u0092i\u00D0\u00AC\x7F\u00E9\u00C8\u00E23e\u00A5\x07\r\u00BC\u00B5f\u00C1\u00DF\u008A\x7FG\u00A5n5\u008B\u00BE\x17\u00F6}\u00D6R\u00C9^\u009E\u00BD\x13\u00EE\x1D\u009A \u0099[\u00B4d\u00BE}FL\u0096\u0098#\u00CB\x0F1\b\x13\u00F8\x1F<.\u00B3\x01\x12\u008B\n\u00D1\u00F7\u00CEba;\u00E1.\"\u00DB,\x19If\u00CA\r\u00F2\u0094 \u0083\u00AA\u00FA\x18\u00F7\u0080q\u00B7\u00D9\x05A\u00A6\u00BB\u00C3\u00D2\u00F2|\x1F \u00BB\u00B1\u0094ttw\x19\u00BBN\u00F6W\u00E6V\u00DDem\u0080qPf\u00FAdL\u008A\u00EF]\u00D2\x01p\x0B\u00C5\x05\u00C7\u00A5\u00BB\u00CC\x02\u00B0\u00DC3= -\u00B4T\u00DC\"\u00C6t\u008A\u00D0w\u00AF\u00CC-Y2(\u00E0<8\x02y\u00DF\x1E\u00A4\x19\u00F46\u0081\u00AB\u00B6Qz,VX2=\f0]X\u00E7\b\x032\x01\x1F \x18=c\u00EB<\u00F5\u00CC\u00C2cuQ2\u00B7\u00E6.\u00A1\"\u00EC\u00D1\x12/`\u008B\u00B2![Q\u00AE\x05\x1A\u00A3\x18k\u00BA\u00CCe\u00B2[K\u00BB\u00B6\x13!\x0B\u00E8\u009B\u00C8 #\u00C9\u00DC\x1A\u00C8Z\u00E1?\u00F5\x00\u00C5k\u00BE\u00B3^] \u00D0JK,(V\u0082\u00AC2\u00FA\u00EDz+\u00BF\u00D6\u00E4\x16\u00811\x19\x15d$\u0099[\x02\x19\u00D6b\u00D8\u00DC\u00A6\f\u00A8\u0097\u00B5\u0096\u00E7\x0E\u0096\u00DA\u0092\u00EB86\x05d\u0085\u00B1\u0088zGR\u00D2#\u00C6\u00D7G\x06\x19I\u00E6V@\x16rV\u009F\u00EA6c\u00EC\u00DF\x1EWf\u0097\u00B6\u00B2\x03\u00E6\x1D\t\u0089\u00D0C,\u0090\u0091dn\x05dm`y\u0082zxQ&\x02X\b\u00C8$\u00D2j7\u00DA\"*\u008C\u0085\u00E9KjBAF\u0092\u00B9\x05\u0090A\x19\f\u00B6\u00CC\u00809\u00E4\b)\u00B6%\u0080\u00AB\x17\u00B87\u0096\u00A8 \u00CB\r\x19\u00941\u009A\u00C0\u00AA-\u00ED\u0084\u0082\u008C$\u00F3\u00A5\u0083\f\u008A\u0095\u00A8\u00FF\u00A3Fy7\u00C0T\u00B0\u00ED,\x7F\u00AF\u00AEQ\u00FE\u00E3#\u00E4\u00A8O\u008B\x1Cs\u00AEM\u00AAnYK\x00\x14y\u00A4\x12\x06I\u00E6\x1F\x01\x06\x00\u00AF\u00A1\u00FE\u00B6\u0099u\u008A+\x00\x00\x00\x00IEND\u00AEB`\u0082"; w.add ("iconbutton", undefined, myIcon); } else { var myMessage1 = w.add ("statictext"); myMessage1.text = "Pixelvaria"; myMessage1.graphics.font = ScriptUI.newFont ("Helvetica", "Regular", 30); myMessage1.graphics.foregroundColor = myMessage1.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [0, 0, 0], 1); } var myMessage2 = w.add ("statictext"); myMessage2.text = "Search and replace"; myMessage2.graphics.font = ScriptUI.newFont ("Helvetica", "Regular", 20); myMessage2.graphics.foregroundColor = myMessage2.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [0, 0, 0], 1); //input fields w.alignChildren = "center"; var myInputGroup = w.add ("group"); var myword = myInputGroup.add ("edittext", undefined, ""); myword.characters = 20; myword.active = true; var check1 = w.add ("checkbox", undefined, "Match case"); //New panel w.btnPnl = w.add('panel', [0,0,450,120], '',{multiline:true}); //Buttons w.btnPnl.testBtn1 = w.btnPnl.add('button', [90,30,350,50], 'search', {name:'doding1'}); w.btnPnl.testBtn1.onClick = dothing; w.btnPnl.testBtn2 = w.btnPnl.add('button', [370,80,100,50], 'close', {name:'doding2'}); w.btnPnl.testBtn2.onClick = doclose; w.btnPnl.testBtn3 = w.btnPnl.add('button', [30,80,200,100], 'more scripts at pixelvaria', {name:'doding3'}); w.btnPnl.testBtn3.graphics.font = ScriptUI.newFont ("Helvetica", "Bold", 12); w.btnPnl.testBtn3.onClick = dowebsite; //Show window w.show(); //Function that loads website function dowebsite() { alert("clicked"); try { //Dit maakt een tijdelijke html pagina aan var URL = new File(Folder.temp + "/openURL.html"); //In deze html pagina word een link gestoken waar hij naartoe refreshed URL.open("w"); URL.writeln(''); URL.close(); URL.execute(); // The temp HTML file created } catch(e) { alert("Error, Can Not Open."); }; } //Function that does the calculations for name changing function dothing(gp) { var searchword = myword.text; //alert(searchword ); function loopoverall(ref) { // declare local variables var layers = ref.layers; var len = layers.length; for ( var i = 0; i < len; i ++) { var layer = layers[i]; //alert(layers[i].id); //Action here //layer.allLocked = false; if (check1.value == true) { if(searchword == layer.name) { nameArray.push(layers[i].id); } } else { var testword = layer.name; var result = testword.indexOf(searchword) > -1; //alert(result); if(result==true) { nameArray.push(layers[i].id); } } if (layer.typename == 'LayerSet') { loopoverall(layer); } } } loopoverall(activeDocument); numberOfFinds = nameArray.length; //alert(numberOfFinds +" items found"); w.close(); //Find right layer and set active select_layer(nameArray[0]); findnextwindow(); } function canceling() { v.close(); } function findnextwindow() { var v = new Window("dialog"); //v.add ("iconbutton", undefined, myIcon); v.add ('statictext', undefined, numberOfFinds +" items found", {multiline: true}); var myInputGroupv = v.add ("group"); var mywordv = myInputGroupv.add ("statictext", undefined, "direction"); var radio1 = myInputGroupv.add ("radiobutton", undefined, "up"); var radio2 = myInputGroupv.add ("radiobutton", undefined, "down"); radio2.value = true; //Buttons v.testBtn1 = v.add('button', [5,30,150,50], 'find next', {name:'find1'}); v.testBtn1.onClick = findnext; var myInputGroupv2 = v.add ("group"); myInputGroupv2.add ("statictext", undefined, "replace:"); var replace = myInputGroupv2.add ("edittext", undefined, ""); replace.characters = 10; replace.active = true; v.replaceBtn1 = v.add('button', [5,30,150,50], 'replace', {name:'replace1'}); v.replaceBtn1.onClick = replacing; v.replaceBtn2 = v.add('button', [5,30,150,50], 'replace all', {name:'replace1'}); v.replaceBtn2.onClick = replacingall; v.testBtn1 = v.add('button', [5,30,150,50], 'cancel', {name:'cancel1'}); v.testBtn1.onClick = canceling; v.show(); function findnext() { if(radio2.value == true) { positionarray += 1; if(nameArray[positionarray] == undefined) { positionarray -= 1; alert("there is no next"); } selectLayerById(nameArray[positionarray]); } else { positionarray -= 1; if(nameArray[positionarray] == undefined) { positionarray += 1; alert("there is no next"); } selectLayerById(nameArray[positionarray]); } } function replacing() { //alert("do replace"); newname = replace.text; app.activeDocument.activeLayer.name = newname; } function replacingall() { //alert("do replace all"); for ( var m = 0; m <= nameArray.length; m ++) { selectLayerById(nameArray[m]); newname = replace.text; app.activeDocument.activeLayer.name = newname; } positionarray = nameArray.length-1; } } //Sluit functie function doclose() { w.close(); } //Functie om laag te vinden function select_layer(id, add, viz) { //Probeer een blok code die fout kan zijn try { //New Action var d = new ActionDescriptor(); //Of visible is of niet if (viz == undefined) viz = false; var r = new ActionReference(); if (typeof(id) == "string") r.putName( charIDToTypeID( "Lyr " ), id); else r.putIdentifier( charIDToTypeID( "Lyr " ), id); d.putReference( charIDToTypeID( "null" ), r ); d.putBoolean( charIDToTypeID( "MkVs" ), viz ); if (add == true) d.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); if (add == -1) d.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "removeFromSelection" ) ); var ok = true; try { executeAction( charIDToTypeID( "slct" ), d, DialogModes.NO ); } catch(e) { ok = false; } d = null; return ok; } //Catch de waarde van de code die fout kan zijn. catch (e) { alert(e); return false; } } function selectLayerById(id,add) { var ref = new ActionReference(); ref.putIdentifier(charIDToTypeID('Lyr '), id); 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) { } };