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

Extendscript that runs "Apply Master Pages"

Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

2.3K

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

correct answers 1 Correct answer

Advocate , Dec 26, 2013 Dec 26, 2013

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 m

...

Votes

Translate

Translate
Advocate ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

http://forums.adobe.com/thread/880398 discussses this issue, but it's still not clear how to invoke the Apply Master Pages command.

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
Community Expert ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Did you try the answer that was in the other forum thread?

Fcodes([app.GetNamedCommand("ApplyMasterPages").Fcode]);

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 ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Rick,

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.

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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 ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Jang,

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.

Thanks again!

Roman

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 ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Roman,

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".

Kind regards

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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 ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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

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
Community Expert ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

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.

Rick

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Rick,

Thank you for your valuable input!

My best regards,

Roman

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
Participant ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Jang,

Great explanation, thank you! Now I understand why an array is used in this case.

My best regards,

Roman

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
Participant ,
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

Guys,

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,

Roman

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
Community Expert ,
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

Roman, Please start a new thread for this question and I will answer it. Rick

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
Participant ,
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

LATEST

Hi Rick,

Sure, I will. Thank you very much in advance!

My best regards,

Roman

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 ,
Dec 26, 2013 Dec 26, 2013

Copy link to clipboard

Copied

Hi Roman,

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).

Kind regards

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