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

SimpleNewDoc also copies the content

Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

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 

TOPICS
Scripting

Views

435

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

correct answers 1 Correct answer

Community Expert , Jul 25, 2019 Jul 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 TextRan

...

Votes

Translate

Translate
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

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.

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
Community Expert ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

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

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
Mentor ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

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

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
Community Expert ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

LATEST

Thanks Russ for the reminder about what's going on...

«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.»:

I wanted to avoid a real template, because for the German/French version I would need something different to the En version...  So I decided to use the last FM document in a book to be the template. Some of the required formats (¶ and character)  would be there already and others could be derived or defined as needed. And the user has all his familiar formats at hand (e.g. Heading1 or 1_heading…).

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