Skip to main content
Participating Frequently
Mar 15, 2018 11:48 AM UTC
Question

Open fm document.

how to open an existing framemaker document using extendscript?

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Legend
Mar 15, 2018 12:50 PM UTC

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]

Translate
frameexpert
Community Expert
Community Expert
Mar 15, 2018 12:44 PM UTC

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

Translate
www.frameexpert.com
Known Participant
Sep 7, 2018 6:02 PM UTC

Hi

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

Thanks

Translate
Legend
Sep 7, 2018 8:39 PM UTC

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

Translate