Highlighted

Latest FM scripting guide not up to date

Participant ,
Nov 10, 2019

Copy link to clipboard

Copied

Hello fellows,

Just downloaded the latest FM scripting guide and discovered that it does not cover the latest versions of FM in the File Save function.

The last save constant listed is FV_SaveFmtInterchange110. Are you aware of any upcoming doc. update?

 

Thanks!

Roman

TOPICS
Scripting

Views

1.9K

Likes

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

Latest FM scripting guide not up to date

Participant ,
Nov 10, 2019

Copy link to clipboard

Copied

Hello fellows,

Just downloaded the latest FM scripting guide and discovered that it does not cover the latest versions of FM in the File Save function.

The last save constant listed is FV_SaveFmtInterchange110. Are you aware of any upcoming doc. update?

 

Thanks!

Roman

TOPICS
Scripting

Views

1.9K

Likes

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
Nov 10, 2019 0
Enthusiast ,
Nov 10, 2019

Copy link to clipboard

Copied

Hi Rombanks,

it never does ;-))

 

When you want to know about the API while coding, you should also have a look at :

- FDK Programmer Guide: An introduction to the FDK and the details on how to set up your development environment

- The complete API reference  

Likes

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
Reply
Loading...
Nov 10, 2019 1
Participant ,
Nov 10, 2019

Copy link to clipboard

Copied

Hi Klaus,

Thank you for your input! Glad to hear that at least the FDK PG is up to date.

 

Best Regards,

Roman

 

 

Likes

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
Reply
Loading...
Nov 10, 2019 0
Participant ,
Nov 10, 2019

Copy link to clipboard

Copied

I can't find the book constant that will enable me to "downgrade" the book from FM15 to FM13. Couldn't find it in the FDK PG either.

The only thing I see is: Constants.FV_BK_BOOK

Please, advise. Thanks in advance!

Likes

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
Reply
Loading...
Nov 10, 2019 0
Enthusiast ,
Nov 10, 2019

Copy link to clipboard

Copied

Hi Rombanks,

there's no separate constant for book. You have to use: FV_SaveFmtBinary130

Likes

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
Reply
Loading...
Nov 10, 2019 1
Participant ,
Nov 11, 2019

Copy link to clipboard

Copied

Hi Klaus, 

 

Thank you for your response! 

 

So I created the following code to save an active doc or book as FM13 upon hitting Save. While it saves an FM file as FM13, it doesn't save the selected book as FM13. Any input will be appreciated!

 

#target framemaker

Notification (Constants.FA_Note_PostSaveDoc, true);

var doc = app.activeDoc;
var book = app.activeBook;

function Notify (note, object, sparam, iparam) {

    switch (note) {
        case Constants.FA_Note_PostSaveDoc :
        SaveToFM13(object);
        break;
    }
}

function SaveToFM13(file) 
{	
    if(doc.ObjectValid() | book.ObjectValid()) 
    {
        var params = GetSaveDefaultParams();
        var returnParamsp = new PropVals();
        var i = GetPropIndex(params, Constants.FS_FileType);
        params[i].propVal.ival = Constants.FV_SaveFmtBinary130;
        file.Save(file.Name, params, returnParamsp);
        return; 
        }
}


 

Likes

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
Reply
Loading...
Nov 11, 2019 0
Enthusiast ,
Nov 12, 2019

Copy link to clipboard

Copied

Hi Rombanks

 

you also have to use further parameters:


i = GetPropIndex(params, Constants.FS_SaveAsModeName);
params[i].propVal.ival = Constants.FV_SaveAsNameProvided;

i = GetPropIndex ( params, Constants.FS_SaveMode );
params[i].propVal.ival = Constants.FV_ModeSaveAs;

 

Sorry for my delayed and short answer, but I'm out of office for some days

Likes

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
Reply
Loading...
Nov 12, 2019 0
Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

Hi Klaus,

I appreciate your response and the input!

Actually, it came as a surprise. I've never seen these params in use for saving a doc/book.

I tried adding them, but it didn't work for some reason. Here is the updated code:

 

...

function SaveToFM13(file) 
{	
    
    if(doc.ObjectValid() | book.ObjectValid()) 
    {
        var params = GetSaveDefaultParams();
        var returnParamsp = new PropVals();
        var i;
        i = GetPropIndex(params, Constants.FS_FileType);
        params[i].propVal.ival = Constants.FV_SaveFmtBinary130;
        i = GetPropIndex(params, Constants.FS_SaveAsModeName);
            params[i].propVal.ival = Constants.FV_SaveAsNameProvided;
        i = GetPropIndex (params, Constants.FS_SaveMode);
            params[i].propVal.ival = Constants.FV_ModeSaveAs;
        file.Save(file.Name, params, returnParamsp);
        return; 
        }
}

 

Likes

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
Reply
Loading...
Nov 13, 2019 0
Enthusiast ,
Nov 15, 2019

Copy link to clipboard

Copied

Hi Rombanks,

I've tested your last code and it works for me.

But one another question: in your function:

function SaveToFM13(file)

 what is file?

I think it's a book object?

And what doesn't work?

Which FA_errno?

 

And I don't understand that line:

if(doc.ObjectValid() | book.ObjectValid()) 

is doc the same as file?

then it should be

if (file.ObjectValid())

 

Sorry for my late response, but I couldn't log in for this afternoon

Likes

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
Reply
Loading...
Nov 15, 2019 0
Participant ,
Nov 17, 2019

Copy link to clipboard

Copied

Hi Klaus,

I appreciate your response!

I don't understand why it doesn't work for me. "file" is just a var placeholder for either "doc" or "book". If  I understand correctly, the name of the variables to handle in the function declaration doesn't really matter. They are replaced by the relevant variables when calling a function. At least this is so in Python. 

 

if(doc.ObjectValid() | book.ObjectValid()) means "perform the save operation when either an .FM file or a .Book file is active."

My Best Regards,
Roman

Likes

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
Reply
Loading...
Nov 17, 2019 0
Enthusiast ,
Nov 17, 2019

Copy link to clipboard

Copied

Hi Roman,

 

I've just did a quick test with your code with a little modification.

This modification was just to add a book object (ActiveBook).

 

Here's the whole script that should work for you:

var oBook = app.ActiveBook;
SaveToFM13(oBook) ;

function SaveToFM13(file) 
{	
    if(file.ObjectValid()) 
    {
        var params = GetSaveDefaultParams();
        var returnParamsp = new PropVals();
        var i;
        i = GetPropIndex(params, Constants.FS_FileType);
        params[i].propVal.ival = Constants.FV_SaveFmtBinary130;
        i = GetPropIndex(params, Constants.FS_SaveAsModeName);
            params[i].propVal.ival = Constants.FV_SaveAsNameProvided;
        i = GetPropIndex (params, Constants.FS_SaveMode);
            params[i].propVal.ival = Constants.FV_ModeSaveAs;
        file.Save(file.Name, params, returnParamsp);
        return; 
        }
}

 

If you say, it doesn't work, what exactly doesn't work?

Which Error / FA_errno

 

 

Likes

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
Reply
Loading...
Nov 17, 2019 1
Participant ,
Nov 17, 2019

Copy link to clipboard

Copied

Hi Klaus, 

 

Thank you for your response and for the input!

 

I actually forgot to add a book saving case for the notifier function. So I did, and it solved the problem.

Thank you very much for your help!

 

My Best Regards,

Roman

 

 

Likes

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
Reply
Loading...
Nov 17, 2019 0
Participant ,
Nov 17, 2019

Copy link to clipboard

Copied

Update: the celebration has started too early. This notification script works very inconsistently in FM19. Although I transfered the script into Autorun, I actually need to select it to and hit Run to make it work. In addition, it saves FM15 files as FM13 only if they are opened as standalone files and not from the book. Here is my updated code. Any input is appreciated! I get no error - just "Result: undefined".

 

 

#target framemaker

Notification (Constants.FA_Note_PostSaveDoc, Constants.FA_Note_PostSaveBook, true);

var oDoc = app.ActiveDoc;
var oBook = app.ActiveBook;

function Notify (note, object, sparam, iparam) {

    switch (note) {
        case Constants.FA_Note_PostSaveDoc :
        SaveToFM13(oDoc);
        break;
        case Constants.FA_Note_PostSaveBook :
        SaveToFM13(oBook);
        break;
    }
}

function SaveToFM13(file) 
{	
    if(file.ObjectValid()) 
    {
        var params = GetSaveDefaultParams();
        var returnParamsp = new PropVals();
        var i;
        i = GetPropIndex(params, Constants.FS_FileType);
        params[i].propVal.ival = Constants.FV_SaveFmtBinary130;
        i = GetPropIndex(params, Constants.FS_SaveAsModeName);
            params[i].propVal.ival = Constants.FV_SaveAsNameProvided;
        i = GetPropIndex (params, Constants.FS_SaveMode);
            params[i].propVal.ival = Constants.FV_ModeSaveAs;
        file.Save(file.Name, params, returnParamsp);
        return; 
        }
}

 

 

Likes

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
Reply
Loading...
Nov 17, 2019 0
Enthusiast ,
Nov 17, 2019

Copy link to clipboard

Copied

Hi Roman,

let's restart the celebration:

 

file.Save(file.Name, params, returnParamsp);

1. Insert alert("Error: " + FA_errno) or $.writeln("Error: " + FA_errno) after this line, so you can check, if  it works.

 

VERY IMPORTANT:

You have to write "$.writeln("Error: " + FA_errno)", not only "$.writeln(FA_errno)".

Because there's a bug in ESTK that doesnt display a message, if it only contains numeric characters.

 

2. When there's a notification in your script and the script stops on error, the registration will remain.

And everytime notification get's active it calls the OLD version of the script, that still is registered.

 

So after a script breaks, you have to remove the registration manually

 

File -> Script - Catalog

 

Registered -> unregister

 

Also, if you close the script, you have to unregister programatically (remove the registration)

 

 

Likes

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
Reply
Loading...
Nov 17, 2019 1
rombanks LATEST
Participant ,
Nov 21, 2019

Copy link to clipboard

Copied

Hi Klaus,

 

Thank you for your valuable input and sorry for the delayed response!!

I added alert("Error: " + FA_errno) under file.Save. When saving a book, I either get no error (and in this case, the book is not saved as FM13) or I get "Error: 0", in which case it works. The notifier function behavior is inconsistent. It may work or it may not. I saw this behavior in the previous versions of FM. Unfortunately, there is no good news in FM19 either...

 

Best Regards,

Roman 

Likes

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
Reply
Loading...
Nov 21, 2019 0