Copy link to clipboard
Copied
Hi all,
I'm looking for a way in Illuastrator to be able to add some text, automatically to hundreds of boxes/shapes on the basis of the name of the shape. The text would ideally be centered to it's corresponding shape.
For example, to turn this...
In to this;
Am I missing something already existing? There are some mucky work arounds involving exporting .svgs of boxes and writing .svgs with text, but I feel there must be a way to do this all internally within illustrator but this seems the realm of some scripting, which is a bit beyond me!
Any thoughts?
1 Correct answer
try this script, this version will name pathItems in a layer named "Layer 1" only
// label boxes
// https://community.adobe.com/t5/illustrator-discussions/automatically-generate-text-labels-with-name-of-shape/td-p/12987454
function main() {
var idoc = app.activeDocument;
var layer1 = idoc.layers["Layer 1"];
var textLayer = idoc.layers.add();
textLayer.name = "Text";
var pItems = layer1.pathItems;
var tframe, pItem;
for (var a=0; a<pItems.length; a+
...
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi, you can use an action to make it and apply to your files...regards
Copy link to clipboard
Copied
Not sure this is possibile unfortunately - Actions recorder doesn't have the capability to grab shape names as far as I can tell.
Copy link to clipboard
Copied
No, this cannot be done with an action.
A script or a custom plugin would be required.
Copy link to clipboard
Copied
try this script, this version will name pathItems in a layer named "Layer 1" only
// label boxes
// https://community.adobe.com/t5/illustrator-discussions/automatically-generate-text-labels-with-name-of-shape/td-p/12987454
function main() {
var idoc = app.activeDocument;
var layer1 = idoc.layers["Layer 1"];
var textLayer = idoc.layers.add();
textLayer.name = "Text";
var pItems = layer1.pathItems;
var tframe, pItem;
for (var a=0; a<pItems.length; a++) {
pItem = pItems[a];
tframe = textLayer.textFrames.add();
tframe.contents = pItem.name || "Not Named";
tframe.textRange.paragraphAttributes.justification = Justification.CENTER;
tframe.position = [pItem.left + pItem.width/2 - tframe.width/2, pItem.top - pItem.height/2 + tframe.height/2]
}
}
main();
Copy link to clipboard
Copied
CarlosCanto - that's excellent and does exactly what I was after. Thanks very much. Get in touch, I owe you a coffee/beer.
Copy link to clipboard
Copied

