Skip to main content
Participant
April 17, 2015
Question

Automate the process of saving Framemaker documents (*.fm) as Xml Files

  • April 17, 2015
  • 2 replies
  • 1552 views

Hi,

I am new to framemaker. We have a list of Framemaker document files (*.fm files) coming  into a folder.  We need to pick up these files and convert to xml format (same as the saveAs opertion from the File menu).

I have written the follwing function to Save fm files to xml

Code to Save fm files to xml files

function saveAsXml (doc) {

   // Get required parameters for the save function.

    var params = GetSaveDefaultParams();

    var returnParamsp = new PropVals();

  

    // Replace the .fm extension with .mif.

    var saveName = doc.Name.replace (/\.[^\.\\]+$/,".xml");

  

    var i = GetPropIndex(params, Constants.FS_FileType);

    params.propVal.ival = Constants.FV_SaveFmtXml;

    // Save the document as XML.

    doc.Save(saveName, params, returnParamsp);

}

How to automate this process so that code checks -

1) New fm files in the folder

2) Saves the fm file as xml

3) Moves the saved fm file to a different folder

Thanks,

GC

[Message moved to Scripting Forum by moderator]

This topic has been closed for replies.

2 replies

frameexpert
Community Expert
Community Expert
April 20, 2015

JoH's script is good but it may eventually time out or run out of memory. Where are the .fm files coming from? A better approach may be to have a script on their machine that will automatically save and send an XML file to the incoming folder whenever they close the .fm document.

www.frameexpert.com
Inspiring
April 20, 2015

Have a look at the sample script below. The "while" loop waits for the specified number of milliseconds, then reads the contents of a directory and processes every individual file in the directory. In my example, it just prints the file path to the console. You would replace this part with your Open / Save as / Move sequence.

For more file system commands, refer to Adobe's Javascript Tools Guide, "File object functions".

var stop = false;

while( stop==false ) {

    // Wait for 20.000 ms

    $.sleep(20000);

    var fld = new Folder("c:/incoming");

    var filesInFld = fld.getFiles("*.fm");

    for(var f=0; f < filesInFld.length; f++) {

        // process the individual file

        $.writeln(filesInFld);

    }

    // Exit the  loop after 19:00

    var time = new Date();

    if( time.getHours() > 19 ) stop = true;

}