While many users begin experimenting with the FEMAP API within the API Programming window available in FEMAP, the API can also be written in most programming languages, as long as you can transfer over the type library. Bringing the FEMAP type library into C# is very simple; within your Visual Studio window go to Project, Add Reference… then in that dialog window go to COM on the sidebar. Within this list you should be able to find your version of FEMAP and add it, if not go to browse and find “femap.tlb” within the highest level folder of your FEMAP installation. This will allow you to access FEMAP objects and methods using C#.
To initialize the program you first need to be able to fetch the active model. To do this you must start with the code below. To use the Marshal object that is seen below you must first declare the System.Runtime.InteropServices namespace at the beginning of your program.
pModel = (femap.model)Marshal.GetActiveObject("femap.model"
pModel = null;
System.Environment.Exit(1);//Exits if there is no active model
You do not always need to fetch an active application of FEMAP in your program. Instead, you could create a new instance of FEMAP by using the code below.
pModel = new femap.model(); pModel.feAppVisible(true);//Makes instance visible
One of the more difficult issues when using programming languages other than Visual Basic with FEMAP is the lack of a native Variant type. Within C# they have the object type, which is very similar to a Variant. The major advantage of this object type is how easy it is to convert between different types. The code below shows how to properly convert an object to a double array using the C# syntax.
double XYZ = new double[nodeCount * 3]; XYZ = (double)nodeXYZ;
Attached code is a C# example that finds the displacement in each direction for selected nodes, and then prints the values to FEMAP’s built in data table. This code shows how to properly use the object type in C# to access the full capabilities of the FEMAP API. One major advantage of Visual C# using Visual Studio is that it automatically builds an executable file from program and stores it in “Documents\Visual Studio\projects\PROJECT_NAME\PROJECT_NAME\bin\Debu