Can I use FME Objects to run an FME mapping file or a Workbench workspace
From Fmepedia
Q) Can I use FME Objects to run an FME mapping file or a Workbench workspace?
A) The FME Objects API does not offer this functionality. However, there is an entry point on FME DLL that allows you to run a mapping file or workspace translation from an application. The rest of this article describes how to go about doing this in the context of C++.
To get started, you need to include the $(FME_HOME)\fmeobjects\cpp\fme.h header file. It defines the two entries points you'll need for the job: FME_Translate() and FME_SetOutOfMemoryCallback(). The code for running a mapping file or workspace looks like this:
static void outOfMemory(const char* message)
{
if (message)
cerr << message << endl;
exit(1);
}
main(int argc, char **argv)
{
FME_SetOutOfMemoryCallback(outOfMemory);
int returnCode = FME_Translate(argc,argv,FME_TRUE,NULL,NULL);
return returnCode;
}
You'll probably want to protect your process from anything that might go wrong during the translation because given the number of bad out of spec data files in the world, this happens more than anyone would like! To do this, we recommend that you run FME_Translate() in its own process, that way if anything were to go wrong, the FME process dies and cleans itself up nicely without affecting the rest of the application.
If you're working on Unix, you'll need to create a pipe to the child translation process, and then display the output of the translation to the user of your program. In Windows, this process is a bit trickier so we've included the FmeSpawner class that is used by both FME Workbench and the FME Universal Translator GUIs to get the output of translation.
Download the fmeSpawner.cpp C++ code and fmespawner.h Help(?) file. You can also read more about this on this old FME Mailing list here: http://safe.com/archives/FMEObjectsList/msg00212.html.
If you are familiar with advanced system level programming, it should be fairly straightforward to set this up as long as you are willing to invest a few hours to understand it and play with it a bit. On ther other hand, if you find this a little intimidating and you'd rather get some help setting it all up, Safe Software offers an Application Development Assistance program (http://www.safe.com/services/development/index.php) that can look after your needs.
