In the extendscipt toolkit data browser, I don't see an option to apply master pages to a document (as in Format-->Page Layout--> Apply Master Pages...).
Shouldn't this be some kind of a function? Am I missing something?
Thank you in advance!
I have answered this same question last week on the FrameScript forum. In that scripting product, there is an option to execute any FrameMaker command as long as you can find the command name. Looking for the command in config files I noticed that the command is not there. It is probably added to the menu via MasterPages.DLL which would imply that it is implemented as a FrameMaker client. This means you should be able to call the command via CallClient, but you would have to know the client name and the command to use. If I find out more, I will post a new reply here. Or maybe someone from Adobe can enlighten us on this point.
Thank you for your prompt response! I've already tried using CallClient(), but for some reason, I get an error saying that app.CallClient() is not a function. I doubt if Adobe guys respond. Our only hope is the Adobe community experts like you.
My best wishes,
CallClient is a global function, not a method of the app object. But I am not sure about the client name and the command you should supply for the ApplyMasterPage functionality. I am trying out some stuff with the info in the linked thread and will post something here when I find the solution. Just my kind of fun for a sunday afternoon (in my country the day after Xmas is a holiday).
It looked so strange to me that I did not think it would be the solution. But it is. I tested it on a document with a master page application table, comparing the result with the result that would appear after calling the function from the GUI. It works.
Kind of crazy that this is not documented in the Scripting Guide, but I guess the warning in the FDK Guide is not there for nothing. The Fcodes ( ) method does not give any error handling options and does not set FA_errno. So there is no way to check whether it has worked or not.
Hi Jang, Rick,
I appreciate your responses, guys!
I tried running the FCodes command in the Exscript tool, but only got the "Result 0" message. If Jang said this command works, apparently I ran it in a wrong way.
I hope you will enlighten me how to do that.
Happy Christmas to you!
My best wishes,
The return code for Fcodes is always 0, and there is no FA_errno either. This means you just have to assume that the command really worked, or find a way to check the document(s) after running the ApplyMasterPages command to make sure that the result is what you want.
To see whether it really works, create a document with a couple of pages, define the rules in the StructMasterPageMaps (for structured docs) or UnStructMasterPageMaps table, then run the Apply Master Pages command via the menu and see what the document looks like. Then manually overrule one or more body pages in the document, then run the ExtendScript and check the result.
Thank you for your explanations about this command!
As you said, this command (with an extremely vague syntax I should say), does work.
I understand the middle part, but it's not clear to me what the Fcode(s) parts exactly do.
The one line from Oliver John's earlier post is a combination of finding the Fcode, entering it into an array and send the array of Fcodes to FrameMaker to be executed. The Fcodes( ... ) command sends one or more Fcodes to FrameMaker, which are then executed. They could be keystroke sequences or, in the case we're discussing, a menu command. So the same could be done with the following code, which separates all steps:
var oCodesToBeExecuted = [ ];
var oMyCommandObject = app.GetNamedCommand ( "ApplyMasterPages" );
var iTheCode = oMyCommandObject.Fcode;
oMyCodes.push ( iTheCode );
Fcodes ( oCodesToBeExecuted );
I hope this explains the method. By the way, if you want to apply the master pages on a book object (i.e. on all its chapters, using the Apply Master Pages command in the Book's Format menu), you should replace "ApplyMasterPages" by "ApplyMasterPagesBook".
Thank you very much for your detailed explanation! If I understood correctly, the array is needed to specify the whole path to the command under the format menu, right?
Question: oMyCodes is not defined anywhere in the code you posted. How is it supposed to work?
Thank you again!
Hello again Roman,
No, the path to the menu is irrelevant. Each command has a unique name. This means that even if the command is moved to another menu (by configuration files, for instance), the code does not change.
The array is used so that you can pass more than one command to the Fcodes ( ) function at one time. If you would also want to save the document after applying the master pages, you could add the Fcode for "SaveDocument" to the array. Then passing the array of codes to the Fcodes ( ) function will cause all those commands to be executed one after the other. This would not be my recommendation, though. Only use Fcodes ( ) for command that are not otherwise available in ExtendScript and try to design a checking mechanism to find whether the command was actually executed.
The oMyCodes in my code sample should have been changed to oCodesToBeExecuted. I had oMyCodes first but decided to rename it and forgot to change that line.
One note about this thread: you should only use Fcodes as a last resort. Fcodes require an active, on screen document, so they don't work on documents you might open invisibly when processing all documents in a book or folder. In this case, you have no choice because the Fcode is the only way to do it. But if you have a choice between an Fcode and a built-in command, you should use the built-in command.
I wonder if there is there a way to make this script event-driven, so that it will be triggered after importing formats from another file? The FM help says that 'Registered' scripts are event-driven, but there is not even a word on how to define the event.
Thank you for your response in advance!
My best wishes,