In this post, you will find a simple script that was created to solve the issue of appended “copy” text on duplicated layers in adobe illustrator. This issue may be extremely frustrating when creating puppets for Adobe Character Animator *. That is because each layer contains lots of sublayers, which also inherit the suffix copy at their layer name when the parent layer is duplicated.
The Main Idea
Remove unwanted text from hundreds of layers in a single click instead of wasting hours doing it manually.
The Problem Explained
When creating puppets, the illustration created in Adobe Illustrator * must follow a very strict hierarchy and naming rules to later function properly in Adobe Character Animator. That hierarchy includes many (sometimes hundreds or even thousands) of sublayers.
Duplicating one view of a character and adjusting it to be used as a new view is a part of a standard workflow. The problem is that once you duplicate one of the views which include lots of sublayers, all those sublayers, and their children get the copy suffix at their layer name.
This results in hundreds of layers with an unwanted suffix. Removing it manually can be very frustrating and time-consuming. And in no way can be part of a routine workflow.
This is a result of running the script (provided in this post) for the above example. Although just the front head view of a puppet was duplicated. The suffix copy was added to 2115 layers. Running the script will remove all of those in a single-click operation. Just imagine doing it manually 🤯🤯🤯.
Who Needs this Script?
- Anyone using Adobe Illustrator to create puppets that will be later used in Adobe Character Animator.
- Anyone working on a project that includes duplicating layers with a relatively complex hierarchy as part of their workflow.
How to Use this Script
Once you run the script in Adobe Illustrator a small pop-up window will appear.Â
It looks like this:
To remove the word copy and copy followed by numbers, just press the “Remove All” button. This action will remove the word copy from all layers and sub-layers.
If you use Illustrator in a different language or want to use this plugin for a different purpose just enter a different word in a text field. And press the “Remove all button” afterward.
Works only for Suffix
Please note that the script only searches for the" unwanted" text at the end of each layer name and removes it. If the word Copy is in a middle of a layer name the layer name will not be changed. ( The script does however check for the "unwanted " text followed by a space and a number and removes those options as well).
How to Run Scripts in Adobe Illustrator
There are 2 main ways to run script in Illustrator:
by Going to File --> Scripts --> Other Scripts, and then navigating to where you saved the downloaded .jsx file.
Installing the script into Script Menu
If you plan to use the script regularly. The best way would be to put the download .jsx file into the Adobe Illustrator /presets/scripts folder. This way you will always have the script accessible in your menus.
Script Logic Explained
You can skip this section if you don’t like coding. Â
The script goes over all layers, sublayers and their child sublayers (all sublayers in the hierarchy) and checks if the word copy (as well as copy 1, copy 2, copy 3, etc..) exists at the end of the layer name.Â
The word copy is the default option, but there is an editable text field in the script window which you can edit and enter any word that is relevant to your project.Â
- Define what is the "unwanted" text
var myTextToRemove = myWorkPanel.add ('edittext', undefined, 'copy');
- Convert the "unwanted" text into Regular expression. The regex will define that the unwanted string is placed at the end of a layer name and may be followed by a space and a number.
- Call for a recursive function to go over all layers and sublayers in .ai document hierarchy.
removeUnwantedTextFromLayerName(myTextToRemove.text);
function removeUnwantedTextFromLayerName(unwantedString){
totalLayersToRemoveFrom=0;
//Turn Unwanted string to Regex
var fullRegexToRemove=new RegExp('\\s'+unwantedString+'(\\s\\d{1,})?$','g');
//Remove from all layers and sublayers
try { findLayersAndRemoveRegex(undefined,fullRegexToRemove);} catch(e) {}
return totalLayersToRemoveFrom;
}
- If the the function runs for the firs time, get all the parent layers from the active document.
- If layer name includes the unwanted regex --> remove it.
- If layer has sublayers, run the same function on all sublayers.
function findLayersAndRemoveRegex(layersList,regexToRemove) {
if(!layersList) layersList = app.activeDocument.layers;
for (var i = 0; i < layersList.length; i++) {
layersList[i].name = layersList[i].name.replace(regexToRemove, '');
totalLayersToRemoveFrom++;
if (layersList[i].layers.length) findLayersAndRemoveRegex(layersList[i].layers,regexToRemove)
}
}
Shop Related Products:
- Facebook32
- Twitter2
- Pinterest1
- Email0
- Subscribe
- 35shares
- Like
- Digg
- Del
- Tumblr
- VKontakte
- Buffer
- Love This
- Odnoklassniki
- Meneame
- Blogger
- Amazon
- Yahoo Mail
- Gmail
- AOL
- Newsvine
- HackerNews
- Evernote
- MySpace
- Mail.ru
- Viadeo
- Line
- Comments
- Yummly
- SMS
- Viber
- Telegram
- Subscribe
- Skype
- Facebook Messenger
- Kakao
- LiveJournal
- Yammer
- Edgar
- Fintel
- Mix
- Instapaper
- Copy Link