SimpleNewDoc also copies the content
Dear all,
I want to add a new document to a book and use the last *.fm document (bookfile_3.fm) as template for this:
oTplDoc = GetLastDocInBook (oBook); // use this a a template
oEnDoc = SimpleNewDoc (oTplDoc.Name, 0); // not interactive
sEnDocPath = GetDocPath (oBook); // save new file in book directory
oEnDoc.SimpleSave (sEnDocPath + "\\" + goTxtN.Fno_EndnotesInBk_01 + ".fm", 0); // can overwrite
AddComponentToBook (oBook, oEnDoc);
This all works fine, but the new document named "endnotes.fm" is not empty, but a complete copy of the bookfile_3.fm
FDK docu reads: F_ApiSimpleNewDoc() creates a new document from a specified template.
- Are templates assumed to be empty (have no text in the frame)?
- How can I simply delete the contents in the oEnDoc ?
- I want to get the properties only (including of course the layout).
Ideas are welcome.
Klaus
Edit
Well, Cleaning out the stuff before entering new stuff can be done with this function
// CleanoutDocument.jsx
#target framemaker
CleanoutDoc (app.ActiveDoc);
function CleanoutDoc (oDoc) { // === remove any content (text) from the document ====================
var oPgfFirst, oPgfLast, oTR;
oPgfFirst = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oPgfLast = GetLastPgfInMainFlow (oDoc); // function described by Rick elsewhere
oTLbeg = new TextLoc (oPgfFirst, 0);
oTLend = new TextLoc (oPgfLast, Constants.FV_OBJ_END_OFFSET);
oTR = new TextRange (oTLbeg, oTLend);
oDoc.DeleteText (oTR);
} //--- end CleanoutDoc

