12 Replies Latest reply on Nov 2, 2012 3:48 PM by pixxxel schubser

    How do I set tabs in textFrames with tabStops?

    HugoTait

      Could anyone show me the javascript syntax, or point me to a script, that sets tabStops and positions them.

       

      I can't get it working.

       

      Please ask if any further clarification or explanation would be usefull.

        • 1. Re: How do I set tabs in textFrames with tabStops?
          Larry G. Schneider Adobe Community Professional & MVP

          You can get info about existing Tab Stops from the Paragraph Attributes but I see no way of setting them by script.

          • 2. Re: How do I set tabs in textFrames with tabStops?
            CarlosCanto Adobe Community Professional & MVP

            I didn't get it to work, but I haven't covered all possibilities yet, what seems to work is to apply a paragraph style with your tab info in it....now, I'm having a hard time creating the paragraph style with the tab info.

             

            post what you have so far

            • 3. Re: How do I set tabs in textFrames with tabStops?
              [Jongware] Most Valuable Participant

              "tabStops" is a property of ParagraphAttributes. It's an r/w array, so shouldn't it be possible to add items to it?

              • 4. Re: How do I set tabs in textFrames with tabStops?
                CarlosCanto Adobe Community Professional & MVP

                JW, don't you remember we're talking about Illustrator where half the things are not accessible and within the half that is, half of it is broken?

                 

                I was able to read the actual tab stop position, set a new tab stop position, read it back to make sure was applied, but nothing seemed to happen to the actual text

                • 5. Re: How do I set tabs in textFrames with tabStops?
                  [Jongware] Most Valuable Participant

                  Ah sorry, Carlos, you're so right

                   

                  Can you show your not-working code?

                  • 6. Re: How do I set tabs in textFrames with tabStops?
                    HugoTait Level 1

                    I see that overnight the JavaScript heavyweights have waded in. Thanks Guys. It seems I can't edit my original post now, so I'm having to reply to it.

                     

                    From what I gather you are saying, I can't create a tabs with a script. But maybe if my template document had a text box containing tabs I could copy the paragraph attributes to a new paragraph and them manipulate the TabStop.position value.  Would that be the way to proceed?

                     

                    Carlos, you asked to see what I'd done so far so here it is!  As you will see I'm an enthusiastic novice with a lot to learn when it comes to javascript, so any comments or suggested improvements anyone cares to make would be most welcome.

                     

                    I am creating ai files containing text and graphic elements created from data in a XML file, mostly these are tabular data. Below is the function that handles the text elements.

                     

                    function layOutText(ele){

                        var eleText;

                        if (ele.@type=="area") {

                            var rectRef = doc.pathItems.rectangle(ele.position[0]/1, ele.position[1]/1, ele.size[0]/1, ele.size[1]/1);

                            eleText = doc.textFrames.areaText(rectRef);       

                            if (ele.@class=="dataTabbed"){

                                var dataArray= new Array ();

                                eleText.contents=splitDataString(ele.value.toString());//this is a call to a function that splits and puts in the command characters for the tabs and

                                eleText.paragraphs[0].paragraphAttributes.tabStops.length=ele.tab.length();

                                for (tab=0; tab<ele.tab.length(); tab++){

                                 eleText.paragraphs[0].paragraphAttributes.tabStops[tab].tabStopsInfo.position=ele.tab[tab ];// this doesn't work

                                    }

                                }

                            else {

                                eleText.contents= ele.value.toString ();

                                }

                            if (eleText.paragraphs)eleText.paragraphs[0].hyphenation=false;

                            }

                        else {

                            eleText = doc.textFrames.add();

                            eleText.position=[ele.position[0]/1, ele.position[1]/1];

                            eleText.contents= ele.value.toString ();

                            }

                     

                        eleText.textRange.characterAttributes.textFont=app.textFonts.getByName(ele.fontStyle.font .toString());

                        eleText.textRange.characterAttributes.fillColor=giveColor(ele.fontStyle.colour.toString() );

                        if (ele.justification.@type=="center") eleText.paragraphs[0].justification = Justification.CENTER;

                        }

                     

                     

                    I am passing it a XML objects that prints out something like

                     

                    <textElement type="area" class="dataTabbed">

                      <value>Benefit t £9,600 t 40% t 23% r Clarins t £7,000 t 10% t -13% r Dior Beaute t £4,500 t 5% t 26% r No7 t £21,500 t -10% t -16% r YSL t £3,200 t -20% t 37%</value>

                      <tab type="left">400</tab>

                      <tab type="left">600</tab>

                      <tab type="left">800</tab>

                      <tab type="left">1000</tab>

                      <tab type="left">1500</tab>

                      <position type="top">275</position>

                      <position type="left">10</position>

                      <size type="width">350</size>

                      <size type="height">140</size>

                      <justification type="left"/>

                      <fontStyle class="data">

                        <font>Tahoma</font>

                        <size>11</size>

                        <colour>black</colour>

                      </fontStyle>

                    </textElement>

                     

                    Thank you.

                    • 7. Re: How do I set tabs in textFrames with tabStops?
                      HugoTait Level 1

                      This is why I presumed it would be possible - but I couldn't make it work and I scoured the net and couldn't find any examples. But as you say reading the reference made it seem like a legitimate thing to try to do.

                      • 8. Re: How do I set tabs in textFrames with tabStops?
                        [Jongware] Most Valuable Participant

                        This works for me. It took some extra time because, uh, well, I accidentally was looking at the InDesign reference ... took me a while to find out why none of the commands worked ...

                         

                        But my hunch payed off: I was thinking, maybe you need to construct a new tab stop. That's way different than how InDesign works.

                         

                        /* set up for testing */
                        doc = app.activeDocument;
                        ele = {position:[100,0], size:[300,100], tab:[60,90,120,200]};
                        var rectRef = doc.pathItems.rectangle(ele.position[0]/1, ele.position[1]/1, ele.size[0]/1, ele.size[1]/1);
                        eleText = doc.textFrames.areaText(rectRef);        
                        var dataArray= new Array ();
                        eleText.contents="hello\tworld\thow\tare\tyou\ttoday";
                        
                        /* Use the following to set tab stops */
                        t = new Array(ele.tab.length);
                        for (tab=0; tab<ele.tab.length; tab++)
                        {
                        t[tab] = new TabStopInfo;
                        t[tab].position = ele.tab[tab];
                        }
                        eleText.paragraphs[0].tabStops = t;
                        

                         

                        Other than with InDesign , you cannot add or modify a single tab stop. Instead, the entire array is "read/write". Creating a new array of "TabStopInfo" items and feeding that into your paragraph is a roundabout way of doing stuff, but hey, at least it works.

                        • 9. Re: How do I set tabs in textFrames with tabStops?
                          Larry G. Schneider Adobe Community Professional & MVP

                          Great job, Jongware. Sometimes it's difficult to see the forest for the trees.

                          • 10. Re: How do I set tabs in textFrames with tabStops?
                            CarlosCanto Adobe Community Professional & MVP

                            yeah, good job JW, maybe TabStopInfo implies "read only", I'll give it another try later using the new keyword

                            • 11. Re: How do I set tabs in textFrames with tabStops?
                              HugoTait Level 1

                              Thank you Very much. It works

                               

                              I really did look hard over the Internet for this code (perhaps I should have asked here sooner) so I'm sure anyone else with this problem will find this answer and benefit from your expertise as well.

                               

                              Regards

                               

                              Hugo

                              • 12. Re: How do I set tabs in textFrames with tabStops?
                                pixxxel schubser Level 5

                                additional to previous ingenious post of [Jongware]:

                                 

                                // for a single TabStop with decimal alignment
                                var myDoc = app.activeDocument;
                                var myDocName = myDoc.name;
                                
                                var t = new Array();
                                t[0] = new TabStopInfo;
                                with (t[0]) {
                                    position = 120;              // in pt
                                    decimalCharacter = ".";      // standard
                                    alignment = TabStopAlignment.Decimal;
                                    }
                                
                                var aText = myDoc.textFrames.add();
                                with (aText) {
                                    contents = myDocName + "\t120.00 Decimalpoint-TabStop";
                                    left = 0;
                                    top = 0;
                                    paragraphs[0].tabStops = t;
                                    }