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

script to put artboard names in text boxes

Participant ,
Dec 02, 2013 Dec 02, 2013

Hi there. I have an Illustrator document with ~100 artboards, each artboard named by me. Each artboard has one textbox in it. Is there a way to take whatever name I assign to the artboard and print it into the text box inside that artboard? So in the end I would be able to see the name associated with each artboard on the artboard itself. Ideally I could run the script once (i.e. "turn it on"), have it populate all the text boxes with the artboard names, and then have it dynamically update the textboxes when I change an artboard name regardless of whether the file has been closed and opened since I originally ran the script.

Maybe this is more of a plugin? Either way I don't have any idea how to approach the problem, nor much scripting experience (I've tried several times, but never succeeded! ).

Petros_

TOPICS
Scripting
13.5K
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
Adobe
Community Expert ,
Dec 02, 2013 Dec 02, 2013

Suppose I could feature request it, but what are the chances...

...based on history, I wouldn't hold my breath.

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 ,
Dec 02, 2013 Dec 02, 2013

Suppose I could feature request it, but what are the chances...

...you'll have better chances adding a feature request here

http://forums.adobe.com/thread/1013711

I don't promise it'll be quick, but it is coming...

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 ,
Nov 26, 2020 Nov 26, 2020

I created script which is working as expected:

// This script generates artboard names captions below each artboard.
// it take artboard name and generates TextArea under artboard aligned
// center in white color / font size 12pt.

var myDocument = app.activeDocument;
for (var i = 0; i < myDocument.artboards.length; i++) {

	var artboard = app.activeDocument.artboards[i];
	var leftA = artboard.artboardRect[0];
	var topA = artboard.artboardRect[1];
	var rightA = artboard.artboardRect[2];
	var bottomA = artboard.artboardRect[3];
	var widthA = Math.abs(rightA - leftA);  

	// For each artboard, add a new text area of sizes and position below
	var l = leftA;
	var t = bottomA >= 0 ? bottomA + 5 : bottomA - 5; // 5pt from the bottom edge of Artboard
	var w = widthA
	var h = 30;
	
	var rectRef = myDocument.pathItems.rectangle(t, l, w, h); // rectangle which will become text area
	var myLabel = myDocument.textFrames.areaText(rectRef);  

	var color = new RGBColor();
	color.red = 255;
	color.green = 255;
	color.blue = 255;

	// make it be area type instead of point type

	// fill it with the artboard name
	myLabel.contents = artboard.name;


	// this line controls the font size

	myLabel.textRange.characterAttributes.size = 12;

	if(myLabel.textRange.length > 0)
	{
		var current_paragraphs = myLabel.textRange.paragraphs;
		for (j = 0; j < current_paragraphs.length; j++)
		{
			if(current_paragraphs[j].characters.length > 0)
			{
				current_paragraphs[j].fillColor = color;
				current_paragraphs[j].hyphenation = false;
				current_paragraphs[j].justification = Justification.CENTER;
			}
		}
	}  

}
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 ,
Dec 02, 2020 Dec 02, 2020

This is great, is there anyway to change the position of the text and add a background behind it?

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 ,
Dec 02, 2020 Dec 02, 2020

If you need do something more with script, I added some more parametrization for it 😛 

You welcome!

 

// This script generates artboard names captions below each artboard.
// it take artboard name and generates TextArea under artboard aligned
// center in white color / font size 12pt.

// ------------------------------------------------------------------ Some i params

var labelsWidth = 100; // width in % of the parent artboard width
                       // if there will be left/right margins added,
                       // this will be adjusted to the width left after adding margins

var labelFontSize = 12;
var labelHeight = labelFontSize * 2 + labelFontSize/3; // fixed height of the label

var labelsMargin = {
    top: 5,    // top label margin in pt (user when labels are below artboards)
    left: 0,   // left label margin in pt
    right: 0,  // right label margin in pt
    bottom: 5  // top label margin in pt (user when labels are above artboards)
};

var labelsBelowArtboard = false; // if false labels will be above artboards

var labelTextColor = '#FFFFFF';
var labelBackgroundColor = null; // null for transparent
var textAlignment = Justification.CENTER; // possibilities LEFT, RIGHT, CENTER, FULLJUSTIFY...and more

// --------------------------------------------------------------------

function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex.toLowerCase());
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}

function doJob() {
    var myDocument = app.activeDocument;
    for (var i = 0; i < myDocument.artboards.length; i++) {

        var artboard = app.activeDocument.artboards[i];
        var leftA = artboard.artboardRect[0];
        var topA = artboard.artboardRect[1];
        var rightA = artboard.artboardRect[2];
        var bottomA = artboard.artboardRect[3];
        var widthA = Math.abs(rightA - leftA);

        // consider margins

        // For each artboard, add a new text area of sizes and position below
        var l = leftA + labelsMargin.left;
        var w = (widthA - labelsMargin.right - labelsMargin.left) * labelsWidth / 100.0; // use percentage width of artboard
        var h = labelHeight;

        // center label between margins - make it look nicer
        l += (widthA - labelsMargin.right - labelsMargin.left - w) / 2;

        if (labelsBelowArtboard) {
            var t = bottomA - labelsMargin.top;
        } else {
            var t = topA + labelsMargin.bottom + h;
        }

        // background color
        if (labelBackgroundColor != null) {
            var bkgRectRef = myDocument.pathItems.rectangle(t, l, w, h); // rectangle of background
            var backgroundColor = new RGBColor();
            var rgbColor = hexToRgb(labelBackgroundColor);
            backgroundColor.red = rgbColor.r;
            backgroundColor.green = rgbColor.g;
            backgroundColor.blue = rgbColor.b;
            bkgRectRef.filled = true;
            bkgRectRef.fillColor = backgroundColor;
        }

        var rectRef = myDocument.pathItems.rectangle(t, l, w, h); // rectangle which will become text area
        var myLabel = myDocument.textFrames.areaText(rectRef);

        // text color
        var textColor = new RGBColor();
        var rgbColorOfText = hexToRgb(labelTextColor);
        textColor.red = rgbColorOfText.r;
        textColor.green = rgbColorOfText.g;
        textColor.blue = rgbColorOfText.b;

        // fill it with the artboard name
        myLabel.contents = artboard.name;

        // this line controls the font size
        myLabel.textRange.characterAttributes.size = labelFontSize;

        if (myLabel.textRange.length > 0) {
            var current_paragraphs = myLabel.textRange.paragraphs;
            for (j = 0; j < current_paragraphs.length; j++) {
                if (current_paragraphs[j].characters.length > 0) {
                    current_paragraphs[j].fillColor = textColor;
                    current_paragraphs[j].hyphenation = false;
                    current_paragraphs[j].justification = textAlignment;
                }
            }
        }

    }
}

// RUN IT !
doJob();
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 ,
Dec 02, 2020 Dec 02, 2020

The script I added has one lack, I couldn't find a way to align text vertically. Normally it is available from UI, but I couldn't make it work. I wanted to have bottom aligned text when label is above artboard.

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 ,
Dec 02, 2020 Dec 02, 2020

Sorry one other request, would it be possible to have vertical align centrally to the text box (As in the area type box options)?

 

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 ,
Dec 02, 2020 Dec 02, 2020
LATEST

That is the problem I described above in my comment. I couldn't find a way to mak it work. There are options for it, but simple don't work. I guess there must be some conditions met before I can vertically align the text area. Sorry, for now, you can seelct all labels and click this alignment by hand 😕

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