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
Copy link to clipboard
Copied
use InsertionPoints:
myStory.textColumns[col].paragraphs[0].insertionPoints[0].contents="Blah Blah\r"
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?
Copy link to clipboard
Copied
screenshot
Copy link to clipboard
Copied
Of 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.....
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.
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
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.
Copy link to clipboard
Copied
myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = {
contents: chemin + "\r",
keepWithNext: 1,
appliedParagrapStyle: someStyle,
underline: true
};
Copy link to clipboard
Copied
I tried you code, but this is the result
Copy link to clipboard
Copied
sorry:
myStory.textColumns[colonne].paragraphs[0].insertionPoints[0].properties = {
contents: chemin + "\r",
startParagraph:StartParagraph.NEXT_COLUMN
};
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
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
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
};
Copy link to clipboard
Copied
contents:SpecialCharacters.columnBreak + chemin + "\r",
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;
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
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.
Copy link to clipboard
Copied
OK i'll be testing tomorrow morning. Again thanks for your nice support.
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:
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:
90% of hem do well but here i got, after inserting a COL BREAK before "mag-c", this very surprising phenomenon:
The remain of the sliced paragraph is pushed on a new column, while the last part that should remain on the previous column overflows!
Copy link to clipboard
Copied
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.