Here is a simple request for those well versed in FEMAP API:
Given a model database that contains a series of freebodies, export all of the freebodies and their object properties to a .txt file (or excel, or csv whatever is easier or already coded..)
If an analyst were to open a separate yet identical model database without freebodies, it is a pain to create them all again. If this data is backed up in a .txt file one should be able to re-create the freebody objects and import using the .txt file. Page 1413 of the API reference is good but I would like a simple example.
I am a Python coder and VB beginner, I just need a kick-start to at least get the objects and data structure out of Femap and into something i can work with. The re-import subroutine will be a good exercise for me.
A workaround you may consider if an API is not that important:
Export your model to a Neutral file (.neu). Then in a text editor delete everything except the data blocks related to the freebodies (Data Block IDs 1070 & 1071).
Your abridged neutral file will look something like this:
-1 1070 <many lines clipped> -1 -1 1071 <many lines clipped> -1
Now you can simply re-import the freebodies if you happen to lose them.
Nah, API is important.
Besides, if the scope of my task is to develop tools optimizing prodictivity in stress analysis workflows, efficiency is key.
Check this attachment out... an Excel VBA FEMAP Freebody Copy / Paster. All it does is save fefreebody properties to instances of a static type in VBA.
From there, copy/paste functionality between active FEMAP sessions is merely a click of a button. From this original solution I have built it out even further... but I can't share v2.
In v2, nodes and elements, view properties etc. may all be displayed and modified in batches on a worksheet, so you don't have to cycle through every single freebody and change view options.
I don't really need anymore help on this one... I forced myself to code a solution that is more robust than your suggestion and runs from Excel...
I'm sure I will have more questions about API soon and I appreciate your responses!
Hi @grudy, when I run this API it appears to copy the Freebodies over but it only grabs the freebody ID/title and Display Mode? Doesn't bring the elements/nodes/CSys... maybe a line missing somewhere?
Freebody entities are stored a little differently than normal properties on an object; as such they require a little additional work to move them between models via API. I tweaked George's code a bit to reflect this:
The HTML Clipboard
Sub Main Dim App As femap.model Set App = feFemap() Dim CurrentModel As Huge_ Dim OtherModel As Huge_ Dim numModels As Long Dim vModel As Variant Dim fb As Freebody Dim nNextID As Long Dim nNode As Long Dim nElem As Long Dim vNode As Variant Dim vElem As Variant Dim fsEnt As femap.Set Dim fcs As femap.CSys Set fsEnt = App.feSet Set fcs = App.feCSys App.feAppGetModel( CurrentModel ) App.feAppGetAllModels( numModels, vModel ) If numModels =2 Then If vModel(0) = CurrentModel Then OtherModel = vModel(1) Else OtherModel = vModel(0) End If Else MsgBox( "You must have 2 models open to use this API", vbOkOnly, "Freebody Copy" ) End End If App.feAppSetModel( OtherModel ) If App.Info_Count(FT_FREEBODY) = 0 Then MsgBox( "Other Model contains no Freebodies to Copy", vbOkOnly, "Freebody Copy" ) App.feAppSetModel( CurrentModel ) End End If nNextID = App.Info_MinID( FT_FREEBODY ) Set fb = App.feFreebody While fb.Next() If fb.DisplayMode <> FBD_DISPLAYMODE_SECTION Then fb.GetElements( nElem, vElem ) fb.GetNodes( nNode, vNode ) End If If fb.CSys > 2 Then fcs.Get( fb.CSys ) End If App.feAppSetModel( CurrentModel ) If fb.DisplayMode <> FBD_DISPLAYMODE_SECTION Then fsEnt.AddArray( nElem, vElem ) fb.SetElements( True, fsEnt.ID ) If fb.DisplayMode = FBD_DISPLAYMODE_INTERFACE Then fsEnt.Clear() fsEnt.AddArray( nNode, vNode ) fb.SetNodes( True, fsEnt.ID ) End If End If If fb.CSys > 2 And Not fcs.Exist( fb.CSys ) Then fcs.Put( App.Info_NextID( FT_CSYS ) ) fb.CSys = fcs.ID End If fb.Put(fb.ID) App.feAppSetModel(OtherModel) Wend App.feAppSetModel( CurrentModel ) App.feViewRegenerate( 0 ) End Sub
The coordinate system not copying over is a different story though. The coordinate system is stored as just an ID on the freebody object itself, similar to most other objects. When copying items between models like this, if the ID doesn't exist in the target model, it's not going to work properly. I've also modified the code to save a coordinate system in the new model, however you need to keep in mind that this also applies to nodes, elements, etc. You'll need to make sure that node/element IDs in the target model are identical and that the freebody results make sense.