<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Stress Analysis via Visual Basic Application in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/stress-analysis-via-visual-basic-application/m-p/11794418#M149706</link>
    <description>&lt;P&gt;I'm working on some project that requires me to prepare automated Stress Analysis to run on previously generated model.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Model generation is already done.&lt;/P&gt;&lt;P&gt;Now I need to execute &lt;STRONG&gt;stress analysis&lt;/STRONG&gt;, which is normally fired from &lt;STRONG&gt;Envirments/Stress Analysis&lt;/STRONG&gt; and then &lt;STRONG&gt;Analysis/Create Study&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Firstly I need &lt;STRONG&gt;Static Analysis&lt;/STRONG&gt; and then &lt;STRONG&gt;Modal Analysis&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I'd like to know how to prepare &lt;STRONG&gt;Material&lt;/STRONG&gt;, &lt;STRONG&gt;Contraints&lt;/STRONG&gt;, &lt;STRONG&gt;Loads&lt;/STRONG&gt; and &lt;STRONG&gt;Contacts&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now I was managed to open &lt;STRONG&gt;Create Study&lt;/STRONG&gt; window and that is it &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@F462EEC827775DA92CB03B7FC147D389/emoticons/1f61e.png" alt=":disappointed_face:" title=":disappointed_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisApplication.ActiveDocument

'if stress simulation is activated
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager

If UIManager.ActiveEnvironment.InternalName &amp;lt;&amp;gt; "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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;^ it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point in couple of threads on forum I've seen suggestion to add this Control Definitions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;System.Windows.Forms.SendKeys.Send(" ")
'and
My.Computer.Keyboard.SendKeys(" ")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of them failes to execute - it keeps throwing an&amp;nbsp;&lt;STRONG&gt;System.InvalidOperationException&amp;nbsp;&lt;/STRONG&gt;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}:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;System.Windows.Forms.SendKeys.SendWait("{ENTER}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After script execution is over, the &lt;STRONG&gt;Create New Study&lt;/STRONG&gt; window is still open with title "Analysis 2", but I see that &lt;STRONG&gt;Static Analysis&lt;/STRONG&gt; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've deleted:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works the same. Magic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe more important - I don't know from where strings&amp;nbsp;&lt;STRONG&gt;FeaCreateSimCmd&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;AppContextual_OKCmd&lt;/STRONG&gt; comes from - I found nothing in inventor documentation. The source of that I found here:&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/manufacturing/2013/08/run-stress-simulation-by-code.html" target="_blank" rel="noopener"&gt;https://adndevblog.typepad.com/manufacturing/2013/08/run-stress-simulation-by-code.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have any of these answers or any suggestion - I would very appreciate you to &lt;STRONG&gt;respond&lt;/STRONG&gt;, even if you see this thread long time after publishing - &lt;STRONG&gt;maybe it will help someone else in the future&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end, I'd like to sum up what I have now and what it results with.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The code&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisApplication.ActiveDocument
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager
If UIManager.ActiveEnvironment.InternalName &amp;lt;&amp;gt; "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}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And &lt;STRONG&gt;the result&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="InventorGenerator.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1183890iDD56DD06BBB7C0AF/image-size/large?v=v2&amp;amp;px=999" role="button" title="InventorGenerator.png" alt="InventorGenerator.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2023 20:46:21 GMT</pubDate>
    <dc:creator>dominikkedzia</dc:creator>
    <dc:date>2023-03-02T20:46:21Z</dc:date>
    <item>
      <title>Stress Analysis via Visual Basic Application</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/stress-analysis-via-visual-basic-application/m-p/11794418#M149706</link>
      <description>&lt;P&gt;I'm working on some project that requires me to prepare automated Stress Analysis to run on previously generated model.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Model generation is already done.&lt;/P&gt;&lt;P&gt;Now I need to execute &lt;STRONG&gt;stress analysis&lt;/STRONG&gt;, which is normally fired from &lt;STRONG&gt;Envirments/Stress Analysis&lt;/STRONG&gt; and then &lt;STRONG&gt;Analysis/Create Study&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Firstly I need &lt;STRONG&gt;Static Analysis&lt;/STRONG&gt; and then &lt;STRONG&gt;Modal Analysis&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I'd like to know how to prepare &lt;STRONG&gt;Material&lt;/STRONG&gt;, &lt;STRONG&gt;Contraints&lt;/STRONG&gt;, &lt;STRONG&gt;Loads&lt;/STRONG&gt; and &lt;STRONG&gt;Contacts&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now I was managed to open &lt;STRONG&gt;Create Study&lt;/STRONG&gt; window and that is it &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@F462EEC827775DA92CB03B7FC147D389/emoticons/1f61e.png" alt=":disappointed_face:" title=":disappointed_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisApplication.ActiveDocument

'if stress simulation is activated
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager

If UIManager.ActiveEnvironment.InternalName &amp;lt;&amp;gt; "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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;^ it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point in couple of threads on forum I've seen suggestion to add this Control Definitions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;System.Windows.Forms.SendKeys.Send(" ")
'and
My.Computer.Keyboard.SendKeys(" ")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of them failes to execute - it keeps throwing an&amp;nbsp;&lt;STRONG&gt;System.InvalidOperationException&amp;nbsp;&lt;/STRONG&gt;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}:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;System.Windows.Forms.SendKeys.SendWait("{ENTER}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After script execution is over, the &lt;STRONG&gt;Create New Study&lt;/STRONG&gt; window is still open with title "Analysis 2", but I see that &lt;STRONG&gt;Static Analysis&lt;/STRONG&gt; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've deleted:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oCol2 As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppContextual_OKCmd")

oCol2.Execute()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works the same. Magic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe more important - I don't know from where strings&amp;nbsp;&lt;STRONG&gt;FeaCreateSimCmd&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;AppContextual_OKCmd&lt;/STRONG&gt; comes from - I found nothing in inventor documentation. The source of that I found here:&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/manufacturing/2013/08/run-stress-simulation-by-code.html" target="_blank" rel="noopener"&gt;https://adndevblog.typepad.com/manufacturing/2013/08/run-stress-simulation-by-code.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have any of these answers or any suggestion - I would very appreciate you to &lt;STRONG&gt;respond&lt;/STRONG&gt;, even if you see this thread long time after publishing - &lt;STRONG&gt;maybe it will help someone else in the future&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end, I'd like to sum up what I have now and what it results with.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The code&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisApplication.ActiveDocument
Dim UIManager As UserInterfaceManager = ThisApplication.UserInterfaceManager
If UIManager.ActiveEnvironment.InternalName &amp;lt;&amp;gt; "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}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And &lt;STRONG&gt;the result&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="InventorGenerator.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1183890iDD56DD06BBB7C0AF/image-size/large?v=v2&amp;amp;px=999" role="button" title="InventorGenerator.png" alt="InventorGenerator.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 20:46:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/stress-analysis-via-visual-basic-application/m-p/11794418#M149706</guid>
      <dc:creator>dominikkedzia</dc:creator>
      <dc:date>2023-03-02T20:46:21Z</dc:date>
    </item>
  </channel>
</rss>

