script to put artboard names in text boxes

Participant ,
Dec 02, 2013

Copy link to clipboard

Copied

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

Views

7.2K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

script to put artboard names in text boxes

Participant ,
Dec 02, 2013

Copy link to clipboard

Copied

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

Views

7.2K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 02, 2013 1
Advocate ,
Dec 02, 2013

Copy link to clipboard

Copied

Hi Petros

Yes, JavaScript can read the name of each artboard.

Try to develop your script and post your code here. So we can help you to correct the necessary problems.

A tip. I think the best way to develop such script is:

1. Make a loop that cycle between all the artboards.

2. In the loop, take the artboard name.

3. Create a new textFrame item and apply the artboard name as the content of this new object. also, define formatting properties for the text

4. Position the textFrame were you want in the artboard.

This would get what you need.

Best Regards

Gustavo.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2013 0
Participant ,
Dec 02, 2013

Copy link to clipboard

Copied

It would be rad if Illustrator had a user-friendly scripting gui like Cinema4D has in the form of xpresso. Xpresso is rad. You can literally drop references to objects into the xpresso window, then find and link the attributes. For instance, if I were doing this same type of thing in Cinema4D I would simply drop the artboard and the text field into xpresso, create an outgoing port in the artboard for artboard name, and then drag and drop that onto an incoming port on the text field for text entry. Illustrator could be this cool. Suppose I could feature request it, but what are the chances...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2013 0
Advocate ,
Dec 02, 2013

Copy link to clipboard

Copied

Petros

The scripting guides for Adobe Illustrator (http://www.adobe.com/devnet/illustrator/scripting.html) as well as other Adobe application's scripting guides are very clear on explaining properties and methods we can use with JavaSscript, Apple Script and VB Script.

The scripting supposes you already know the programming language, so it's very useful and easy to understand the explanations and descriptions.

Best Regards

Gustavo.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2013 0
Adobe Community Professional ,
Dec 02, 2013

Copy link to clipboard

Copied

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

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2013 0
Adobe Community Professional ,
Dec 02, 2013

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2013 0
Participant ,
Dec 06, 2013

Copy link to clipboard

Copied

This is pretty wonky, but here's the garble I have so far. I've read through the Scripting Guide, and opened the Scripting Reference, but it's probably clear I really have no idea what I'm doing. Any more tips?

// This script should display the artboard names at the bottom of each artboard

// It should create a direct link between the strings displayed in every artboard

// and the user-entry occurring in the artboard palette

// Get the active document

var docRef = app.activeDocument;

// STEP ONE: Create the text frames for each artboard

// Cycle through the artboards, grab their names, and create new text frames

for (artboard.length; )

{

          var labelFrame = myDocument.textFrames.add();

}

labelFrame.position = [0,0];

labelFrame.contents = artboard.string;

// Position this text frame in the bottom center of the first artboard at 100% width and 2 lines worth of text for height

// STEP TWO: Update a text frame to reflect changes the user has made to the artboard names

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 06, 2013 0
Engaged ,
Dec 06, 2013

Copy link to clipboard

Copied

Wonky. I really like that.

Here's some VB.NET code to help you if you can convert it to JS -- well it's either going to help you or confuse the heck out of you. I hope it's the former. This code dosen't do everything that you want, like place the artboard name at the bottom with an additional blank line (or that's what I understood) but it names each artboard. I had really hoped to complete it more for you but ran out of time. Like I said -- I hope that it helps.

-TT

 Dim aDoc As AI.Document = app.ActiveDocument

  For i = 1 To aDoc.Artboards.Count

   Dim ab As AI.Artboard = aDoc.Artboards(i)

   Dim abRect = ab.ArtboardRect

   ab.RulerOrigin = {abRect(0), abRect(1)}

   Dim pi As AI.PathItem = aDoc.PathItems.Rectangle(abRect(1), abRect(0), abRect(2) - abRect(0), -abRect(3) + abRect(1))

   Dim abText As AI.TextFrame = aDoc.TextFrames.AreaText(pi, 0)

   abText.Contents = ab.Name

   abText.TextRange.ParagraphAttributes.Justification = AiJustification.aiCenter

  Next

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 06, 2013 0
Participant ,
Dec 09, 2013

Copy link to clipboard

Copied

Maybe a little less broken? but still broken. Am I anywhere close to on the right track for this?

// Script function: enable a user to put artboard names on the artboard, and update

// them dynamically (e.g. when you change an artboard name, the label changes too.)

// Tell the script to only work on the open, focused document

var myDocument = app.activeDocument;

// STEP ONE: Create the labels for each artboard

// grab ahold of the artboards

for (var i = 1; myDocument.Artboards.Count; i++)

{

          // For each artboard, add a new text frame

          var myLabel = myDocument.textFrames.add();

 

          // fill it with the artboard name

          myLabel.contents = "artboard.name"

 

          // and put it at this position

          myLabel.position = artboardRect [0,0];

}

// STEP TWO: Update the labels whenever the user makes changes to the artboard names

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Participant ,
Dec 09, 2013

Copy link to clipboard

Copied

Maybe a little less broken? but still broken. Am I anywhere close to on the right track for this?

// Script function: enable a user to put artboard names on the artboard, and update

// them dynamically. E.g. when you change an artboard name, the label changes too.

// Tell the script to only work on the open, focused document

var myDocument = app.activeDocument;

// STEP ONE: Create the labels for each artboard

// grab ahold of the artboards

for (var i = 1; myDocument.Artboards.Count; i++)

{

          // For each artboard, add a new text frame

          var myLabel = myDocument.textFrames.add();

 

          // fill it with the artboard name

          myLabel.contents = "artboard.name"

 

          // and put it at this position

          myLabel.position = artboardRect [0,0];

}

// STEP TWO: Update the labels whenever the user makes changes to the artboard names

I'm sure I'm doing something dumb, because I'm getting this error. No doubt my problem has to do with how I'm trying to call out the artboards.

Screen Shot 2013-12-09 at 3.28.22 PM.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Adobe Community Professional ,
Dec 09, 2013

Copy link to clipboard

Copied

Try

for (var i = 0; i<myDcoument.artboards.count; i++)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Participant ,
Dec 09, 2013

Copy link to clipboard

Copied

thanks Larry. A friend of mine helped me get it working. Still trying to control position and a few other things, plus add the feature to make the text fields update automatically when an artboard name is changed, but hey the basic part is working!

// Script function: enable a user to put artboard names on the artboard, and update

// them dynamically. E.g. when you change an artboard name, the label changes too.

// Tell the script to only work on the open, focused document

var myDocument = app.activeDocument;

// STEP ONE: Create the labels for each artboard

// grab ahold of the artboards

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

{

          var artboard = app.activeDocument.artboards;

 

          // For each artboard, add a new text frame

          var myLabel = myDocument.textFrames.add();

 

          // fill it with the artboard name

          myLabel.contents = artboard.name;

 

          // this line controls the font size

          myLabel.textRange.characterAttributes.size = 4;

 

          // this line positions the text relative to each artboard

          myLabel.position = [artboard.artboardRect[0], artboard.artboardRect[1]];

 

}

// STEP TWO: Update the labels whenever the user makes changes to the artboard names

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Adobe Community Professional ,
Dec 09, 2013

Copy link to clipboard

Copied

plus add the feature to make the text fields update automatically when an artboard name is changed

this won't be possible without human intervention, scripting has no access to events.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 1
Engaged ,
Dec 09, 2013

Copy link to clipboard

Copied

Nice touch Carlos. 🙂  I didn't know that. Thanks -- good to know. Actually I guess I never thought about it. If really necessary, in .NET, I would probably periodically review with an event handler on the .NET side probably using a timer or a threaded while terminated by the closing of the doc, since my .NET code always runs parallel with .AI running. Just the way that I do it (although I think that I'm the only one in the world that does it this way, or even uses .NET for scripting!).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Participant ,
Dec 09, 2013

Copy link to clipboard

Copied

Bummer. Back to my original dream that Illustrator had the capability and node-based gui for doing simple things like this. In Cinema 4D (which, of course, is more complex than Illustrator) I can just add a tag to an object, drag two things (like the null object and the text field) into xpresso, link up the attributes I want linked and voila! The artboard label (in this case a motext object) would be driven by the artboard name (in this case a null object). Handy for simpletons like me who are too A.D.D. for Javascript.

Screen Shot 2013-12-09 at 9.00.51 PM.png

Thanks everyone for your input on this. I think I'll be able to sort of get what I want from the script y'all helped me to cobble together. Cheers!

Petros_

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Participant ,
Dec 09, 2013

Copy link to clipboard

Copied

If it's useful to anyone, here's the script that's working:

//This script takes a document's artboard names and prints them into each artboard.

// Tell the script to only work on the open, focused document

var myDocument = app.activeDocument;

// STEP ONE: Create the labels for each artboard

// grab ahold of the artboards

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

{

          var artboard = app.activeDocument.artboards;

 

          // For each artboard, add a new text frame

          var myLabel = myDocument.textFrames.add();

 

          // 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 = 4;

 

          // this line positions the text relative to each artboard

          myLabel.position = [artboard.artboardRect[0], artboard.artboardRect[1]];

 

}

Any pointers on making the text fields area text instead of point text are appreciated. Same goes for pointers on styling the text from the script, perhaps with the use of an editable paragraph style.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2013 0
Adobe Community Professional ,
Dec 10, 2013

Copy link to clipboard

Copied

Hi TT, do you think you'd be able to pull if off with .NET? if you find the time would you try? nothing major, just a simple text box that auto updates the artboard name whenever it changes...if it works, wouldn't it be too resource demanding?

I used VBA for years for my own projects, then switched to Javascript to share with mac users

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Adobe Community Professional ,
Dec 10, 2013

Copy link to clipboard

Copied

Petros, it'll be nice if illustrator could do that, that sounds like a great help for non-programmers in Cinema 4D...but no, there's lots and lots of thing not accessible to scripting in Illustrator. Photoshop and Indesign are more robust.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Engaged ,
Dec 10, 2013

Copy link to clipboard

Copied

Hey Carlos! I'll see what I can do -- make take a few days to get to it since I've got a lot going on. As far as being too resource demanding... you know if done properly, not at all. I used to think that way too until I learned differently.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Adobe Community Professional ,
Dec 10, 2013

Copy link to clipboard

Copied

no rush, I'm just curios to know, if it works it could open up a whole range of new projects

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Engaged ,
Dec 10, 2013

Copy link to clipboard

Copied

Hi Carlos,

>> no rush, I'm just curios to know, if it works it could open up a whole range of new projects

Seriously? Well THAT moved it to the top of the pile!

SO I have to admit, when a really smart guy (as yourself) asks me to do something that I think is easy, I figure that I've DEFINITELY missed something.   So I hope that I am wrong, but I threw this together in VB.NET and tested it and it works fine. Now there are a number of ways to do this and I am sure that I could refine it and make it more efficient if needed, but it works as a start. I don't know if VBA offers a timer, but if it does I think that it could be implemented fairly easily. If not, since it has to run concurrently with AI, I could compile it and offer it as a small executable but I don't know how others would feel about that. If they have VS 2008 Express or higher (and maybe even lower since there's not too much fancy stuff here) they might be able to opo in this code and compile it themselves.

