Skip to main content
K.Daube
Community Expert
Community Expert
July 24, 2019
Answered

SimpleNewDoc also copies the content

  • July 24, 2019
  • 1 reply
  • 581 views

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 

This topic has been closed for replies.
Correct answer K.Daube

Great hint, Rick,

So my CleanoutDoc function now is this:

// ClaeanoutDocument.jsx

#target framemaker

CleanoutDoc (app.ActiveDoc);

function CleanoutDoc (oDoc) { // === remove any content (text) from the document ====================

var oPgfFirst, oPgfLast, oTR, oBpage;

  oPgfFirst = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

  oPgfLast  = GetLastPgfInMainFlow (oDoc);

  oTLbeg    = new TextLoc (oPgfFirst, 0);

  oTLend    = new TextLoc (oPgfLast, Constants.FV_OBJ_END_OFFSET);

  oTR      = new TextRange (oTLbeg, oTLend);

  oDoc.DeleteText (oTR);

  oBpage    = oDoc.LastBodyPageInDoc;

  while (oBpage.PageNum > 0) {

    oBpage.Delete();

    oBpage  = oDoc.LastBodyPageInDoc;

  }

} //--- end CleanoutDoc

function GetLastPgfInMainFlow (oDoc) {

// Arguments  oDoc    Current document

// Returns    object LastPfg in current flow

// Reference  Rick Quatro in https://forums.adobe.com/message/11169995

var textFrame;

    

  textFrame = oDoc.MainFlowInDoc.LastTextFrameInFlow;

  while (textFrame.ObjectValid () === 1) {

    if (textFrame.LastPgf.ObjectValid () === 1) {

        return textFrame.LastPgf;

    }

    textFrame = textFrame.PrevTextFrameInFlow;

  }

} //--- end GetLastPgfInMainFlow

1 reply

frameexpert
Community Expert
Community Expert
July 24, 2019

I take a similar approach. The only other thing you may have to worry about are extra pages that may have custom master pages applied. To be safe, after you delete the content, you can delete all of the body pages except the first.

www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthorCorrect answer
Community Expert
July 25, 2019

Great hint, Rick,

So my CleanoutDoc function now is this:

// ClaeanoutDocument.jsx

#target framemaker

CleanoutDoc (app.ActiveDoc);

function CleanoutDoc (oDoc) { // === remove any content (text) from the document ====================

var oPgfFirst, oPgfLast, oTR, oBpage;

  oPgfFirst = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

  oPgfLast  = GetLastPgfInMainFlow (oDoc);

  oTLbeg    = new TextLoc (oPgfFirst, 0);

  oTLend    = new TextLoc (oPgfLast, Constants.FV_OBJ_END_OFFSET);

  oTR      = new TextRange (oTLbeg, oTLend);

  oDoc.DeleteText (oTR);

  oBpage    = oDoc.LastBodyPageInDoc;

  while (oBpage.PageNum > 0) {

    oBpage.Delete();

    oBpage  = oDoc.LastBodyPageInDoc;

  }

} //--- end CleanoutDoc

function GetLastPgfInMainFlow (oDoc) {

// Arguments  oDoc    Current document

// Returns    object LastPfg in current flow

// Reference  Rick Quatro in https://forums.adobe.com/message/11169995

var textFrame;

    

  textFrame = oDoc.MainFlowInDoc.LastTextFrameInFlow;

  while (textFrame.ObjectValid () === 1) {

    if (textFrame.LastPgf.ObjectValid () === 1) {

        return textFrame.LastPgf;

    }

    textFrame = textFrame.PrevTextFrameInFlow;

  }

} //--- end GetLastPgfInMainFlow

Legend
July 25, 2019

Hi Klaus, also in answer to one of your questions... Every new document in FrameMaker is created by making a copy of an existing document. So you will always get the same content. When you create a new document in the UI with File > New, it is picking some template file somewhere that is empty. That is, the same thing is happening, FrameMaker is making an exact copy of some document somewhere. Naturally, then, Adobe has provided empty documents for those templates.

It is always much, much easier to create a template file that represents the new document you want, rather than "fix" the new document after you make it. If it is possible.

Russ