Wednesday, August 18, 2004

FileMaker via ActiveX in C#

I had trouble finding documentation about Automating FileMaker from C# (using FM Developer 6), so I’ve written up some of my notes…

First, you have to “add reference”, going to the COM tab and selecting the FM type library. Hit the “Select” button, and then hit OK.

Add a “using FMPRO50Lib;” clause to the beginning of the file where you will be using FM Automation.

Here is the basic code to call a script in the active DB.

ApplicationClass fmApp = new ApplicationClass();
IFMIDocuments fmDocs = (IFMIDocuments) fmApp.Documents;
IFMIDocument fmDoc = (IFMIDocument)fmDocs.Active;
string strScriptName = "ReturnToApprovalRec";
fmDoc.DoFMScript (ref strScriptName);

To find a particular document, you will want to loop the open documents. NOTE: The name shown in the message box is the FULL PATH - you will have to dig the DB name out of there.

IEnumerator myEnum = fmDocs.GetEnumerator ();
while (myEnum.MoveNext ()) {
IFMIDocument myDoc = (IFMIDocument) myEnum.Current;
MessageBox.Show (myDoc.FullName);
}

To open a new DB, you would want to use IFMIDocuments.Open

There are not many things that you can automate (see the object browser), but at least the above outlines the things that CAN be done.

------------------------

Notes for 64 bit machines

There are a number of things that you have to be aware of when using FileMaker on a 64 bit machine

  • Filemaker help cannot be accessed until you install WinHlp32.exe. See http://www.microsoft.com/downloads/d...displaylang=en
  • The FileMaker ODBC driver setup must be done in a somewhat strange way. I found the solution here: http://postgresqldbnews.blogspot.com/2008/03/32-bit-odbc-drivers-in-vista-64.html. Short version: there are two versions of odbcad32.exe in the windows directory. Look for the version inside the syswow64 directory, and use that to set up 32 bit ODBC drivers.
  • AmImEx must be compiled in 32 bit mode for it to be able to access the FM ODBC driver
  • In Windows 7, I had the experience that the COM component for FileMaker was not installed even after FileMaker installed successfully. To fix this, search from "cmd.exe" in the start menu, right click on it and execute as administrator, cd (change directory) to the directory where FileMaker is installed, and execute
    "NameOfFilemaker.exe" /REGSERVER

No comments: