26 Replies Latest reply on Dec 16, 2013 6:09 AM by ThinkingThings

    script to put artboard names in text boxes

    Petros_ Level 1

      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_

        • 1. Re: script to put artboard names in text boxes
          Gustavo Del Vechio Level 3

          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.

          • 2. Re: script to put artboard names in text boxes
            Petros_ Level 1

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

            • 3. Re: script to put artboard names in text boxes
              Gustavo Del Vechio Level 3

              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.

              • 4. Re: script to put artboard names in text boxes
                CarlosCanto Adobe Community Professional & MVP

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

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

                • 5. Re: script to put artboard names in text boxes
                  CarlosCanto Adobe Community Professional & MVP

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

                  • 6. Re: script to put artboard names in text boxes
                    Petros_ Level 1

                    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

                    • 7. Re: script to put artboard names in text boxes
                      ThinkingThings Level 1

                      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
                      
                      • 8. Re: script to put artboard names in text boxes
                        Petros_ Level 1

                        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
                        
                        
                        • 9. Re: script to put artboard names in text boxes
                          Petros_ Level 1

                          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

                          • 10. Re: script to put artboard names in text boxes
                            Larry G. Schneider Adobe Community Professional & MVP

                            Try

                             

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

                            • 11. Re: script to put artboard names in text boxes
                              Petros_ Level 1

                              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[i];
                                
                                        // 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
                              
                              
                              • 12. Re: script to put artboard names in text boxes
                                CarlosCanto Adobe Community Professional & MVP

                                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.

                                1 person found this helpful
                                • 13. Re: script to put artboard names in text boxes
                                  ThinkingThings Level 1

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

                                  • 14. Re: script to put artboard names in text boxes
                                    Petros_ Level 1

                                    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_

                                    • 15. Re: script to put artboard names in text boxes
                                      Petros_ Level 1

                                      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[i];
                                        
                                                // 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.

                                      • 16. Re: script to put artboard names in text boxes
                                        CarlosCanto Adobe Community Professional & MVP

                                        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

                                        • 17. Re: script to put artboard names in text boxes
                                          CarlosCanto Adobe Community Professional & MVP

                                          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.

                                          • 18. Re: script to put artboard names in text boxes
                                            ThinkingThings Level 1

                                            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.

                                            • 19. Re: script to put artboard names in text boxes
                                              CarlosCanto Adobe Community Professional & MVP

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

                                              • 20. Re: script to put artboard names in text boxes
                                                ThinkingThings Level 1

                                                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

                                                • 21. Re: script to put artboard names in text boxes
                                                  CarlosCanto Adobe Community Professional & MVP

                                                  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.

                                                  • 22. Re: script to put artboard names in text boxes
                                                    ThinkingThings Level 1

                                                    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

                                                    • 23. Re: script to put artboard names in text boxes
                                                      CarlosCanto Adobe Community Professional & MVP

                                                      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.

                                                      • 24. Re: script to put artboard names in text boxes
                                                        ThinkingThings Level 1

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

                                                        • 25. Re: script to put artboard names in text boxes
                                                          Petros_ Level 1

                                                          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?

                                                          • 26. Re: script to put artboard names in text boxes
                                                            ThinkingThings Level 1

                                                            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