Now as far as performance is concerned, this is setup for 100 artboards (the AI max). I've run it with 6 and it seems fine. I don't know which benchmark one would use to compare it. I'm open to testing it. I figured that I would stop here, though, just to make sure that you and I are on the same train.

Hope this helps. Let me know.

-TT

Here's the code. Hope it makes sense to you.

Private Sub CompareArtboardNames()
  Dim aDoc As AI.Document = app.ActiveDocument
  Static Dim pass As Integer = 0
  Static lastAbNames(100) As String
  Dim abNames(100) As String
  For i = 1 To aDoc.Artboards.Count
   abNames(i) = aDoc.Artboards(i).Name
   If pass = 0 Then
    lastAbNames(i) = abNames(i)
   Else
    If abNames(i) <> lastAbNames(i) Then
     aDoc.TextFrames.Item("_ChangedText").Contents = lastAbNames(i) & " ----> " & abNames(i)

     lastAbNames(i) = abNames(i)
    End If
   End If
  Next
  pass = 1
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  CompareArtboardNames()
End Sub

Private Sub TestTimerForArtboardNamesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TestTimerForArtboardNamesToolStripMenuItem.Click
  Dim aDoc As AI.Document = app.ActiveDocument
  Dim chgdText As AI.TextFrame = aDoc.TextFrames.Add()
  chgdText.Top = (aDoc.Artboards(1).ArtboardRect(0) - 50)
  chgdText.Left = aDoc.Artboards(1).ArtboardRect(1)
  chgdText.Name = "_ChangedText"
  Timer1.Interval = 1000
  Timer1.Enabled = True
