Run Stress Simulation by code

By Xiaodong Liang

Currently, API has not exposed the ability to work with Stress Simulation. The only way which may be of a bit help is to execute the corresponding commands by ControlDefinition.Execute. e.g. in this case, the command is “”

“FeaSimulateCmd”.

image

But this can only pop out the dialog, instead of running it automatically. A workaround is to take advantage of VB: SendKeys since the default focused button in this dialog is [Run]. That is to say, we send key [Enter] to the dialog thus it can be executed automatically. I have to confess, however SendKeys is not always working in all cases. But in this case, it is quite simple. It works well at my side.

 

image

 

In addition, you need to make sure to activate the enviorment of Sress Simulation before running simulation. The following is a code demo.

 

Public Sub DoFea()

     Dim oDoc As Document

     Set oDoc = ThisApplication.ActiveDocument

     ‘if stress simulation is activated
     Dim UIManager As UserInterfaceManager

    Set UIManager = ThisApplication.UserInterfaceManager

If UIManager.ActiveEnvironment.InternalName <> "FEA Environment Internal Name" Then

        ‘if it is not activated

        Dim environmentMgr As EnvironmentManager

        Set environmentMgr = oDoc.EnvironmentManager

        Dim dsEnv As Environment

        Set dsEnv = UIManager.Environments.Item("FEA Environment Internal Name")

        Call environmentMgr.SetCurrentEnvironment(dsEnv)

    End If

   ‘get [simulation] command

    Dim oCol As ControlDefinition

    Set oCol = ThisApplication.CommandManager.ControlDefinitions("FeaSimulateCmd")

    ‘send [enter] key to the dialog to mimic the clicking [Run]

SendKeys "{ENTER}"

‘execute the command. The dialog will pop out and execute run automatically.
    oCol.Execute

End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading