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

Automatically generate text labels with name of shape

New Here ,
Jun 06, 2022 Jun 06, 2022

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...

defaulteb2kek6295tr_0-1654519940837.pngexpand image
In to this;

defaulteb2kek6295tr_1-1654520038749.pngexpand image


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?

 

TOPICS
Draw and design , Feature request , Scripting , Tools
1.4K
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 , Jun 06, 2022 Jun 06, 2022

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+
...
Translate
Adobe
Community Expert ,
Jun 06, 2022 Jun 06, 2022

Hi, you can use an action to make it and apply to your files...regards

Ali Sajjad / Graphic Design Trainer / Freelancer / Adobe Certified Professional
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
New Here ,
Jun 06, 2022 Jun 06, 2022

Not sure this is possibile unfortunately - Actions recorder doesn't have the capability to grab shape names as far as I can tell. 

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 ,
Jun 06, 2022 Jun 06, 2022

No, this cannot be done with an action.

 

A script or a custom plugin would be required.

 

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 ,
Jun 06, 2022 Jun 06, 2022

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();

 

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
New Here ,
Jun 07, 2022 Jun 07, 2022

CarlosCanto - that's excellent and does exactly what I was after. Thanks very much. Get in touch, I owe you a coffee/beer. 

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 ,
Jun 07, 2022 Jun 07, 2022
LATEST

sapporoBeer.jpgexpand image

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