Skip to main content
rombanks
Inspiring
December 26, 2013
Answered

Extendscript that runs "Apply Master Pages"

  • December 26, 2013
  • 1 reply
  • 3334 views

Hello Framers,

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!

This topic has been closed for replies.
Correct answer 4everJang

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,

Roman


Hi Roman,

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.

Good luck

Jang

1 reply

4everJang
Brainiac
December 26, 2013

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.

Kind regards

Jang

rombanks
rombanksAuthor
Inspiring
December 26, 2013

Hi Jang,

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,

Roman

4everJang
Brainiac
December 26, 2013

Hi Jang,

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!

Roman


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.

Kind regards

Jang