Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

looping through groups to save pictures using femap api

Hello,

I'm new in femap api. I'm trying to create a script that loops into different groups in my model and takes a picture (after post showing different results for each of them). I do not know however to show/post/activate groups from the list of groups I have stored using:

 

Dim g1 As femap.Group
Set g1 = App.feGroup

Dim gcount As Long
Dim listID As Variant
Dim gtitles As Variant

g1.GetTitleList (0, 0, gcount, listID, gtitles)

 

Thanks for any help.

Manu 

6 REPLIES

Re: looping through groups to save pictures using femap api

I've got an API that animates groups so I'll modify it for your application and post it shortly.

Best Regards,
Chip Fricke
Principal Applications Engineer - Femap Product Development
Solution
Solution
Accepted by topic author Manurico
‎06-07-2017 10:48 AM

Re: looping through groups to save pictures using femap api

Give the below a try. It utilizes the API as well as the macro recording feature in FEMAP to show the active group. Change where pictures are saved by putting your own file path where fName is defined. This API makes the assumption you have your desired contour vector displayed.



Sub Main
Dim App As femap.model
Set App = feFemap()

Dim vi As femap.View
Set vi = App.feView
Dim g1 As femap.Group
Set g1 = App.feGroup
Dim oSet As femap.OutputSet
Set oSet = App.feOutputSet
Dim vec As femap.Output
Set vec = App.feOutput
Dim gID As Long, viewID As Long

'Get the active view
App.feAppGetActiveView (viewID)
vi.Get(viewID)

Dim fName As String, title As String

'Save picture file(s) to
fName = "C:\Users\y2gfxr\Desktop\TEST"
If Right(fName,1) <> "\" Then
fName = fName+"\"
End If

i = 0
While g1.Next()
gID = g1.ID
g1.Get(gID)
g1.Active = gID
If i < 1 Then
ActivateGroup()
i =1
End If
App.feViewRedraw(0)
App.feViewRegenerate(0)

App.feFilePictureCopy2(FPRG_WINDOW)
'If you make the first paramter below = TRUE, an interactive dialog box will open each time asking for a file name
App.feFilePictureSave2(False,FPRG_WINDOW,FPM_BMP,fName+Str$(gID)+"_"+g1.title)

Wend

End Sub
Sub ActivateGroup()
Dim App As femap.model
Set App = feFemap()

Dim program As String
program = "{~2054}"
App.feFileProgramRun(False,True,False,program)

While App.feFileProgramRunning() = FE_OK
Wend
End Sub

Re: looping through groups to save pictures using femap api

Thanks RCatania,

This is exactly what I was looking for. It also shows me more about how api objects operate.

Regards

Manuel

Re: looping through groups to save pictures using femap api

Hi, where do you get the reference for the buff parameter {~2054}?

 

Solution
Solution
Accepted by topic author Manurico
‎06-07-2017 10:47 AM

Re: looping through groups to save pictures using femap api

You can also change which group is being displayed in a view, this API will save the initial group display setting, loop through all groups, saving BMPs, and then set the display back to where it was -

 

The HTML Clipboard

Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim feView As femap.View
    Set feView = App.feView

    Dim feGroup As femap.Group
    Set feGroup = App.feGroup

    Dim viewID As Long

    App.feAppGetActiveView( viewID )

    Dim iniGroupSetting As Long

    Dim sDir As String
    Dim fName As String

    App.feFileCurrentDirectory( sDir )

    If feView.Get( viewID ) = FE_OK Then
        iniGroupSetting = feView.Group
        While feGroup.Next = FE_OK
            feView.Group = feGroup.ID
            feView.Put( viewID )
            App.feViewRegenerate( viewID )
            fName = sDir + feGroup.title

            App.feFilePictureCopy2(FPRG_WINDOW)
            'If you make the first paramter below = TRUE, an interactive dialog box will open each time asking for a file name
            App.feFilePictureSave2(False,FPRG_WINDOW,FPM_BMP, fName )
        Wend
        feView.Group = iniGroupSetting
        feView.Put( viewID )
        App.feViewRegenerate( viewID )
    End If

End Sub

Solution
Solution
Accepted by topic author Manurico
‎06-07-2017 10:47 AM

Re: looping through groups to save pictures using femap api

If you open the Program File pane, and hit the red Record button, you can create macros of operations you do in the GUI.  Using the "Show Active" option at the bottom right corner of the Femap screen on the group tab will print the strings shown in the image below ($ = comment).  For the code to work above, you only need to take the last string (i.e. program  = "{~2054}") and it will execute as a macro.  It is good to be thorough when using this feature through the API since it is easy to skip a button when creating your strings.  This will prevent the macro from running.

 

ProgramFile.pngGroup1.png