3 Replies Latest reply on Apr 17, 2013 5:23 AM by MarcoVogelaarBreda

    Set tabs in Paragraph Style

    BenCloutier Level 1

      Hi, i am creating paragraph Styles in JavaScript. I looked but found absolutely no info about setting tabs in a paragraph style.

       

      Am i too tired? Can someone point me in the right direction please?

       

      Thanks

       

      Ben

        • 1. Re: Set tabs in Paragraph Style
          [Jongware] Most Valuable Participant

          Too tired, yeah must be that

           

          Add them one by one to the tabStops property. Before adding your own, make sure it's empty (that is, if you don't want to add to an existing tab ruler).

          Not tried, but I gather it's as easy as

           

          t = myStyle.tabStops.add();

          t.alignment = TabStopAlignment.CENTER_ALIGN;

          t.leader = '?';

          t.position = "3mm";

           

          -- or use 'with properties' to set everything in one go per tabstop:

           

          myStyle.tabStops.add({alignment:TabStopAlignment.CENTER_ALIGN, leader:"?", position:"3mm"});

          • 2. Re: Set tabs in Paragraph Style
            BenCloutier Level 1

            Thanks alot (again) for your help. I am still trying to figure out how to script. So far i've been able to come with some that do the trick (that mean, my 100 lines script would take you five or six).

             

            Ben

            • 3. Re: Set tabs in Paragraph Style
              MarcoVogelaarBreda

              I have made two InDesign scripts, one that deletes all TabStops from all ParagraphStyles of a Document and one that adds TabStops to all ParagraphStyles of a Document.

               

              var oDoc = app.documents.item(0);

               

              // First delete all tabstops

              deleteTabStops(oDoc);

               

              var iNumberOfTabsToAdd = 3;

              var iTabDistance = 5;

              // Then add tabstops

              addTabStops(oDoc, iNumberOfTabsToAdd, iTabDistance);

               

              function deleteTabStops(oDocument)

              {

                   var iNumberOfParagraphStyles = oDocument.paragraphStyles.length;

               

                   for (var iParagraphStyleItem = 0; iParagraphStyleItem < iNumberOfParagraphStyles; iParagraphStyleItem++) {

                        var oParagraphStyle = oDoc.paragraphStyles.item(iParagraphStyleItem);

               

                        if (oParagraphStyle != null) {

                             var iNumberOfTabStops = parseInt(oParagraphStyle.tabStops.length);

               

                             if (iNumberOfTabStops > 0) {

                                  var iLastTabStop = parseInt(iNumberOfTabStops - 1);

               

                                  for (var iLastTabStopItem = iLastTabStop; iLastTabStopItem >= 0; iLastTabStopItem--) {

                                       var oTabStop = oParagraphStyle.tabStops.item(iLastTabStopItem);

               

                                       if (oTabStop != null) {

                                            oTabStop.remove();

                                       }

                                  }

                             }

                        }

                   }

              }

               

              function addTabStops(oDocument, iNumberOfTabsToAdd, iTabDistance)

              {

                   var iNumberOfParagraphStyles = oDocument.paragraphStyles.length;

               

                   for (var iParagraphStyleItem = 0; iParagraphStyleItem < iNumberOfParagraphStyles; iParagraphStyleItem++) {

                        var oParagraphStyle = oDoc.paragraphStyles.item(iParagraphStyleItem);

               

                        if (oParagraphStyle != null && iParagraphStyleItem > 0) {

               

                             for (iTabNumber = 1; iTabNumber <= iNumberOfTabsToAdd; iTabNumber++) {

                                  var sPosition = parseInt(iTabDistance * iTabNumber) + 'mm';

                                  var oTabStop = oParagraphStyle.tabStops.add();

                                  oTabStop.alignment = TabStopAlignment.CENTER_ALIGN;

                                  oTabStop.leader = '';

                                  oTabStop.position = sPosition;

                             }

                        }

                   }

              }

               

              I hope this helps you further.