• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Batch renaming sub-layers in Illustrator

Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hello, I have hundreds of files that require layers renaming from target1 at the bottom of the layers list to the top in sequential order. For example: target1, target 2, target 3 until it reaches the top. I've searched high and low for a script for this, does anyone have one I can use? 

 

Thanks in advance for any help.

 

Illustrator Layers.JPG

TOPICS
Scripting

Views

510

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Oct 16, 2021 Oct 16, 2021

This one almost does it: 

 

var ItemRenamer, itemRenamer;

ItemRenamer = (function() {
function ItemRenamer() {

if ( app.activeDocument.selection.length > 0 ) {

this.replacements = [
prompt( 'What would you like to replace?\nEmpty if you are renaming instead of replacing.', 'Eg: source.' ),
prompt( 'What would you like to replace it with?\nUse %i placeholder to auto-increment naming. "name-%i" will name items: "name-1", "name-2", etc.', 'Eg: replacement, or replacement-%i' )
];

this.renameItems( app.active

...

Votes

Translate

Translate
Adobe
Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

 They could also be objects/paths this is what it looks like from the top if that helps.

Twinkl5C5F_0-1634381111041.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

This one almost does it: 

 

var ItemRenamer, itemRenamer;

ItemRenamer = (function() {
function ItemRenamer() {

if ( app.activeDocument.selection.length > 0 ) {

this.replacements = [
prompt( 'What would you like to replace?\nEmpty if you are renaming instead of replacing.', 'Eg: source.' ),
prompt( 'What would you like to replace it with?\nUse %i placeholder to auto-increment naming. "name-%i" will name items: "name-1", "name-2", etc.', 'Eg: replacement, or replacement-%i' )
];

this.renameItems( app.activeDocument.selection );

} else {
alert( 'Select the items you would like to be renamed. You can select a Layer to rename all the items inside it.' );
}
}

ItemRenamer.prototype.renameItems = function( items ) {
var _i, _results, counting, regxp;

_results = [];
regxp = new RegExp( '%i', 'i' );
counting = this.replacements[1].match( regxp ) ? prompt( 'Start counting at:', '1' ) : 0;

for (_i = 0; _i < items.length; _i++) {
nb = parseInt( _i ) + parseInt( counting );
origin = this.replacements[0];
replacement = this.replacements[1].match( regxp ) ? this.replacements[1].replace( regxp, ( '' + nb ) ) : this.replacements[1];

// Renaming.
if ( origin === '' ) {
_results.push( items[_i].name = replacement );
}
// Replacing.
else {
_results.push( items[_i].name = items[_i].name.replace( origin, replacement ) );
}
}

return _results;
};

return ItemRenamer;

})();

itemRenamer = new ItemRenamer();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

This works if you refresh it. I then reversed the layer order using the 'reverse order' option in the layer menu.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

LATEST

You may also try this approach provided by Sergey Osokin.

 

https://github.com/creold/illustrator-scripts#renameitems

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines