5 Replies Latest reply on Nov 5, 2015 4:17 AM by Christopher Pickering

    how to add multiple tabStops at the same time..

    Christopher Pickering

      Hello,

      I know this is a bit basic, but I'm struggling 

       

      I'm trying to create four tabStops in a paragraph style. This is what I have so far... but when it gets to tabStops[1] it dies.. I think something is wrong with how I am creating the four tabStops, but I'm not sure what.. do you see anything I am doing wrong?

       

      Thanks!
      Christopher

       

      try {

          myParagraphStyle = myDocument.paragraphStyles.item("Verse");

          myName = myParagraphStyle.name;

      }

      catch (e){

          myParagraphStyle = myDocument.paragraphStyles.add({name:"Verse"});

          myParagraphStyle.tabStops.add();

          myParagraphStyle.tabStops.add();

          myParagraphStyle.tabStops.add();

          myParagraphStyle.tabStops.add();

       

          with (myParagraphStyle) {

              appliedFont = "Lexicon No1 A Tab";

              fontStyle = "Normal";

              pointSize = 8.75;

              leading = 10;

              alignToBaseline = true;

              justification = Justification.LEFT_JUSTIFIED;

              keepFirstLines = 2;

             tabStops[0].alignment = TabStopAlignment.CENTER_ALIGN;

             tabStops[0].leader = '';

             tabStops[0].position = 5;

         // crashes here

             tabStops[1].alignment = TabStopAlignment.CENTER_ALIGN;

             tabStops[1].leader = '';

             tabStops[1].position = 10;

             tabStops[2].alignment = TabStopAlignment.CENTER_ALIGN;

             tabStops[2].leader = '';

             tabStops[2].position = 15;

             tabStops[3].alignment = TabStopAlignment.CENTER_ALIGN;

             tabStops[3].leader = '';

             tabStops[3].position = 20;

           }

       

       

      }

        • 1. Re: how to add multiple tabStops at the same time..
          Jump_Over Level 5

          Hi,

           

          Specify tab properties while creating, like this:

          myParagraphStyle = app.activeDocument.paragraphStyles.item("Verse");
            with (myParagraphStyle) {
            tabStops.add({
                 position: 5,
                 alignment: TabStopAlignment.CENTER_ALIGN,
                 leader: ""
                 });
            tabStops.add({
                 position: 10,
                 alignment: TabStopAlignment.CENTER_ALIGN,
                 leader: ""
                 });
            tabStops.add({
                 position: 15,
                 alignment: TabStopAlignment.CENTER_ALIGN,
                 leader: ""
                 });
            appliedFont = "Lexicon No1 A Tab";
            fontStyle = "Normal";
            pointSize = 8.75;
            leading = 10;
            alignToBaseline = true;
            justification = Justification.LEFT_JUSTIFIED;
            keepFirstLines = 2;
            }
          

           

          Jarek

          • 2. Re: how to add multiple tabStops at the same time..
            Harbs. Level 6

            It is possible using tabList. Here's some code which does this and sets all properties at the same time. "with" does NOT set properties at the same time and should always be avoided.

             

            var myParagraphStyle = app.documents[0].paragraphStyles.item("Verse");
            myParagraphStyle.properties = {
              tabList:[
                {
                  position: 5,  
                  alignment: TabStopAlignment.CENTER_ALIGN,  
                  leader: ""  
                },
                {
                  position: 10,  
                  alignment: TabStopAlignment.CENTER_ALIGN,  
                  leader: ""  
                },
                {
                  position: 15,  
                  alignment: TabStopAlignment.CENTER_ALIGN,  
                  leader: ""  
                }
              ],
              appliedFont: "Lexicon No1 A Tab",
              fontStyle: "Normal",
              pointSize: 8.75,
              leading: 10,
              alignToBaseline: true,
              justification: Justification.LEFT_JUSTIFIED,
              keepFirstLines: 2
            };
            
            1 person found this helpful
            • 3. Re: how to add multiple tabStops at the same time..
              [Jongware] Most Valuable Participant

              Right. The problem is that you do not add tab stops; you only move the very first one, and there are no more tab stops in that style.

               

              Adding tabstops is the correct way but still may not do what you want it to. If you already have a tabstop at "8", then adding new ones to "5" and "10" will indeed do so – and you end up with 3 tabstops, not 2!

               

              So to make sure that the only tabs in your style are the ones you want, delete them first. Before adding tabstops, you can clear all of them at once with the line

               

              myParagraphStyle.tabStops.everyItem().remove();

              • 4. Re: how to add multiple tabStops at the same time..
                Harbs. Level 6

                [Jongware] wrote:

                So to make sure that the only tabs in your style are the ones you want, delete them first...

                Or use tabList...