Copy link to clipboard
Copied
I am opening XML files which may have large tables that force the page layout to landscape. But as the table location is just the anchor and not the entire table contents, only the first page on which the table occurs is getting the landscape format. When I apply the master pages via the menu, this problem is corrected. So I tried to call that function after opening the file, but there is no effect. Does anyone have experience with calling the ApplyMasterPages function from a script when opening the file ?
Here is the event handler code that fires when opening an XML file. The ProcessTables( ) function takes several layout attributes and applies them to the table properties, so applying master pages has to be done after that, as the layout changes may affect the number of pages spanned by the table.
ProcessTables( oDoc );
var oCmd = app.GetNamedCommand( "ApplyMasterPages" );
Fcodes( [oCmd.Fcode] );
This does not do a thing on the opened document. But when I take the last two lines and put them in a new script and execute that, the result is what I need it to be. So why is the code not firing when I call it in my event handler ? Any ideas ?
4everJang
Dear fellow scripters,
I have finally figured out why calling the ApplyMasterPages method via Fcodes( ) does not work in my event handler. Even though the event is called after the file was opened, the app.ActiveDoc property is not yet set at that time. This seems to happen only after all the processing has been done and the document appears on the screen. Which is bad news for me, as I really need to run this immediately after opening the file (it is going to run on the FrameMaker Publishing Ser
...Copy link to clipboard
Copied
Hi Jang,
I see no one has attempted an answer, so I thought I would reply just for moral support. In truth, I don't know the answer either. I have run into unreliable behavior with master page application before, though, so this is not a surprise to me. I have not done exactly what you are trying to do, but I have seen cases where master page application just doesn't work as expected. I think I have had to refresh the screen, maybe even save and reopen the document for the changes to appear. You have been doing this a long time, so I suspect you have already tried these things... Maybe also try a reimport of the template, with the page layout option?
Russ
Copy link to clipboard
Copied
Hi Russ. I am trying all the tricks and usually it is me who wins, not FrameMaker. But sometimes it is a hard battle indeed. Thanks for the support.
Copy link to clipboard
Copied
Hi,
Could you do UpdateBook(), passing in a single param, Constants.FS_UpdateBookMasterPages?
Copy link to clipboard
Copied
Thanks for the suggestion, but there is no book.
Copy link to clipboard
Copied
Dear fellow scripters,
I have finally figured out why calling the ApplyMasterPages method via Fcodes( ) does not work in my event handler. Even though the event is called after the file was opened, the app.ActiveDoc property is not yet set at that time. This seems to happen only after all the processing has been done and the document appears on the screen. Which is bad news for me, as I really need to run this immediately after opening the file (it is going to run on the FrameMaker Publishing Server and therefore does not have a user interface or even a screen).
The Fcodes( ) work on the active document, so there currently is no way around this. Maybe I could try and use one of the other events, such as view change. I will experiment with that. I do think that the activeDoc property should be set by FrameMaker as soon as a document is opened (before the PostOpen events are triggered), so I have sent a message to the dev team about this.
If you use any code that requires app.ActiveDoc to be set in your event handlers, make sure your script contains some method of verifying that you are not working on another file which happened to be open (and would still be the activeDoc). This may give very unexpected results. In my case, nothihg happened as I have one file open only (working on the FPS) but who knows what might happen if your script fires on another document and you never notice that it did.
Kind regards
4everJang
Copy link to clipboard
Copied
One more thing I just thought about and it seems to work:
I added one line of code to my event handler to correct the incorrect timing of updating app,ActiveDoc by FrameMaker: In the event handler I have the Doc object for which the event handler is called (the document that was just opened). So I am actively setting the app.ActiveDoc property to point to that Doc object. Then the Fcodes( ) for ApplyMasterPages works on my newly opened Doc.
Happy again (but still want the fix to be made by the dev team) 🙂
Copy link to clipboard
Copied
There is no need to script anything. FrameMaker can assign master pages automatically by means of a mapping table on the reference pages. You create this table by clicking the function "Apply Master Pages" from the menu [format > Page Layout]
You can apply master pages to the first page only or on consecutive pages after a given paragraph format.
Copy link to clipboard
Copied
Hi tulpe-media,
I know that this is possible and I am using it. But a startup script first changes the sizes of table rows depending on attributes and this causes the table to take up more pages. That is when the master pages must be reapplied.
4everJang
Copy link to clipboard
Copied
Sorry, i was a bit quick (and stupid) with my answer. I misread and thought you were trying to apply individual master pages by script.
Thank you for your kind answer.