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

Looking for a way to rename Indesign Layers in bulk.

Explorer ,
Jan 13, 2024 Jan 13, 2024

Hi all,

I use Indesign daily and am always looking for a way to rename layers in bulk. I've scoured the boards and plugin market place but can't quite seem to find anything that fits the bill.

One of the main things I use it for is exporting of files built with a specific naming structure so they can be use by another script. This script looks for page number call outs and then exports based on that, an example would be...

 

Object1>1

Object2>1

Object3>1

etc.

 

The ( >1) is telling the script which page to find the graphic and do its thing.

Sometimes this involves dozens of layers, and if there is a change i have to manually go in and change the page number on each layer 1 by 1. I was hoping to find something that would let you bulk rename layers and possible a find a replace to boot. Something similar to this program (but for layers) would be great....

 

https://www.publicspace.net/ABetterFinderRename/index.html

 

I know it's a long shot but I was hoping someone in the forums might point me in the right direction.

Best,

Matt

TOPICS
Feature request , Scripting
597
Translate
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 Expert , Jan 13, 2024 Jan 13, 2024

Hi @Little_Matty, I have written a script that gives a great ability for renaming things, especially if you have a good text editor. I'm not sure if this is exactly what you want, but I couldn't resist sharing it here because I use this A LOT and find it very useful.

 

1. Run script (see below). You will see a large edit window with each item on a line of text.

2. Make changes to the text, any way you like, but keep the same number of lines (the line order is consequential). 

Personally, I copy/

...
Translate
Community Expert ,
Jan 13, 2024 Jan 13, 2024

Those are not layers, they are simply objects.

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

looks for page number call outs

 

Hi @Little_Matty , As Bob suggests, a text frame is not a Layer, it is a page item. The active page’s page items are listed in the Layers panel when the containing layer is toggled open. Here page 3 is active so Layer 1’s page items are listed:

 

Screen Shot 7.png

 

Page 5 contains no page items so when I make it active no page items are listed:

 

Screen Shot 8.png

 

 

You can rename page items via scripting, but there would have to be a way to determine which items you want to rename and what their new name should be.

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

Hi @Little_Matty, I have written a script that gives a great ability for renaming things, especially if you have a good text editor. I'm not sure if this is exactly what you want, but I couldn't resist sharing it here because I use this A LOT and find it very useful.

 

1. Run script (see below). You will see a large edit window with each item on a line of text.

2. Make changes to the text, any way you like, but keep the same number of lines (the line order is consequential). 

Personally, I copy/paste into the free VSCode because it has *excellent* text editing features including multi-line editing and regular expression find/change. When you're finished editing, copy/paste the text back into the script window.

3. Press Apply button.

 

So, if you want to name Page Items, here is the script:

/**
 * Edit Page Item Names As Text.js
 * Can easily be re-purposed to change other properties as text.
 * Change `settings.description`, `settings.things` and `settings.prop`.
 * @author m1b
 * @version 2024-01-14
 * @discussion https://community.adobe.com/t5/indesign-discussions/looking-for-a-way-to-rename-indesign-layers-in-bulk/m-p/14353655
 */
(function () {

    var settings = {
        description: 'Rename Page Items',
        things: app.activeDocument.pageItems,
        prop: 'name',
        before: [],
        after: [],
    };

    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, settings.description);


    /**
     * Sets properties according to `settings` global object.
     * @author m1b
     * @version 2024-01-14
     */
    function main() {

        if (!settings.things)
            return alert('Sorry there are no things for "' + settings.description + '".');

        if ('function' === typeof settings.things.everyItem)
            settings.before = settings.things.everyItem()[settings.prop];

        if ('Array' === settings.things.constructor.name)
            for (var i = 0; i < settings.things.length; i++)
                settings.before[i] = settings.things[i][settings.prop];

        // show UI
        while (settings.before.length !== settings.after.length)
            if (ui(settings) == 2)
                return;

        // set the properties
        for (var i = settings.before.length - 1; i >= 0; i--)
            if (settings.things[i][settings.prop] != settings.after[i])
                settings.things[i][settings.prop] = settings.areNumbers
                    ? Number(settings.after[i])
                    : settings.after[i];

    };

})();


