Copy link to clipboard
Copied
Dear friends, It seems that I stretch my knowledge to far...
I have collected footnotes in an array aoFNcollected.
A heading has already be placed: oPgf
Now I want to place the FN paragraphs to a new place forming endnotes (remember, a footnote can contain more than 1 paragraph).
for (j = 0; j < nNotes; j++) {
oFn = aoFNcollected
; // Fn to be handled now oFnPgf = oFn.FirstPgf; // first ¶ in footnote
oPgf = oDoc.NewSeriesPgf(oPgf); // new empty ¶ in doc
oDoc.TextSelection = oFnPgf; // this does not work - halt of script
oDoc.Copy(0); // copy Fn para
oTL = new TextLoc (oPgf, 0);
oTR = new TextRange(oTL, oTL);
oDoc.TextSelection = oTR;
oDoc.Paste(); // paste Fn para
Fno_ApplyPgfFmt (oDoc, oPgf, goFno.FmtEn) // apply ¶ format zen-endnote
// further code not yet verified - just showing my intention
oFnPgf = oFnPgf.NextPgfInFlow; // ??? is a FN also a flow of its own ???
while (oFnPgf.ObjectValid()) { // a footnote can have multiple paragraphs
oPgf = oDoc.NewSeriesPgf(oFnPgf);
Fno_ApplyPgfFmt (oDoc, oPgf, goFno.FmtEnCont) // apply ¶ format zenc-endnote-continue
oFnPgf = oFnPgf.NextPgfInFlow; // get next ¶ from footnote
}
}
I tried to use the copy/paste method - but obviously line 05 does not provide a TextSelection, because the object comes from an array and not from the document.
But how can I place a Pfg object to a new place defined by a new Pgf (line 04)?
Copy link to clipboard
Copied
You can't select a paragraph by just assigning it as the document's TextSelection property. You have to make a TextRange first:
var textRange;
textRange = new TextRange (
new TextLoc (oFnPgf, 0),
new TextLoc (oFnPgf, Constants.FV_OBJ_END_OFFSET));
oDoc.TextSelection = textRange;
Or, you could try selecting and copying them all at once:
var textRange;
textRange = new TextRange (
new TextLoc (oFn.FirstPgf, 0),
new TextLoc (oFn.LastPgf, Constants.FV_OBJ_END_OFFSET));
oDoc.TextSelection = textRange;
Copy link to clipboard
Copied
Thanks to Ric I'm a great step further - but the results are still not what I want:
Stopping the script at line 27 to inspect the results I see this (the pasted Fn para has its 'old' ¶-format):
Why the heck does Paste not insert at the 'current location' defined by oTL in line 22?
Whether I define the new paragraph oPgf in line 15 or do that later just before defining oTL ahs no influence.
function Fno_ConvertFootnotes (oDoc, aoFNcollected) { //=== convert the footnotes to endnotes =====
var j, nNotes, oFn, oFnPgf, oPgf, oPgfFmt, oPgfFmtC, oPgfProps, oPgfPropsC, oTL, oTR, sText;
nNotes = aoFNcollected.length;
// --- At end of document insert title paragraph ---
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf; // get last oPgf in flow
oPgf = oDoc.NewSeriesPgf(oPgf); // add a paragraph
oTL = new TextLoc (oPgf, 0);
sText = "Endnotes"; //
oDoc.AddText (oTL, sText); // Create the title
oPgfFmt = oDoc.GetNamedObject(Constants.FO_PgfFmt, goFno.FmtEnTitle);
oPgfProps = oPgfFmt.GetProps();
oPgf.SetProps(oPgfProps); // apply ¶ format
// --- Add new paragraphs at end of doc and format
for (j = 0; j < nNotes; j++) {
oPgf = oDoc.NewSeriesPgf(oPgf); // new empty ¶ for endnote
oFn = aoFNcollected
; // Fn to be handled now oFnPgf = oFn.FirstPgf; // first ¶ in footnote
oDoc.TextSelection = new TextRange (
new TextLoc (oFnPgf, 0), // Fn ¶s get different ¶-formats
new TextLoc (oFnPgf, Constants.FV_OBJ_END_OFFSET));
oDoc.Copy(0); // copy Fn para
oTL = new TextLoc (oPgf, 0);
oDoc.TextSelection = new TextRange (oTL, oTL); // essential ?
oDoc.Paste(); // paste Fn para
Fno_ApplyPgfFmt (oDoc, oPgf, goFno.FmtEn) // apply ¶ format zen-endnote
// code to handle second to last Fn paragraph
}
// code to replace the Fn anchor by cross ref to endnote
} //--- end Fno_ConvertFootnotes
function Fno_ApplyPgfFmt (oDoc, oPgf, sPgfFmt) {
// Reference https://forums.adobe.com/thread/1711161
var oPgfFmt = 0, oProps;
oPgfFmt = oDoc.GetNamedPgfFmt(sPgfFmt);
if (oPgfFmt.ObjectValid()) {
oProps = oPgfFmt.GetProps();
oPgf.SetProps(oProps);
} else {
oPgf.Name = sPgfFmt;
}
} //--- end Fno_ApplyPgfFmt
I can not see that the order of my statements are wrong, but I may be blindfolded...
Copy link to clipboard
Copied
To ease reproduction of the problem I have stripped down my script to something which should run on any document.
You may replace the format "Table Title" by something elsle in your document.
Running the below script on a document with the default template gives these results:
Here the last inserted line gets the applied format, but the copy creates an own new paragraph!
How can I get the copied ¶ to get the new format - or copy into the willingly inserted new ¶?
I have probably shot myself into the knee: Since I copy a paragraph, a paste will insert a paragraph, not just its contents...
Will have to check this after lunch break.
// CopyParagraph.jsx
// add a copy of the first para to the end
#target framemaker
main ();
function main () {
var oDoc, oFnPgf, oPgf, oTL;
oDoc = app.ActiveDoc;
oFnPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf;
oTL = new TextLoc (oPgf, 0);
oDoc.TextSelection = new TextRange (
new TextLoc (oFnPgf, 0), //
new TextLoc (oFnPgf, Constants.FV_OBJ_END_OFFSET));
oDoc.Copy(0); // copy Fn para
oPgf = oDoc.NewSeriesPgf(oPgf); // new empty ¶
Fno_ApplyPgfFmt (oDoc, oPgf, "Table Title") // apply ¶ format
oTL = new TextLoc (oPgf, 0);
oDoc.TextSelection = new TextRange (oTL, oTL); // essential !
oDoc.Paste(0); // paste Fn para
}
function Fno_ApplyPgfFmt (oDoc, oPgf, sPgfFmt) {
var oPgfFmt = 0, oProps;
oPgfFmt = oDoc.GetNamedPgfFmt(sPgfFmt);
if (oPgfFmt.ObjectValid()) {
oProps = oPgfFmt.GetProps();
oPgf.SetProps(oProps);
} else {
oPgf.Name = sPgfFmt;
}
} //--- end Fno_ApplyPgfFmt
Copy link to clipboard
Copied
Hi Klaus,
I'm a bit in a hurry, so I can't test it in deep.
My suggestion is to change your line 18 "oPgf = oDoc.NewSeriesPgf(oPgf);" to oNewPgf = .... and continue working on with oNewPgf.
At that moment you create NewSeriesPgf it is not yet visible.
Copy link to clipboard
Copied
Klaus, that that did not help...
However I have discovered a circumvention - delete the obstacle paragraph inserted by copy:
// CopyParagraph.jsx
// add a copy of the first para to the end
#target framemaker
main ();
function main () {
var oDoc, oFnPgf, oPgf, oNewPgf, oTL;
oDoc = app.ActiveDoc;
oFnPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oDoc.TextSelection = new TextRange (
new TextLoc (oFnPgf, 0), //
new TextLoc (oFnPgf, Constants.FV_OBJ_END_OFFSET));
oDoc.Copy(0); // copy Fn para
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf;
oPgf = oDoc.NewSeriesPgf(oPgf); // add a paragraph
oTL = new TextLoc (oPgf, 0);
oDoc.TextSelection = new TextRange (oTL, oTL); // essential !
oDoc.Paste(0); // paste Fn para
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf; // Superfluous by Copy
oPgf.Delete();
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf;
Fno_ApplyPgfFmt (oDoc, oPgf, "Test") // apply ¶ format
}
function Fno_ApplyPgfFmt (oDoc, oPgf, sPgfFmt) {
var oPgfFmt = 0, oProps;
oPgfFmt = oDoc.GetNamedPgfFmt(sPgfFmt);
if (oPgfFmt.ObjectValid()) {
oProps = oPgfFmt.GetProps();
oPgf.SetProps(oProps);
} else {
oPgf.Name = sPgfFmt;
}
} //--- end Fno_ApplyPgfFmt
IMHO this is not very elegant - hope that someone will find the real solution. But it works:
Between the two runs of the script I removed the first paragraph of the document to get a new first one:
Paragraph format Test does not contain any highlighting to get the character formats from the original source paragraph.
For the time beeing I can live with this ugliness.