Issue solved. Files that I try to open from a script in FM22 result in an invalid doc.Object. I thought I'd converted the file successfully during an earlier test, but most not have. I'm suspecting the alert I get when I try to manually open a 2020 or older version file, asking if I want to convert the file to the newer format, is causing the error. Not a problem now that I know why it's happening. I'll just convert all the documents I load with the script to FM22. Thanks for tips on things to check.
Here's code snippet:
#target framemaker
// SET UP VARIABLES
var path = "C:\\Users\\fight\\Desktop\\FM Hitlists\\";
var HLTitle = "Table 25. Words Not Spelled Out.fm";
//var HLTitle = "Table 25. Words Not Spelled Out(FM22).fm"
loadHitlist();
function loadHitlist() {
$.writeln("Loading Table 25. Words Not Spelled Out.fm...");
var doc = SimpleOpen(path + HLTitle);
if(doc.ObjectValid() == false) {
alert("Couldn't open the file! Check to see if it is an FM document " +
"or if somebody is already using it. The selected path was:\n\n" + path);
}
}
I would use the Open () method instead of SimpleOpen (). Open allows you to ignore all kinds of things when opening a document or book. If you look through the code, you can see the kinds of issues that it will ignore while still opening the document or book.
function openDocOrBook (filename, structuredApplication, visible) {
var openProps, retParm, i, docOrBook;
// Get default property list for opening documents.
openProps = GetOpenDefaultParams ();
// Get a property list to return any error messages.
retParm = new PropVals ();
// Set specific open property values to open the document.
i = GetPropIndex (openProps, Constants.FS_AlertUserAboutFailure);
openProps[i].propVal.ival = false;
i = GetPropIndex (openProps, Constants.FS_MakeVisible);
openProps[i].propVal.ival = visible;
i = GetPropIndex (openProps, Constants.FS_FileIsOldVersion);
openProps[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex (openProps, Constants.FS_FileIsInUse);
openProps[i].propVal.ival = Constants.FV_ResetLockAndContinue;
i = GetPropIndex (openProps, Constants.FS_FontChangedMetric);
openProps[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex (openProps, Constants.FS_FontNotFoundInCatalog);
openProps[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex (openProps, Constants.FS_FontNotFoundInDoc);
openProps[i].propVal.ival =Constants.FV_DoOK;
i = GetPropIndex (openProps, Constants.FS_RefFileNotFound);
openProps[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;
if (structuredApplication !== undefined) {
i = GetPropIndex (openProps, Constants.FS_StructuredOpenApplication);
openProps[i].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.
}