21 Replies Latest reply on Sep 22, 2016 6:53 PM by ZedGeneve

    Adding a new paragraph before the first extisting one

    ZedGeneve

      Hello

       

      I'm sorry to ask what could be a very basic question but I'm a beginner.

       

      I've a text column containing a given number of paragraphs, each richly formatted, with character styles and paragraph styles. I'd like to append a new paragraph just before the first existing one.

       

      If i add a string doing for example myStory.textColumns[col].paragraphs[0].contents = "blabla" + "\r" + myStory.textColumns[col].paragraphs[0].contents i lose all the formatting or a mess occurs.

       

      Thank for the help

       

      Best

       

      Ed

        • 1. Re: Adding a new paragraph before the first extisting one
          Vamitul Level 4

          use InsertionPoints:

          myStory.textColumns[col].paragraphs[0].insertionPoints[0].contents="Blah Blah\r"

          • 2. Re: Adding a new paragraph before the first extisting one
            ZedGeneve Level 1

            Thanks for your answer, it's almost working

            I've got now a little issue: when inserting the text, as my pages have 2 textframes, the newly added text very often "goes back" down of the previous column

            Is there a way to prevent this as i just want to "push" my new text?

            • 4. Re: Adding a new paragraph before the first extisting one
              ZedGeneve Level 1

              Capture d’écran 2016-09-21 à 18.28.41.pngCapture d’écran 2016-09-21 à 18.28.55.pngOf course my goal is to add at the beginning of every new column the chapter, sub chapter, sub sub chapter name, etc.
              As i hope you can see here on the first pic, the first paragraph of column 2 should be "ABSORBE" that I added, but Indesign moved it forward at the end of the previous column.
              In a new version of my text, this time using 2 columns set in the properties of text block, i don't have columns anymore.....

              • 5. Re: Adding a new paragraph before the first extisting one
                Skemicle Level 3

                If these chapter names will always be at the beginning of the column set the Keep: options in the paragraph style to start paragraph in next column.

                • 6. Re: Adding a new paragraph before the first extisting one
                  ZedGeneve Level 1

                  That what i did:

                  myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].contents=chemin+"\r";

                                                      myStory.textColumns[colonne].paragraphs[0].keepWithNext= 1;

                  but it doesn't work as i guess at the moment the first line's executed, the paragraph's been moved already on the previous column

                  • 7. Re: Adding a new paragraph before the first extisting one
                    Skemicle Level 3

                    start in next column is different than keep with next 1 line..

                    Since your contents -chemin- are being push to the previous column the script you are using sets the keep with next to the paragraph you are adding the chapters in front of. in this case you would need the last paragraph of the previous column:

                    myStory.textColumns[colonne - 1].paragraphs[-1].keepWithNext= 1;

                    Though that may give undesired results if some of the chapter names you are adding do display properly when adding to the column.

                     

                    What i was saying was to manually set the paragraph style Keep options.. rather than scripting that.. that way whenever that paragraph style comes up it will automatically be set to a new column.

                    • 8. Re: Adding a new paragraph before the first extisting one
                      Vamitul Level 4
                      myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = {
                        contents: chemin + "\r",
                        keepWithNext: 1,
                        appliedParagrapStyle: someStyle,
                        underline: true
                        };
                      
                      • 9. Re: Adding a new paragraph before the first extisting one
                        ZedGeneve Level 1

                        Capture d’écran 2016-09-21 à 19.18.52.png

                        I tried you code, but this is the result

                        • 10. Re: Adding a new paragraph before the first extisting one
                          Vamitul Level 4

                          sorry:

                          myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = {  
                            contents: chemin + "\r",  
                            startParagraph:StartParagraph.NEXT_COLUMN
                           };
                          
                          • 11. Re: Adding a new paragraph before the first extisting one
                            Skemicle Level 3

                            app.activeDocument.paragraphStyles.item ("Chapter Name Style").startParagraph = StartParagraph.NEXT_COLUMN

                            Try this..

                             

                            EDIT: Vamitul got there before i did ignore this lol

                            • 12. Re: Adding a new paragraph before the first extisting one
                              ZedGeneve Level 1

                              Thanks to both of you

                              Unfortunately

                                                                myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = { 
                                                                   contents: chemin + "\r", 
                                                                   keepWithNext: 1, 
                                                                      appliedParagrapStyle: "rappel", 
                                                                  underline: true 
                                                                   }; 
                                                                
                                                                     app.activeDocument.paragraphStyles.item ("rappel").startParagraph = StartParagraph.NEXT_COLUMN

                               

                               

                              is not working either

                              • 13. Re: Adding a new paragraph before the first extisting one
                                ZedGeneve Level 1

                                I think the solution could be to add a COLUMN BREAK but i'm still unable to do so

                                 

                                myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = { 

                                                                         contents: SpecialCharacters.COLUMN_BREAK+ chemin + "\r", 

                                                                         keepWithNext: 1, 

                                                                            appliedParagrapStyle: "rappel", 

                                                                        underline: true 

                                                                         }; 

                                • 14. Re: Adding a new paragraph before the first extisting one
                                  Skemicle Level 3

                                  contents:SpecialCharacters.columnBreak + chemin + "\r",

                                  • 15. Re: Adding a new paragraph before the first extisting one
                                    Vamitul Level 4

                                    Skemicle, that code cannot work because of type conversions:
                                    the SpecialCharacters.columnBreak will be converted to its numeric value (1396927554) and that value will be then converted to a string, resulting in "1396927554ABSORBE".

                                    Also, SpecialCharacters.columnBreak is an alias for StartParagraph.NEXT_COLUMN

                                     

                                    For Ed:

                                    var ip=myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].index;
                                    myStory.insertionPoints[ip].contents=chemin + "\r";
                                    myStory.insertionPoints[ip].paragraphs[0].startParagraph=StartParagraph.NEXT_COLUMN;
                                    
                                    
                                    //alternative, using a column break:
                                    var ip=myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].index;
                                    myStory.insertionPoints[ip].contents=chemin + "\r";
                                    myStory.insertionPoints[ip].contents=SpecialCharacters.COLUMN_BREAK;
                                    
                                    • 16. Re: Adding a new paragraph before the first extisting one
                                      ZedGeneve Level 1

                                      Thanks a lot to both of you

                                      I did something like Vamitul suggests but i'm facing now an unpredictable issue: after inserting the break, sometimes the rest of a column is "pushed" pout to a next one resulting in an almost empty column. I'm dealing this issue but testing the contents of the text. But still some places where i'm not completely understanding the Indesign behaviour

                                      • 17. Re: Adding a new paragraph before the first extisting one
                                        Vamitul Level 4

                                        Hi Ed,

                                        The text getting pushed is most likely because the column break also acts as an end-of-paragraph. So you are basically not inserting one paragraph (the chemin) but two of them.

                                        Ways to fix it:

                                        a) Use the first version i suggested, with startParagraph.

                                        b) Instead of inserting the column break, replace the previous paragraph's '\r' with the column break.

                                        • 18. Re: Adding a new paragraph before the first extisting one
                                          ZedGeneve Level 1

                                          OK i'll be testing tomorrow morning. Again thanks for your nice support.

                                          • 19. Re: Adding a new paragraph before the first extisting one
                                            ZedGeneve Level 1

                                            Hi Vamitul

                                             

                                            Well i did a lot of tests, and it seems that only the hard break can work here. In many cases, the added text in beginning of a new column will be pushed backwards, if i use startParagraph.

                                             

                                            I even did that:

                                             

                                            1. myStory.textColumns[colonne].paragraphs[0].select();
                                            2.                                 var firstParContents= myStory.textColumns[colonne].paragraphs[0].contents;
                                            3.                             
                                            4.                                 var ip=myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].index;
                                            5.                                 myStory.insertionPoints[ip].contents=chemin + "\r";
                                            6.                                 
                                            7.                                 myStory.textColumns[colonne].paragraphs[0].select();
                                            8.                                 if (firstParContents == myStory.textColumns[colonne].paragraphs[0].contents){
                                            9.                                         myStory.textColumns[colonne-1].paragraphs[-1].appliedParagraphStyle= "rappel";
                                            10.                                         myStory.textColumns[colonne-1].paragraphs[-1].startParagraph=StartParagraph.NEXT_COLUMN;
                                            11.                                     
                                            12.                                         }

                                             

                                            It appears that at the very moment chemin + "\r" is inserted, it's pushed back so i force Indesign to redraw the column to really see it. My little test detects such occurrences and then replaces the paragraph where it should be. Unfortunately, when dealing with the next column, it will be eventually pushed back whatever startParagraph is applied.

                                             

                                            So i went back to the hard break version which is working fine as lon as we have a new paragraph in the beginning of a column. I'm dealing now with the slicing of large paragraphs like this one:

                                             

                                            Capture d’écran 2016-09-23 à 03.09.24.png

                                             

                                            90% of hem do well but here i got, after inserting a COL BREAK before "mag-c", this very surprising phenomenon:

                                             

                                            Capture d’écran 2016-09-23 à 03.09.06.png

                                            The remain of the sliced paragraph is pushed on a new column, while the last part that should remain on the previous column overflows!

                                            • 20. Re: Adding a new paragraph before the first extisting one
                                              ZedGeneve Level 1

                                              OK as i'm typing this i understand this happens because the definition of my style as i'm asking Indesign to keep at least 3 lines together

                                              Going to fix this by changing this property before slicing i guess; Let's see if i find it.