13 Replies Latest reply on Aug 9, 2017 3:27 AM by Ribnog

    Change leading value

    Ribnog Level 1

      Hi,

       

      I have some paragraphs with overrides applied manually across the document.

       

      I want to apply the leading that are in each respective paragraph styles without do the clearOverrides method because I have italic or colored words with no char style applied that I don't want to "clear".

       

      Thank you in advance.

        • 1. Re: Change leading value
          Loic.Aigon Adobe Community Professional
          myPara.leading = myPara.appliedParagraphStyle.leading;
          
          2 people found this helpful
          • 2. Re: Change leading value
            Ribnog Level 1

            And the var myPara would be? I tried app.activeDocument.stories.everyItem but not work.

            • 3. Re: Change leading value
              Loic.Aigon Adobe Community Professional

              You can use everyItem() in a collection purpose but you would still need to introspect every single paragraph as they may have different leading values.

               

              var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();

              var n = myParas.length;

               

              while ( n-- ) {

              myParas[n].leading = myParas[n].appliedParagraphStyle.leading;

              }

              • 4. Re: Change leading value
                Ribnog Level 1

                Works!

                 

                Yeah I forgot to say that are various paragraph styles with different leadings. Sorry...

                 

                Thank you!

                • 5. Re: Change leading value
                  Ribnog Level 1

                  Hi! I'm back!

                   

                  I'm trying to apply this method only in a selected group with various elements, even other groups, include text frames that where my paragraphs are using selection[0] but I saw that this is not the way. I don't want to ungroup...

                   

                  How I can achieve this?

                  • 6. Re: Change leading value
                    Loic.Aigon Adobe Community Professional

                    Given that app.selection[0] is your group you need to introspect allPageItems property which is an array. If the nth item is of kind TextFrame you can then apply paragraphs changes.

                    • 7. Re: Change leading value
                      Ribnog Level 1

                      I see that's the way, but I don't know how to put this theory in the code. I'm a novice in javascript with indesign.

                       

                      Can you help with the code? Sorry to bother you again

                      • 8. Re: Change leading value
                        Ribnog Level 1

                        I tried this, but nothing...

                         

                        var mySel = app.selection[0];

                        var myEveryGroup = mySel.groups.everyItem().allPageItems;

                        var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();

                         

                        for(var i = 0; i < myEveryGroup.length; i++) 

                                for (var j = 0; j < myEveryGroup[i].length; j++) 

                                { 

                                        myEveryGroup[i][j] instanceof TextFrame && myEveryGroup[i][j].paragraphs.properties = {leading: myParas[n].appliedParagraphStyle.leading}; 

                                    } 

                        }

                        • 9. Re: Change leading value
                          Ribnog Level 1

                          I did it:

                           

                          var mySel = app.selection[0];

                          var myEveryGroup = mySel.groups.everyItem().allPageItems;

                           

                          for(var i = 0; i < myEveryGroup.length; i++) 

                                  for (var j = 0; j < myEveryGroup[i].length; j++) 

                                  { 

                                          myEveryGroup[i][j] instanceof TextFrame && myEveryGroup[i][j].paragraphs.everyItem().leading = 14; 

                                      } 

                          }

                           

                          To change the leading to a specific number, but don't know how to do with "appliedParagraphStyle" method.

                          • 10. Re: Change leading value
                            Ribnog Level 1

                            Any light [Jongware] ? I mentioned you because maybe Loic.Aigon is busy.

                            • 11. Re: Change leading value
                              Ananth@desgin Level 2

                              Hi,

                               

                              var myGroup = app.selection[0]; 
                               
                              // Building an array: 
                              var myGroupItems = myGroup.pageItems.everyItem().getElements();   
                              myGroup.ungroup(); 
                              // If you like a selection of the ungrouped items: 
                              app.select(myGroupItems);
                              var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();
                              var n = myParas.length;
                              while ( n-- ) {
                              myParas[n].leading = myParas[n].appliedParagraphStyle.leading;
                              }
                              myObj = app.selection; 
                              app.activeWindow.activePage.groups.add(myObj);

                               

                               

                              Thanks

                              1 person found this helpful
                              • 12. Re: Change leading value
                                Laubender Adobe Community Professional & MVP

                                Ribnog  wrote

                                 

                                I did it:

                                 

                                var mySel = app.selection[0];

                                var myEveryGroup = mySel.groups.everyItem().allPageItems;

                                 

                                for(var i = 0; i < myEveryGroup.length; i++) 

                                        for (var j = 0; j < myEveryGroup[i].length; j++) 

                                        { 

                                                myEveryGroup[i][j] instanceof TextFrame && myEveryGroup[i][j].paragraphs.everyItem().leading = 14; 

                                            } 

                                }

                                 

                                To change the leading to a specific number, but don't know how to do with "appliedParagraphStyle" method.

                                Hi,

                                if you are after all items stored in app.selection[0] (I suppose a group of items of unknown depth with a nested structure) just get them like that:

                                 

                                var arrayOfPageItems = app.selection[0].allPageItems;
                                

                                 

                                Then loop the items for text frames. Something like that:

                                 

                                var arrayOfPageItems = app.selection[0].allPageItems;
                                for(var n=0;n<arrayOfPageItems.length;n++)
                                {
                                    if(arrayOfPageItems[n].getElements()[0].constructor.name != "TextFrame"){continue};
                                    arrayOfPageItems[n].parentStory.texts[0].leading = 14;
                                };
                                

                                 

                                Hope, that helps…

                                 

                                What I did not understand:
                                What do you mean by "how to do with "appliedParagraphStyle" method"?

                                Would you like to apply the new leading value only to paragraphs, that are formatted with a distinct paragraph style?

                                And if yes, would you like to have a locale override with leading? If not, just change the paragraph style…

                                 

                                Uwe

                                1 person found this helpful
                                • 13. Re: Change leading value
                                  Ribnog Level 1

                                  Hi Laubender

                                   

                                  I need to use the script in groups that I have to increase the size to 200%, so when I do that the text increases too. So to not have to ungroup them and apply your styles with your correct leading and pointSize (yes, I will need to change the size of the text too) I will need this.

                                   

                                  So the appliedParagraphStyle is because in those groups I have text frames with differents text sizes and leadings and all of them have your own style so to not change one by one I think is more easy apply your respective styles to back to your right properties.

                                   

                                  I think override.ALL works, but if some text have italic will miss it.

                                   

                                  I hope you understand, my english is not very good.