Skip to main content
Monfa
Participant
July 26, 2018
Answered

Rename Objects with the Fill Color name

  • July 26, 2018
  • 1 reply
  • 780 views

Hi, trying to improve the processes, I'm looking for a way to assign names to each object in a layer with the name of the fill color. I have already managed to change the names of the objects, but I want it to be an automatic process: When selecting the objects, it will be renamed according to its fill color.

Using a very simple code for each individual color:

var docRef = activeDocument;  

var sel = docRef.selection;  

for (var i=0; i < sel.length; i++)  

     sel.name = "Color20" ;

But I need the name to be taken from the fill color

To each object

This topic has been closed for replies.
Correct answer Silly-V

Greeetings, I hope this solution is going to work for this problem!

Please try it.

It assumes your selection items are path items!

    var docRef = activeDocument;

    var sel = docRef.selection;

    var storedSel = [];

    for (var i=0; i < sel.length; i++){ // collect selection into a custom memory array

        storedSel.push(sel);

    }

    docRef.selection = null; // clear the selection

    var assocSwatch;

    for (var i=0; i < storedSel.length; i++){ // select items one by one and get selected swatches in swathc panel

        storedSel.selected =  true;

        assocSwatch = docRef.swatches.getSelected()[0];

        storedSel.name = assocSwatch.name;

        docRef.selection = null;

    }

1 reply

Silly-V
Silly-VCorrect answer
Legend
July 27, 2018

Greeetings, I hope this solution is going to work for this problem!

Please try it.

It assumes your selection items are path items!

    var docRef = activeDocument;

    var sel = docRef.selection;

    var storedSel = [];

    for (var i=0; i < sel.length; i++){ // collect selection into a custom memory array

        storedSel.push(sel);

    }

    docRef.selection = null; // clear the selection

    var assocSwatch;

    for (var i=0; i < storedSel.length; i++){ // select items one by one and get selected swatches in swathc panel

        storedSel.selected =  true;

        assocSwatch = docRef.swatches.getSelected()[0];

        storedSel.name = assocSwatch.name;

        docRef.selection = null;

    }

Monfa
MonfaAuthor
Participant
July 27, 2018

Amazing. It works in all tests, in more than 500 objects and 20 colors: it takes some time, but there is no comparison with my old process of change one by one. Thanks