/**
 * UI with large text edit field.
 * Will update `settings.after` with
 * final edited text, which must
 * contain the same number of lines
 * as `settings.before`.
 * @author m1b
 * @version 2024-01-14
 * @param {Object} settings
 * @param {Array<String>} settings.before - the before array of strings.
 * @param {Array<String>} [settings.description] - a short description of what's going to happen (default: none).
 * @returns {Number} - ScriptUI result code (1 = good, 2 = user cancelled).
 */
function ui(settings) {

    var count = settings.before.length,
        text = settings.before.join('\n');

    var w = new Window("dialog", 'Editor by m1b'),
        title = undefined == settings.description ? '' : settings.description + ' - ',
        intro = w.add('statictext', undefined, title + 'Important: must have ' + count + ' lines.', { alignment: 'left' }),
        textArea = w.add('edittext', undefined, text, { multiline: true, scrolling: true }),
        row = w.add("Group {orientation:'row', alignment:['right','top'] }"),
        cancelButton = row.add('button', undefined, 'Cancel', { name: 'cancel' }),
        okButton = row.add('button', undefined, 'Apply', { name: 'ok' });

    textArea.preferredSize.height = w.maximumSize.height - 400;
    textArea.preferredSize.width = 600;
    textArea.minimumSize.height = 250;
    textArea.minimumSize.width = 200;

    okButton.onClick = function () {

        settings.after = textArea.text.split('\n');

        if (count !== settings.after.length)
            return alert('There must be '
                + count + ' lines of text, but there are '
                + settings.after.length + ' lines. Please fix and try again.');

        w.close(1);

    };

    w.center();
    return w.show();

};

 Important note: many page items won't have a name to start with, so they will appear on a blank line and you must keep the same number of lines when Applying.

 

This is a very flexible script, so if you actually do want to rename Layers, just make settings look like this:

 

var settings = {
    description: 'Rename Layers',
    things: app.activeDocument.layers,
    prop: 'name',
    before: [],
    after: [],
};

 

 

If you want to rename, say, Paragraph Styles, make settings look like this:

 

var settings = {
    description: 'Rename Paragraph Styles',
    things: app.activeDocument.allParagraphStyles,
    prop: 'name',
    before: [],
    after: [],
};

 

 

Just for crazy demo, select a small amount of text or text frame and try this:

var settings = {
    description: 'Set Character Sizes',
    things: app.activeDocument.selection
        && app.activeDocument.selection[0]
        && app.activeDocument.selection[0].characters,       
    prop: 'pointSize',
    areNumbers: true,
    before: [],
    after: [],
};

 

Anyway, if you find this script useful, please let me know. It's pretty bare bones, so feel free to elaborate on it, too.

- Mark

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

If you work on a PC - you could use my ID-Tasker - even free version would let you do a lot.

 

As pointed out by others - those are Objects not Layers - so, if you are on a PC and let me know what is your workflow - I could add new "rules" just for you.

 

Translate
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
Explorer ,
Jan 13, 2024 Jan 13, 2024

Thank you for the replys. Just for clarification, I was just using the word object as an example of a layer name not an actual object . This is definitely a layer need, not for renaming of objects, sorry for the confusion. 
@m1b , thank you for the script. I'll plug it in and get back to you with the results.

Translate
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
Explorer ,
Jan 13, 2024 Jan 13, 2024

@Robert at ID-Tasker  Mac not PC Unfortunately.

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

Okay, give it a try, but don't forget to change the settings object to the Layers option I gave. - Mark

Translate
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 ,
Jan 14, 2024 Jan 14, 2024

Can you show a screen capture of your Layers panel and give some more details on how you typically rename the Layers?  In your example do you mean the Layer name (not the actual page number object) is Object1>1 and you want to rename it to NewObject1>1

Translate
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
Explorer ,
Jan 14, 2024 Jan 14, 2024

I can't show an exact screenshot of a working file but here is a basic example if if helps clarify.

@m1b That worked perfectly. Very useful!

Thanks all!

-Matt

Translate
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
Explorer ,
Jan 14, 2024 Jan 14, 2024
LATEST

An example of a change needed would be that stuff is shuffled around and now I need to indicate that all my layers are pointing at page 5 instead of  1. Currently I would manually have to go through and rename ">1" to ">5". Sometimes the files can get pretty large with lots of layers so it can be tedious.

Translate
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