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

How can I autorun a script that will process an XML file on open?

New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

I am using Frame 11. I have a registered script that looks for event notification Constants.FA_Note_PostOpenXML. When this event fires, the script is supposed to examine the root element (so I only edit appropriate XML files), then make some edits to the file. Specifically, I want to be able to delete empty pages, remove room for side heads, and fix table formatting (such as left indent, which I can't directly access, apparently, in the EDD or R/W rules). The snippet of code that starts doing the work follows:


Notification(Constants.FA_Note_PostOpenXML,true);

function Notify(note, object, sparam, iparam) {

    switch (note) {

        case Constants.FA_Note_PostOpenXML:

            doTheWork();

            break;

            }

}

function doTheWork() {

    var doc, flow, root, elemName, mPageAttrib, topicElem, topicElemName, allAttribs;

    doc = app.ActiveDoc;

    flow = doc.MainFlowInDoc;

    root = flow.HighestLevelElement; // will always get something even if unstructured document

    while(root.ObjectValid()) { //only do something for structured docs

        elemName = getElementName(root);

        ...more code to do stuff....

    }

}

I then check the root element name, and if it matches, I make some changes. This code works fine when run manually. But, when run as a registered script, the app.ActiveDoc object is invalid, and there is no structure to edit. (I added debug line if(!doc.ObjectValid()){alert("not valid");}, which is not included above.) It appears that the Constants.FA_Note_PostOpenXML event fires as soon as the XML file is opened, but BEFORE Frame actually reads it.

Does anyone have any recommendations on how to work around this? Is there another event I could use instead of Constants.FA_Note_PostOpenXML? Is there any other way to automatically manipulate an XML file when it loads?

Thanks in advance

TOPICS
Scripting

Views

545

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

Community Expert , Feb 06, 2014 Feb 06, 2014

The Notify event receives four parameters: note, object, sparam, and iparam. For the event you are using, object should be the document object of the FrameMaker document being opened. So, you should be able to use this:

doTheWork(object);

Make sure you update your doTheWork function to receive the Doc object:

function doTheWork(doc) {

    var flow, root, elemName, mPageAttrib, topicElem, topicElemName, allAttribs;

    flow = doc.MainFlowInDoc;

    root = flow.HighestLevelElement; // will always get so

...

Votes

Translate

Translate
Community Expert ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

The Notify event receives four parameters: note, object, sparam, and iparam. For the event you are using, object should be the document object of the FrameMaker document being opened. So, you should be able to use this:

doTheWork(object);

Make sure you update your doTheWork function to receive the Doc object:

function doTheWork(doc) {

    var flow, root, elemName, mPageAttrib, topicElem, topicElemName, allAttribs;

    flow = doc.MainFlowInDoc;

    root = flow.HighestLevelElement; // will always get something even if unstructured document

    while(root.ObjectValid()) { //only do something for structured docs

        elemName = getElementName(root);

        ...more code to do stuff....

    }

}

-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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

LATEST

Thanks! That did it.

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