Script to Rename Artboards Based on Layers (and Reverse)
A couple of years ago I had some awesome help making a couple of scripts to rename layers based on the containing artboard (Re: Script to Rename Artboards with Layer Names). One problem posed (and solved) was:
- Each artboard has a name.
- Each layer NEEDS a name.
- There are an equal number of layers and artboards.
- Only one layer "exists" on each artboard. (i.e. They share coordinates.)
- I would like to name the layer with the same name as its encompassing artboard.
The solution was:
function artboardLayerNameMatch() {
if (app.documents.length == 0) {
alert("No Open / Active Document Found");
} else {
var doc, i, l, ab, sel, n;
doc = app.activeDocument;
for (i = 0, l = doc.artboards.length; i < l; i++) {
ab = doc.artboards;
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
sel = doc.selection[0];
sel.parent.name = ab.name;
doc.selection = false;
}
}
}
artboardLayerNameMatch();
Now, I'm wondering if the reverse is also possible?
The new scenario is:
- Each layer has a name.
- Each artboard NEEDS a name.
- There are an equal number of layers and artboards.
- Only one layer "exists" on each artboard. (i.e. They share coordinates.)
- I would like to name the artboard with the same name as the layer that resides “on” it
