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.