Copy link to clipboard
Copied
Hey there,
I would like to save (multiple) *.fm files as XML, preferably via command line and was pointed to this forum by the Technical Support.
So far I don't have any experience with ExtendScript but general programming experience is available.
Edit: Using FrameMaker 12
Appreciating any hints in the right direction or a simple solution.
Thanks and best regards!
Copy link to clipboard
Copied
Hi adhese,
With the right skillset and a modest amount of code, this is not a difficult task. Having said that, though, ExtendScript is tricky to understand at first, even for a seasoned FrameMaker developer. Additionally, the XML export process has the potential for many complicating factors. While initiating a save action is reasonably simple, the management of possible errors, contingencies, etc. may not be.
Also, you mention the command line, which is another hurdle. I assume you are talking about the Windows command prompt, Run dialog, etc. In order to save as XML, FrameMaker has to be open first. So, a command line action would first need to open FM, then FM would need to open all the required FM files and initiate the save automatically. While this is possible, it adds a significant layer of complexity, especially with determining just what files should be opened and then saved. If you don't absolutely need this level of automation, I'd highly recommend a process where you open FM yourself, open the desired files, then run a script to do the rest. Or at the very least, open FM yourself, then tell the script which files to open and then save.
Here is a simple script that will save the currently-active document as XML. It is a basic set of code to get you started, as you would likely want more layers to locate and save multiple files at once. Note that it has minimal error checking. It is just a little something to help you out. A production-worthy script should have a bit more to make it robust and reliable. I hope this helps.
Russ
//Call the function to do the save.
saveAsXml(doc, "SomeApp");
//Here is the function.
//It saves a binary FM file as XML. It expects a valid
//document object and a structure application name.
//The document is expected to have a *.fm extension.
//The application name should be a string. To use the
//default application, if any, specify an empty string.
//If you specify an invalid (ie, non-existent) application
//name, the save action will likely fail.
function saveAsXml(doc, structureApp)
{
//Make sure we have a valid document object
if(!doc.ObjectValid())
{
alert("Document object is not valid. Cannot continue.");
return;
}
//Get the default properties for the save
var props = GetSaveDefaultParams();
var propIndex;
//Set the destination file type (XML)
propIndex = GetPropIndex(props, Constants.FS_FileType);
props[propIndex].propVal.ival = Constants.FV_SaveFmtXml;
//Set the save mode to "Save As"
propIndex = GetPropIndex(props, Constants.FS_SaveMode);
props[propIndex].propVal.ival = Constants.FV_ModeSaveAs;
//Set the structure app for the save.
propIndex = GetPropIndex(props, Constants.FS_StructuredSaveApplication);
props[propIndex].propVal.sval = structureApp;
//Get the current filepath of the document and replace the .fm extension with .xml
var filepath = doc.Name;
filepath = filepath.replace(".fm", ".xml");
//Allocate a PropVals() structure to capture the save results.
//These may not be used, but the array is a required parameter
//of the Save function.
var returnProps = new PropVals();
//And finally, do the save.
doc.Save(filepath, props, returnProps);
}
Copy link to clipboard
Copied
I forgot this part... this should be at the top of that code to capture the currently-active document. My apologies.
//Get the currently-active document.
var doc = app.ActiveDoc;
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more