Stress Analysis via Visual Basic Application

Stress Analysis via Visual Basic Application

dominikkedzia
Observer Observer
292 Views
0 Replies
Message 1 of 1

Stress Analysis via Visual Basic Application

dominikkedzia
Observer
Observer

I'm working on some project that requires me to prepare automated Stress Analysis to run on previously generated model. 

Model generation is already done.

Now I need to execute stress analysis, which is normally fired from Envirments/Stress Analysis and then Analysis/Create Study.

Firstly I need Static Analysis and then Modal Analysis.

I'd like to know how to prepare Material, Contraints, Loads and Contacts.

 

For now I was managed to open Create Study window and that is it 😞

 

 

Dim oDoc As Document = ThisApplication.ActiveDocument

'if stress simulation is activated
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager

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

    'if it is not activated

    Dim environmentMgr As EnvironmentManager = oDoc.EnvironmentManager

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

    Call environmentMgr.SetCurrentEnvironment(dsEnv)

End If

'get Create Study Command
Dim oCol As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("FeaCreateSimCmd")

oCol.Execute()

 

 

^ it works.

 

At this point in couple of threads on forum I've seen suggestion to add this Control Definitions:

 

 

Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()

 

 

But it fails to do anythig and I've seen another suggestion to execute {SPACE} key between this two code blocks, so I had try with these two:

 

System.Windows.Forms.SendKeys.Send(" ")
'and
My.Computer.Keyboard.SendKeys(" ")

 

Both of them failes to execute - it keeps throwing an System.InvalidOperationException with message that says It is unable to run SendKeys in application, because it does not handle communicates/messages of Windows and I should change the application to somehow handle this or use SendKeys.SendWait, so i did it and change {SPACE} approach to {ENTER}:

 

System.Windows.Forms.SendKeys.SendWait("{ENTER}")

 

After script execution is over, the Create New Study window is still open with title "Analysis 2", but I see that Static Analysis is created (with ID = 1) in Model Browser on the left side of the Inventor window. So it doesn't works perfectly and the most important - I don't know what's next.

 

I've deleted:

 

Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()

 

It works the same. Magic.

 

I still don't know how to change default Static Analysis to Modal Analysis, moving forword with Modal Analysis - I don't know how to change default values in inputs.

 

Maybe more important - I don't know from where strings FeaCreateSimCmd and AppContextual_OKCmd comes from - I found nothing in inventor documentation. The source of that I found here: https://adndevblog.typepad.com/manufacturing/2013/08/run-stress-simulation-by-code.html 

 

If you have any of these answers or any suggestion - I would very appreciate you to respond, even if you see this thread long time after publishing - maybe it will help someone else in the future.

 

At the end, I'd like to sum up what I have now and what it results with.

The code:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager
If UIManager.ActiveEnvironment.InternalName <> "FEA Environment Internal Name" Then
    Dim environmentMgr As EnvironmentManager = oDoc.EnvironmentManager
    Dim dsEnv As Environment = UIManager.Environments.Item("FEA Environment Internal Name")
    Call environmentMgr.SetCurrentEnvironment(dsEnv)
End If
Dim oCol As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("FeaCreateSimCmd")
oCol.Execute()
System.Windows.Forms.SendKeys.SendWait("{ENTER}")

 

 

And the result:

InventorGenerator.png

 

293 Views
0 Replies
Replies (0)