• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adding a new paragraph before the first extisting one

New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

935

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

use InsertionPoints:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

screenshot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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.....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

  contents: chemin + "\r",

  keepWithNext: 1,

  appliedParagrapStyle: someStyle,

  underline: true

  };

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

I tried you code, but this is the result

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

sorry:

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

  contents: chemin + "\r", 

  startParagraph:StartParagraph.NEXT_COLUMN

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

Try this..

EDIT: Vamitul got there before i did ignore this lol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2016 Sep 21, 2016

Copy link to clipboard

Copied

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 

                                         }; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2016 Sep 22, 2016

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines