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

Having Problems Using F_ApiSimpleImportFormats

Guest
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Hi,

I am (still) using FM 8 in Structured Authoring mode with FDK8 .

I want to automate the processs of importing formats to the components of a book.

I have located the F_ObjHandleT of the files I want to import from

I have tried using:

F_ApiSimpleImportFormats(bookId, titleId, 0);

Where bookId is the F_ObjHandleT of the book using bookId = F_ApiGetId(FV_SessionId, FV_SessionId, FP_ActiveBook);

And titleId is the F_ObjHandleT of the component to import from using titleId = F_ApiGetId(FV_SessionId, bookId, FP_FirstComponentInBook);

Believing this would simply update every file in the book

I have also tried cycling through the book componenets in a while loop with:

compId = F_ApiGetId(FV_SessionId, bookId, FP_FirstComponentInBook);

and

compId = F_ApiGetId(bookId, compId, FP_NextComponentInBook);

using

F_ApiSimpleImportFormats(compId, titleId, 0);

for each component (skipping the first one since that is the source)

In each case I get an FA_errno of -2 (FE_BadDocId - Illegal Document or Book)

I am able to get the name of the component using: componentName = F_ApiGetString(bookId, compId, FP_Name);

and print it to the log window, so I believe the doc ID and the book ID are sound.

Any other clues why I get an error on this API call?

Thanks,

- Michael

TOPICS
Scripting

Views

1.0K

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
Advocate ,
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Hello Michael,

1. You should cycle through the components of the book - i.e. opening them and importing the formats into them before saving and closing them again. There is the option to import formats into all files in a book, but the ImportFmtInclude property of the components must be True, otherwise they are ignored by this book method. I would simply use the method of opening each component first and running the simple import method on that component.

2. You have to specify the formats to import using SimpleImportFormats. Supplying 0 as the last parameter will cause nothing to be imported. The values to specify can be found on page 428-9 of the FrameMaker 10 Scripting Guide.

Good luck

Jang

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
Guest
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Thanks, Jang! I appreciate the response.

I short-handed my code in my original post, but I am doing as you indicate.

Here is a larger code snippet:

userCancel = F_ApiUserCancel();

            while (compId && !userCancel) {

                componentName = F_ApiGetString(bookId, compId, FP_Name);

                F_Printf(NULL, "Updating File: %s\n", componentName);

                if (compId == titleId) {

                    F_Printf(NULL, "We can skip updating the Title\n");

                } else {

                    F_Printf(NULL, "Importing Formats to %s\n", componentName);

                    /*

                    It didn't help to open the component first

                    docId = F_ApiSimpleOpen(componentName, FALSE);

                    */

                    if (F_ApiClearAllChangebars(compId) != FE_Success) {

                        F_Printf(NULL, "    F_ApiClearAllChangebars: %d\n", FA_errno);                   

                    }

                    /*

                    It didn't help to open the component first

                    F_ApiSimpleSave(docId, componentName, FALSE);

                    F_ApiClose(docId, TRUE);

                    */

                    /*

                    if (F_ApiSimpleImportFormats(bookId, compId, 0) != FE_Success) {

                        F_Printf(NULL, "    F_ApiSimpleImportFormats: %d\n", FA_errno);                   

                    }

                    */

                }


                F_Free(componentName);

                if (wholeBook)

                    compId = F_ApiGetId(bookId, compId, FP_NextComponentInBook);

                else

                    compId = F_ApiGetId(bookId, compId, FP_NextSelectedComponentInBook);


                userCancel = F_ApiUserCancel();

            }


Note, I changed the API call to something else to make sure the API call was not the problem.

I get the same error code using F_ApiCLearAllChangebars()

(Wow, That formatting is annoying. Must be a better way to place code into the forum message)

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
Advocate ,
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Yes, but in the larger code you are still supplying 0 as parameter to the SimpleImportFormats function, which makes it import nothing at all. Check the Framemaker Scripting Guide or the FDK reference for the values. Search for Constants.FF_UFF_PGF om those documents and it will take you right to the list of constants to use. Use bitwise OR to combine them into one value and supply that value as the last parameter to SimpleImportFormats. Let us know whether it worked.

Ciao

Jang

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
Guest
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

OK, but that isn't going to help as long as I'm getting an error code of -2. I changed the code to use (what I thought was) a simplier function. I'm not calling the ImportFormats() routine (it is commented out), I changed it to the ClearChangeBars() routine and I still get an error code of -2.

The fdk reference says the 0 in the ImportFormats() api means to apply the 'default' formats, whatever that is. It's not doing that either.

I have to solve the mystery of the FE_BadDocId (-2) error code. Then I can tune the FF_UFF_* import flags to what I actually want to import.

But, I appreciate the help!

Thanks!

- mike

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
Guest
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Got It!

Let me just say this is the third project I've written using the FDK and there is much I do not understand about it.

The problem was I was not using the F_ObjHandleT returned from the F_ApiOpen() routines in the F_ApiSimpleImportFormats() routine, I was using the F_ObjHandleT returned from the F_ApiGetId() routine and that doesn't seem to work. It will generate an error code of -2 (FE_BadDocId).

Jang: You are correct. I need to specify all the flags I want to import. While the fdk documentation says 0 is the default set of flags, it doesn't define what that means and I can tell you it at least doesn't mean FF_UFF_VAR.

Thanks for the help!

- mike

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
Advocate ,
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Mike,

Yes, the object handles can be a mystery sometimes. Good to see you've solved your problem.

BTW, If you are going to use the SimpleImportFormats on this or other projects, don't forget to include Constants.FF_UFF_REMOVE_EXCEPTIONS if you want to remove overrides to standard formats from the document.

Ciao

Jang

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
Guest
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Good point.

I have created a #define that ORs all of the FF_UFF_* together (including FF_UFF_REMOVE_EXEPTIONS). Our MO is to always import all formats from a single controller document to all other documents.

Thanks again!

- m

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
Mentor ,
Oct 18, 2012 Oct 18, 2012

Copy link to clipboard

Copied

LATEST

Michael,

The solution to your original problem is generally simple. It seems that you have figured it out, but let me add a little more insight.

F_ApiSimpleFormats() is used to import formats from one document to another. However, you were attempting to import formats to a book component object, but a book component is not a document. It's just a special book-related object that points to some document file via its FP_Name property. Otherwise, it has no real link to any document. Despite the appearance to the contrary in the GUI, books do not contain or own any documents, just these FP_BookComponent objects which are different.

You might think FM should be smart enough make that extra step to locate the associated document when you try to import to a component, but it does not. Nor is it smart enough to iterate through all associated documents when you attempt to import to a book, as the GUI implies that it can. Bottom line... to use SimpleImport, it must be from one document to another (or to and from book files I think, but note that this affects only what is stored in the book file itself, not any chapter files). A book component is not a document.

Russ

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