Aug 27, 2016 The Photoshop scripting guru Paul R over at RetouchPro has created a really cool script to batch rename and number selected Photoshop layers. I haven't found anything similar on the Illustrator side. He's given permission for me to post it here in my hopes that some Illustrator scripting genius could come up with a similar script for Illustrator.
PermalinkJoin GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up Find file Copy path
Cannot retrieve contributors at this time
//@include 'stdlib.js' |
vardocRef=app.activeDocument; |
varlayers=Stdlib.getLayersList(docRef, false, true); |
for (vari=0; i<layers.length; i++) { |
varlayer=layers[i]; |
renameLayer(layer); |
} |
// borrowed from RenameLayers.jsx by Mark Walsh |
functionrenameLayer(objectRef) { |
vartheRegEx=newRegExp(/(s*copys*d*)+$/); |
if (theRegEx.test(objectRef.name)) { |
// save state of layer (visible or invisible) |
varlayerVisible=objectRef.visible; |
varindexNumber=0; |
indexnumber=objectRef.name.indexOf(' copy'); |
objectRef.name=objectRef.name.substr(0,indexnumber); |
objectRef.visible=layerVisible; |
} |
return0; |
} |
Copy lines Copy permalink
![Photoshop scripts folder Photoshop scripts folder](http://blog.darkwark.com/images/layerRenamer_APR/n-word_step2.png)
I recently tried to dip back into my old JavaScript 'skills' to make a script for Photoshop. It's simply a recursive function that will loop over all the layers in a file and renames any duplicate names to add numbers so every layer name is unique.
In Photoshop, an
ArtLayer
is just a regular layer, and a LayerSet
is a folder that contains layers, so I need to address them both separately. I wasn't sure if I could just make a function to do the main body of renameLayerNames
because I wasn't sure if I could pass the ArtLayer
and LayerSet
objects by reference or if they'd become copies.The format is copied from a pre-existing Photoshop script, so it might be funny looking and I'm not averse to changing it to fit how JavaScript normally works. I'm looking for all feedback, particularly about any notes about not writing 'proper' JavaScript style.
SuperBiasedManSuperBiasedMan12k5 gold badges28 silver badges60 bronze badges
$endgroup$