Cancel
Showing results for 
Search instead for 
Did you mean: 

API generating GIF animated images of multiple outputs

Experimenter
Experimenter

Im using Femap version 11.2

 

I have been trying to get the following code to work; however, it keeps generating the animation of originally activated output, but it names them differently based on the ID. "OutSet.Active=title" has no effect on the generated files.

 

Example: I have 3 outputs with IDs: 1,2,3. "1" is activated before running the code so the window shows the animation. Code is run, all outputs selected. gif files generated with titles "1","2","3" but they all show animation of "1".

 

 

Sub Main
    Dim App As femap.model
    Set App = feFemap()
    Dim OutSet As OutputSet
    Set OutSet=App.feOutputSet
    Dim resultcases As Set
    Set resultcases=App.feSet

    info = "Select Cases"
    resultcases.SelectMultiID ( FT_OUT_CASE, 1, info )

    While resultcases.Next
	title=resultcases.CurrentID
	OutSet.Active=title
	rc=App.feFilePictureSave2(False,0,10,title)
    Wend
End Sub

 

 

 

I have searched for similar forum posts and came up with code below (and a few modified versions). However it only generates undeformed/non-animated gifs. The API help "F1" has nothing but dead ends or vague explanations.

 

 

Sub Main
    Dim App As femap.model
    Set App = feFemap()
    Dim OutSet As OutputSet
    Set OutSet=App.feOutputSet
    Dim resultcases As Set
    Set resultcases=App.feSet
    Dim viewID As Long
    Dim feView As femap.View
    Set feView = App.feView

    info = "Select Cases"
    resultcases.SelectMultiID ( FT_OUT_CASE, 1, info )

    While resultcases.Next
	title=resultcases.CurrentID
	OutSet.Active=title
	App.feAppGetActiveView( viewID )
	feView.Get(viewID)
	feView.OutputSet = 1
	feView.Put(viewID)
	App.feViewRegenerate(0)
	rc=App.feFilePictureSave2(False,0,10,title)

    Wend
End Sub

 

 

Thanks

 

-Tymek

 

6 REPLIES

Re: API generating GIF animated images of multiple outputs

Siemens Phenom Siemens Phenom
Siemens Phenom

You're not actually getting the ID of the Output Set.  Try this:

 

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

Dim vID as Long

App.feAppGetActiveView ( vID )

Dim resultcases As Set Set resultcases=App.feSet info = "Select Cases" resultcases.SelectMultiID ( FT_OUT_CASE, 1, info )
Dim osID as Long

resultscases.reset osID = resultscases.first While osID > 0 title = osID App.Info_ActiveID ( FT_OUT_CASE ) = osID
    App.feViewRegenerate ( vID ) 'Update the View rc=App.feFilePictureSave2(False,0,10,title)
osID = resultscases.next Wend End Sub

 

Best Regards,
Chip Fricke
Principal Applications Engineer - Femap Product Development

Re: API generating GIF animated images of multiple outputs

Experimenter
Experimenter

Your suggestion has the same result. It is not updating for the active output set. It is just updating the same output that was active when the code is first run. 

 

Example: Before the code is run, I can have output set "2" activated and the animation showing. Code is run and "1,2,3" selected. It will generate 3 gif files named "1,2,3" but they all show the animation for "2".

 

It seems like I need something in the loop that updates more than just the view. Something that re-creates whatever goes on when the user double clicks on an output set in the "model info" tree: this activates the output set, updates the view, and rebuilds/regenerates the animation on the selected case.

 

Thanks for the help

Re: API generating GIF animated images of multiple outputs

Experimenter
Experimenter

I believe FEMAP already has the functionality you are looking for: first setup your animated plot with the Animate-MultiSet style, then try File>Picture>Save and there is an animated GIF type available.

Re: API generating GIF animated images of multiple outputs

Experimenter
Experimenter

Although that is a useful function i am going to use, it is not what I am trying to do with this code.

 

I need to apply this to a larger number of output sets. I have several hundred modes that I need to generate a seperate animaions for.

Re: API generating GIF animated images of multiple outputs

Siemens Phenom Siemens Phenom
Siemens Phenom
Try the API below. Make sure to have your first output set selected and animating in the Model Info Tree before running.

I've jumped onto Chip's functionality. For some reason, the active output being set via the API does not change the active view while animating, nor does a Regenerate or Redraw. I will investigate this further. For now, the below takes advantage of the ability to run a program macro as well as the Event Callback functions. The macro is the same as using the output set toggles on the Post Toolbar from the GUI. Event Callback gives more control over how and when the program file will end.


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

Dim vID As Long
App.feAppGetActiveView ( vID )

Dim resultscases As Set
Set resultscases=App.feSet

info = "Select Cases"
resultscases.SelectMultiID ( FT_OUT_CASE, 1, info )
Dim osID As Long

resultscases.Reset
osID = resultscases.First
While osID > 0
title = osID
App.feAppGetActiveView ( vID )
App.Info_ActiveID ( FT_OUT_CASE ) = osID
Call ResultsSetToggle()
App.feViewRegenerate ( vID ) 'Update the View
rc=App.feFilePictureSave2(False,0,10,title)
osID = resultscases.Next
Wend
End Sub
Sub ResultsSetToggle()

Dim prg As String
prg = "{~824}"

rc = App.feFileProgramRun(False,True,False,prg)
rc = App.feAppEventCallback(FEVENT_PROGSTART,"{~824}")
App.feAppMessage(FCM_ERROR,"rc = "+Str$(rc))
While App.feFileProgramRunning
App.DialogAutoSkipMsg = 1
If App.feAppEventCallback(FEVENT_PROGEND,"") Then
Exit While
End If
Wend

End Sub


Re: API generating GIF animated images of multiple outputs

Siemens Phenom Siemens Phenom
Siemens Phenom

I had neglected to update the active view with the selected Output Set.  I've confirmed that this one works:

 

The HTML Clipboard

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

    Dim activeView As femap.View
    Set activeView = App.feView
    Dim vID As Long
    App.feAppGetActiveView ( vID )

    Dim resultcases As femap.Set
    Set resultcases=App.feSet

    Dim activeOutputSet As Long
    activeOutputSet = App.Info_ActiveID ( FT_OUT_CASE )
    info = "Select Cases"
    resultcases.SelectMultiID ( FT_OUT_CASE, 1, info )
    Dim osID As Long

    resultcases.Reset
    osID = resultcases.First
    While osID > 0
        activeView.Get ( vID )
        activeView.OutputSet = osID
        activeView.Put ( vID )
        App.feViewRegenerate ( vID )   'Update the View
        title = osID
        App.Info_ActiveID ( FT_OUT_CASE ) = osID
        rc=App.feFilePictureSave2 (False,0,10,title )
        osID = resultcases.Next
    Wend

    App.Info_ActiveID ( FT_OUT_CASE ) = activeOutputSet

End Sub

Best Regards,
Chip Fricke
Principal Applications Engineer - Femap Product Development