• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

FrameMaker Script to open readonly books

Community Beginner ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

946

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 27, 2018 Jan 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(

...

Votes

Translate

Translate
Community Expert ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

I get no messages, and have had no issues manually opening up any books from a read only area.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

Can you post the ExtendScript code you are using to try to open the document? Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

Hi,

Here are two examples of how I have tried to open a readonly book

I have set the following permissions on the bookdir directory which contains the book
Read & execute
List folder contents
Read

If the book successfully opens, the book is opened up in FrameMaker and an alert dialog box opens up with the name of the book. Otherwise if the book cannot be opened, an unsuccessful alert box is displayed with undefined as the book name.

Both Scripts have returned unsuccessful undefined, though I have no issues manually opening the readonly book. Also If I give myself write permissions to the bookdir directory, the scripts have no issues opening the book.

I decided the execute method wasn't suitable.

Example 1

var path = "C:\\bookdir\\booksample.book";

var doc = SimpleOpen(path, "");
if(doc.ObjectValid() == true){
        alert("Successfully opened the file:\n\n" + doc.Name);
}
else
{
    alert("Unsuccessfull:\n\n" + doc.Name);
}

Example 2

var openProp = GetOpenDefaultParams();
var retParm = new PropVals();
var doc=Open(path,openProp,retParm);

if(doc.ObjectValid() == true){
        alert("Successfully opened the file:\n\n" + doc.Name);
}
else
{
    alert("Unsuccessfull:\n\n" + doc.Name);
}

Thanks again for any help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

I believe that you are seeing the expected behaviour. The SimpleOpen is just that, it makes no assumption about any special requirements to open the document or book. The normal Open function does provide the means to handle all of the possible problems that you may encounter. The Open Params are the way that you can alter what FrameMaker does when you run into a problem. By just supplying the Open Default Params you are in effect replicating the SimpleOpen function.

Looking through the list of the Open Params there are some that need to be set for example FS_OpenFileNotWritable. The default action is FV_DoCancel which cancels the Open operation (this is the result you are seeing). If you supply the value FV_DoOK the file should open. There may be other Open Params that need managing too.

One other thing. When you have a problem opening a file or any other command you can check the value of FA_errno. In your case this was probably given the value -44 which I believe means Cancelled. Then use CheckStatus() to get the FS_OpenStatus flags.

I hope this helps you to find a solution to your problem

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 27, 2018 Jan 27, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

LATEST

Thanks for your help all!

Cheers Ian, your response has has answered my question

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines