Skip navigation
Currently Being Moderated

Extendscript that runs "Apply Master Pages"

Dec 26, 2013 7:15 AM

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!

 
Replies
  • Currently Being Moderated
    Dec 26, 2013 7:46 AM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 8:10 AM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 8:13 AM   in reply to rombanks

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

     

    Fcodes([app.GetNamedCommand("ApplyMasterPages").Fcode]);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 8:47 AM   in reply to frameexpert

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 9:54 AM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 11:12 AM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 12:22 PM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2013 12:47 PM   in reply to 4everJang

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 27, 2013 5:54 AM   in reply to rombanks

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points