Skip to main content
Participant
June 24, 2015
Answered

Open Old FrameMaker Documents with ExtendScript

  • June 24, 2015
  • 1 reply
  • 1355 views

I am trying to open a FrameMaker 5.5 document using scripting and convert it to XML. 

I can open the files in the interactive version, but when I try to open them in FrameMaker 2015 using ExtendScript it just won't open.  No return parameter errors.  Just says not valid document. 

Is there a parameter I can set in the open parameters to allow this?

Anyone have an example of how to do this?

Paul V

This topic has been closed for replies.
Correct answer frameexpert

function openDocOrBook (filename, structuredApplication, visible) {

   

    var i = 0, docOrBook = 0;

    // Get default property list for opening documents.

    var openProps = GetOpenDefaultParams ();

    // Get a property list to return any error messages.

    var retParm = new PropVals ();

    // Set specific open property values to open the document.

    i=GetPropIndex (openProps,Constants.FS_AlertUserAboutFailure);

    openProps.propVal.ival=false;

    i=GetPropIndex (openProps,Constants.FS_MakeVisible);

    openProps.propVal.ival=visible;

    i=GetPropIndex (openProps,Constants.FS_FileIsOldVersion);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FileIsInUse);

    openProps.propVal.ival=Constants.FV_ResetLockAndContinue;

    i=GetPropIndex (openProps,Constants.FS_FontChangedMetric);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FontNotFoundInCatalog);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FontNotFoundInDoc);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_RefFileNotFound);

    openProps.propVal.ival=Constants.FV_AllowAllRefFilesUnFindable;

    if (structuredApplication !== undefined) {

        i=GetPropIndex (openProps,Constants.FS_StructuredOpenApplication);

        openProps.propVal.sval=structuredApplication;

    }

    // Attempt to open the document.

    docOrBook = Open (filename,openProps,retParm);

    if (docOrBook.ObjectValid () === 1) {

        // Add a property to the document or book, indicating that the script opened it.

        docOrBook.openedByScript = true;

    }

    else {

        // If the document can't be open, print the errors to the Console.

        PrintOpenStatus (retParm);

    }

    return docOrBook; // Return the document  or book object.

}

This is a general purpose function for opening documents or books. You can call it like this:

var doc = openDocOrBook (filename, structuredApplication, visible);

For structured documents, you can pass in a structured application name as the second parameter. For unstructured documents, just use undefined for the second parameter. The "visible" parameter can be 0 (open the document invisibly) or 1 (open the document and make it visible). Please let me know if you have any questions or comments.

Rick

1 reply

frameexpert
Community Expert
Community Expert
June 24, 2015

Paul, Can you post the code that you are currently using? Thanks. -Rick

freeweelAuthor
Participant
June 24, 2015

Rick, Here's a simplified version of the code:

     var openParams = GetOpenDefaultParams();

     var i = GetPropIndex(Constants.FS_MakeVisible, paramType);

     openParams.propVal.ival = 0;

     var path = "D:/MyOldFrameFile.fm";

     var doc = Open(path, openParams, returnParamOpen);

     if(doc.ObjectValid() == true)

     {

        // If we successfully opened the doc then save as XML and then close

        // NOTE: Removed this code since it never gets here on the older 5.5 docs....

     }

     else

     {

        $.writeln("Couldn't open the file: \n" + path + "\n");

     }

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
June 24, 2015

function openDocOrBook (filename, structuredApplication, visible) {

   

    var i = 0, docOrBook = 0;

    // Get default property list for opening documents.

    var openProps = GetOpenDefaultParams ();

    // Get a property list to return any error messages.

    var retParm = new PropVals ();

    // Set specific open property values to open the document.

    i=GetPropIndex (openProps,Constants.FS_AlertUserAboutFailure);

    openProps.propVal.ival=false;

    i=GetPropIndex (openProps,Constants.FS_MakeVisible);

    openProps.propVal.ival=visible;

    i=GetPropIndex (openProps,Constants.FS_FileIsOldVersion);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FileIsInUse);

    openProps.propVal.ival=Constants.FV_ResetLockAndContinue;

    i=GetPropIndex (openProps,Constants.FS_FontChangedMetric);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FontNotFoundInCatalog);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_FontNotFoundInDoc);

    openProps.propVal.ival=Constants.FV_DoOK;

    i=GetPropIndex (openProps,Constants.FS_RefFileNotFound);

    openProps.propVal.ival=Constants.FV_AllowAllRefFilesUnFindable;

    if (structuredApplication !== undefined) {

        i=GetPropIndex (openProps,Constants.FS_StructuredOpenApplication);

        openProps.propVal.sval=structuredApplication;

    }

    // Attempt to open the document.

    docOrBook = Open (filename,openProps,retParm);

    if (docOrBook.ObjectValid () === 1) {

        // Add a property to the document or book, indicating that the script opened it.

        docOrBook.openedByScript = true;

    }

    else {

        // If the document can't be open, print the errors to the Console.

        PrintOpenStatus (retParm);

    }

    return docOrBook; // Return the document  or book object.

}

This is a general purpose function for opening documents or books. You can call it like this:

var doc = openDocOrBook (filename, structuredApplication, visible);

For structured documents, you can pass in a structured application name as the second parameter. For unstructured documents, just use undefined for the second parameter. The "visible" parameter can be 0 (open the document invisibly) or 1 (open the document and make it visible). Please let me know if you have any questions or comments.

Rick