Cancel
Showing results for 
Search instead for 
Did you mean: 

API - Export freebodies to txt

Experimenter
Experimenter

Hello, 

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.

 

11 REPLIES

Re: API - Export freebodies to txt

Experimenter
Experimenter

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.

Re: API - Export freebodies to txt

Experimenter
Experimenter

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. 

Re: API - Export freebodies to txt

Siemens Phenom Siemens Phenom
Siemens Phenom
Have you simply tried copying the freebodies directly from one model to another? If you simply open both models in the same FEMAP session, and have the model that you want to copy into active, the following API should copy all the freebodies from the other model. A word of warning though, I wrote this API fairly quickly just to show the process... it doesn't check every return code like it probably should and assumes that the "current model" probably doesn't have any freebodies so that you can simply copy to the same IDs... it will overwrite any existing freebodies in the current model with IDs that match the original ones. It would have a fairly simple change though to just store with a new ID if that was what you wanted. Also this is setup to run in the FEMAP API environment, not from Excel or some other external language, but again, that could also be done fairly easily. Hope this helps. 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 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 Set fb = App.feFreebody 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 While fb.Next() App.feAppSetModel( CurrentModel ) fb.Put(fb.ID) App.feAppSetModel(OtherModel) Wend App.feAppSetModel( CurrentModel ) End Sub

Re: API - Export freebodies to txt

Siemens Phenom Siemens Phenom
Siemens Phenom

I guess that did not post too well...Here is an attached file...

 

 

Re: API - Export freebodies to txt

Experimenter
Experimenter

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!

Re: API - Export freebodies to txt

Experimenter
Experimenter

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?

Re: API - Export freebodies to txt

Siemens Genius Siemens Genius
Siemens Genius

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.

Re: API - Export freebodies to txt

Experimenter
Experimenter
Thanks!! I reached a similar solution on my own. Your code is much appreciated

_____________________________________________________________ This e-mail transmission contains information that is confidential and may be privileged. It is intended only for the addressee(s) named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited. Please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated.

Re: API - Export freebodies to txt

Experimenter
Experimenter

what is the advantage of using this API than "Save as" another femap model directly?