Skip to main content
Participating Frequently
March 15, 2018
Question

Open fm document.

  • March 15, 2018
  • 2 replies
  • 804 views

how to open an existing framemaker document using extendscript?

This topic has been closed for replies.

2 replies

Legend
March 15, 2018

Hi,

You can find a sample here for a "simple" document open (script 01.03):

FrameMaker ExtendScript Samples - West Street Consulting

If the file has any type of error or special condition, the simple method will not work. In that case, you have to use the Open() method. That can get a little complicated... Here is a function I use, where the path is the fully qualified path and all other arguments are boolean:

function file_OpenFile(path, ignoreErrors, ignoreLock, hidden, allowNonWriteable)

{

    var index;

    var props = GetOpenDefaultParams();

    index = GetPropIndex(props, Constants.FS_AlertUserAboutFailure);

    if(ignoreErrors)

        props[index].propVal.ival = false;

    else

        props[index].propVal.ival = true;

       

    index = GetPropIndex(props, Constants.FS_BookIsInUse);

    if(ignoreLock)

        props[index].propVal.ival = Constants.FV_ResetLockAndContinue;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_DisallowMIF);

    props[index].propVal.ival = false;

       

    index = GetPropIndex(props, Constants.FS_DisallowXml);

    props[index].propVal.ival = false;

       

    index = GetPropIndex(props, Constants.FS_DontNotifyAPIClients);

    props[index].propVal.ival = true;

       

    index = GetPropIndex(props, Constants.FS_FileIsOldVersion);

    props[index].propVal.ival = Constants.FV_DoOK;

       

    index = GetPropIndex(props, Constants.FS_FileIsInUse);

    if(ignoreLock)

        props[index].propVal.ival = Constants.FV_ResetLockAndContinue;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_FontChangedMetric);

    if(ignoreErrors)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_FontNotFoundInCatalog);

    if(ignoreErrors)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_FontNotFoundInDoc);

    if(ignoreErrors)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_LanguageNotAvailable);

    if(ignoreErrors)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_LockCantBeReset);

    if(ignoreLock)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_MakeVisible);

    if(hidden)

        props[index].propVal.ival = false;

    else

        props[index].propVal.ival = true;

       

    index = GetPropIndex(props, Constants.FS_NewDoc);

    props[index].propVal.ival = false;

       

    index = GetPropIndex(props, Constants.FS_OpenAsType);

    props[index].propVal.ival = Constants.FV_AUTORECOGNIZE;

       

    index = GetPropIndex(props, Constants.FS_OpenBookViewOnly);

    props[index].propVal.ival = false;

       

    index = GetPropIndex(props, Constants.FS_OpenDocViewOnly);

    props[index].propVal.ival = false;

       

    index = GetPropIndex(props, Constants.FS_UseAutoSaveFile);

    props[index].propVal.ival = Constants.FV_DoNo;

       

    index = GetPropIndex(props, Constants.FS_UpdateTextReferences);

    props[index].propVal.ival = Constants.FV_DoNo;

       

    index = GetPropIndex(props, Constants.FS_UpdateXRefs);

    props[index].propVal.ival = Constants.FV_DoNo;

       

    index = GetPropIndex(props, Constants.FS_UseRecoverFile);

    props[index].propVal.ival = Constants.FV_DoNo;

       

    index = GetPropIndex(props, Constants.FS_UseAutoSaveFile);

    props[index].propVal.ival = Constants.FV_DoNo;

       

    index = GetPropIndex(props, Constants.FS_OpenFileNotWritable);

    if(allowNonWriteable)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_DoCancel;

       

    index = GetPropIndex(props, Constants.FS_RefFileNotFound);

    if(ignoreErrors)

        props[index].propVal.ival = Constants.FV_DoOK;

    else

        props[index].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;

       

 

    //open the document

    var returnp = new PropVals();

    var file = Open(path, props, returnp);

 

    if(file.ObjectValid() && hidden)

        file.IsOnScreen = false;

    else if(file.ObjectValid())

        file.IsOnScreen = true;

       

    return file;

}   

Hope this helps.

Russ

[EDIT: Clarified input parameters]

frameexpert
Community Expert
Community Expert
March 15, 2018

See this post for some functions for opening a document or book:

Running a Publish script at startup

See line 84 for the function call. There are three functions involved: getDocOrBook, docOrBookIsOpen, and openDocOrBook. Please post any additional questions if this doesn't make sense. Thanks -Rick

www.frameexpert.com
Known Participant
September 7, 2018

Hi

These functions don't work for my files to open fm files. Do you know what might be the reason.

Thanks

Legend
September 7, 2018

Hi,

This is virtually impossible to troubleshoot without more information. There are so many reasons that a file fails to open. Do you get any errors when trying to open it manually in the UI?


Russ