End Sub

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Adobe Community Professional ,
Dec 10, 2013

Copy link to clipboard

Copied

Seriously? Well THAT moved it to the top of the pile!

hahaha, sorry about that and thanks for those kind words

well that's great news, good job,

so, could we freely work on any given file and the textFrame would autoupdate, without us noticing the timer is checking? no lag?

first thing to come to my mind is obviously an autosave script, or another heavily requested feature, a slug script

how different is .NET from VB? I never gave it a try?

oh, vba does not have a timer.

thanks for putting this together.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 10, 2013 0
Engaged ,
Dec 11, 2013

Copy link to clipboard

Copied

Hi Carlos,

Glad to help. Thanks for the kudos.

well that's great news, good job,

so, could we freely work on any given file and the textFrame would autoupdate, without us noticing the timer is checking? no lag?

The code would have to modified just a bit to check for a new active document, but easily doable. An autosave should be easy, a slug script -- what did you have in mind?

how different is .NET from VB? I never gave it a try

VB.NET vs VBA or VB.NET vs VB (like V4)? I suspect that you would have little problems. I've seen your code and watched your thinking played out in the forum so, yeah, no sweat. Brain surgery is easy if you know what you are doing too, right? (apologies to all the brain surgeons out there...). Very similar, but WAY more robust. So my offer still stands -- at the AI Scripting Forum Christmas party, we'll find a quiet little corner and I'll teach you .NET and you teach me VBA. 15 minutes, tops. Whadda ya say? 😉

If you would like, shoot me a PM and I'll make a few fixes and compile it for you, then you can try it out yourself.

Best regards,

-TT

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2013 0
Adobe Community Professional ,
Dec 11, 2013

Copy link to clipboard

Copied

hahaha, the Christmas party, we have a deal

I'll get the Express edition and give your code a try...but not now, I'm kind of busy these days, but I'll definitely revisit this topic as soon as I can.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2013 0
Engaged ,
Dec 11, 2013

Copy link to clipboard

Copied

<smile> Deal! 😉 Let me know if I can help. It would be my pleasure.  - TT

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2013 0
Participant ,
Dec 15, 2013

Copy link to clipboard

Copied

Hmm, now I kind of want to have the artboard names driven by the text inside the text box located within the artboard instead of vice versa. Any ideas about how to access the text inside an existing text box? And/or finding a textbox inside the bounds of an artboard?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2013 0
Engaged ,
Dec 16, 2013

Copy link to clipboard

Copied

Search TextRange.Contents in the Scripting Reference PDF for accessing the text box text. As far as finding a particular textbox to use as a source, we'll need some more info on what we have to work with. Try to figure out what you think would be the best way to "snag" a particular entity and we can go from there. If it is possible to post an example, that would be helpful too. You can PM me one if you feel more comfortable. But please try to give this some thought yourself first.

-TT

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 16, 2013 0
Explorer ,
Nov 26, 2020

Copy link to clipboard

Copied

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;
			}
		}
	}  

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 26, 2020 0
Community Beginner ,
Dec 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2020 0
Explorer ,
Dec 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2020 0
Explorer ,
Dec 02, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2020 1
Community Beginner ,
Dec 02, 2020

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2020 0
Explorer ,
Dec 02, 2020

Copy link to clipboard

Copied

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 😕

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2020 0
Resources