Skip to main content
Participant
January 19, 2018
Answered

FrameMaker Script to open readonly books

  • January 19, 2018
  • 2 replies
  • 1501 views

Hi,

Is it possible to open readonly books in FrameMaker using a script? I have tried the SimpleOpen(), Open() and the execute() methods and have not had any success. Any help would be appreciated, thanks.

I am currently using FrameMaker 12

This topic has been closed for replies.
Correct answer Ian Proudfoot

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.

2 replies

Ian Proudfoot
Ian ProudfootCorrect answer
Legend
January 27, 2018

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.

Participant
January 31, 2018

Thanks for your help all!

Cheers Ian, your response has has answered my question

frameexpert
Community Expert
Community Expert
January 19, 2018

You can use ExtendScript's File object to unlock the file before you try to open it. For example,

var name = "C:\\DATA\\Scripts\\Test.book";

var file = File (name);

file.readonly = false;

www.frameexpert.com
Participant
January 24, 2018

Hi frameexpert,

Thanks for your input, but I have tried the above and it hasn't worked.

The issue isn't that the file is locked by myself or by another user using it, it's a permissions issue.

For example if I have book sitting in a directory and I have only got the specific permissions Read & Execute and Read Permissions, I would not be able to write to the file or change the propertys of it,
using a script. But I would at least would like to be able to open it with a script, which I'm having trouble doing.

I need to write a script which can open books in a readonly access directory share or a DVD.

Thanks

frameexpert
Community Expert
Community Expert
January 24, 2018

Try opening the document without a script and let me know what kind of message you get.

www.frameexpert.com