I was thinking about the naming of the GetOpenDefaultParams function. It gives the impression that the default params are those used by the File > Open command in the FrameMaker UI. That's not the case, it means the default values for each open parameter.
In the script below there are two parameters that commonly cancel the opening process:
open();
function open() {
var path = "C:\\bookdir\\booksample.book",
file = File (path),
fileName = file.fsName,
openParams = GetOpenDefaultParams(),
retParams = new PropVals();
openParams.push(propertyVals(Constants.FS_OpenFileNotWritable, Constants.FT_Integer, Constants.FV_DoOK));
openParams.push(propertyVals(Constants.FS_FileIsOldVersion, Constants.FT_Integer, Constants.FV_DoOK));
if (file.exists) {
var newDoc = Open(fileName, openParams, retParams);
if(newDoc.ObjectValid()){
alert("Successfully opened the file:\n\n" + newDoc.Name);
}
else
{
alert("Unsuccessful:\n\n" + newDoc.Name + "\nError: " + FA_errno);
}
}
}
function propertyVals(ident, type, value) {
var newPropIdent = new PropIdent(),
newPropVal = new PropVal();
newPropIdent.num = ident;
newPropVal.propIdent = newPropIdent;
newPropVal.propVal = new TypedVal();
newPropVal.propVal.valType = type;
newPropVal.propVal.ival = value;
return newPropVal;
}
You will also notice that I initially check to see if the file exists using the ExtendScript File handling abilities. It's much easier to do that than unscramble the messages that FrameMaker returns if you try to open an invalid file.