目前没有应力分析的API,能做的只是直接执行相关的命令。例如若要执行分析,则命令名是:“FeaSimulateCmd”
而即便如此,只是弹出对话框。要让 【运行】自动执行,还需要模拟点击了【运行】按钮。这里可以用到VB中的一个技巧SendKeys。即发送【Enter】键给这个对话框,因为该对话框弹出时默认的焦点按钮时【运行】。【Enter】 则意味着按下了这个按钮。
另外,还需要首先激活应力分析的环境。 请参考如下代码:
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