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

Autorun script that adds elements to an XML file on open with Notify event

New Here ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

Hello,

I am working with FrameMaker 2019 and I try to add some elements to an xml file based on a custom application when a new xml file is selected by the user.

I have managed to set the notification (with Constants.FA_Note_PostOpenXML) and register the script in FM, but I have to following strange behavior:

1. The object property of the Notify function does not seem to reflect the new xml doc object

2. By selecting the app.ActiveDoc object in order to insert elements in the xml file these elements are actually inserted but are not shown unless I first select to create a new xml file (with any type of structured application).

The code I use is as follows:

Notification(Constants.FA_Note_PostOpenXML , true);

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

switch (note) {

     case Constants.FA_Note_PostOpenXML:

     doWork();    

     break;

     }

}

function doWork() {

     var doc = app.ActiveDoc;

     var flow = doc.MainFlowInDoc;

     var elemBook = flow.HighestLevelElement;

     var ELEM_BOOK_META = doc.GetNamedElementDef("book-meta");

     // ... more element definitions

    

     var elementBookMeta = ELEM_BOOK_META.NewElement(elemBook.TextRange.end);

     // ... adding more elements to to the xml ...

}

As stated above,

If I pass the object parameter to my doWork function the elements are not added to the xml.

By executing doc.Redisplay() or doc.Reformat() the xml does not get updated with the added elements.

The only way to see the added elements is to create a new xml file (whatever structured application but for sake of simplicity assume that I always create xml files for my custom app) and come back to the previously created xml file.

Does anyone have any ideas for this behavior or how I can get the script to update the xml with my new elements?

Any help is appreciated.

Thanks.

TOPICS
Scripting

Views

339

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 ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

A couple of things: the new document may not be getting seen as the ActiveDoc. So you don't depend on this, change line 6 to

doWork (object);

and line 11 to

function doWork (doc) {

and remove line 12.

Also, make sure that your lines 16 and below are actually the correct syntax for doing what you want.

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 ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

Thank you very much for the reply.

When changing the lines suggested, and leaving only one element to be added to the new xml (just like to code in the original post) nothing happens.

The <book-meta> element is a valid object to be placed under <book> (this is the highest level element automatically inserted in the xml upon creation) based on my edd and dtd.

Adding some alerts in the doWork function I can see that:

after line with var ELEM_BOOK_META,  this is actually an element definition object,

after line with var elementBookMeta, this is actually an element object,

but nothing gets inserted in the xml. file.

The strange thing is that by using the originally posted code I can see the elements inserted in the xml file for a sec and then they disappear. If I do the process described in the original post the elements appear in the xml. As a note, if i save the xml file, close it and open it again the added elements are there.

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
Advisor ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

Vasilis,

   Independently of the mechanics of writing the particular script you described, I'd like to ask about the circumstances in which you will use the script. In particular, are the XML documents going to be edited in FrameMaker? Is the inserted content always the same, or does it vary, for example for different users or the date and time?

   I don't know your circumstances, but a different approach that you may want to consider is editing the documents in WYSIWYG view. You can provide users with a template that has the needed initial content. You can configure FrameMaker so that the browser resulting from the File > New command opens in the directory containing that template. The user can then complete the content using the WYSIWYG approach to editing structured documents that helps the user create valid documents that can then be saved as XML.

        --Lynne

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 ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

LATEST

Thank you very much for your reply,

This is indeed an interesting approach to the issue, but for this specific flow we want to be able to do it with ExtendScript by displaying a form, requesting some input from the user and then building the xml structure.

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