Automatically change stress analysis settings

Automatically change stress analysis settings

Futek
Explorer Explorer
647 Views
2 Replies
Message 1 of 3

Automatically change stress analysis settings

Futek
Explorer
Explorer

Hello,

 

I would like to turn the setting in Stress Analysis to create OLE Link off by running a rule when a part file opens. For future files, I have already edited the template so that it is automatically checked off but I need to do this for files that currently exist. I looked through the iLogic API reference, but I couldn't find anything on the stress analysis module (or maybe I'm blind). Does anyone know how to reference this in a rule?

 

Futek_0-1597875319806.png

Thank you

0 Likes
648 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Ready to be blown away?

This is the long way to automate do it, but it gets the job done whey I tried it.

It basically simulates the manual actions of activating the FEA Analysis Environment, then creating a Study (because there needs to be one, and I'm not sure how to check to see if one already exists...yet), then opens the Settings dialog, then navigates through that dialog using simulated keyboard key presses, then either turns that specific setting on or off (depending on which line of code yo choose to use at the end), then uses Enter key to accept the changes and close the dialog.

This is not the preferred or recommended method, but may help you get through a lot of stuff in a hurry, if it works for you right now.

Here's the code:

 

'AddReference "Microsoft.VisualBasic.Devices"
Imports Microsoft.VisualBasic.Devices

Dim oRib As String
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oRib = "Part"
ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oRib = "Assembly"
Else
	MsgBox("This rule only works from a Part or Assembly document. Exiting.")
	Return
End If

Dim oUIMgr As UserInterfaceManager = ThisApplication.UserInterfaceManager

Dim oRibbon As Ribbon = oUIMgr.Ribbons.Item(oRib)
Dim oTab As RibbonTab = oRibbon.RibbonTabs.Item("id_TabEnvironments")
Dim oPanel As RibbonPanel = oTab.RibbonPanels.Item("id_Panel_EnvironmentsBegin")
Dim oCC As CommandControl = oPanel.CommandControls.Item("FEA Environment Internal Name")
'This activates the Stress Analysis environment
oCC.ControlDefinition.Execute

Dim oFEA_Env As Inventor.Environment = oUIMgr.Environments.Item("FEA Environment Internal Name")
Dim oFEA_Ribbon As Ribbon = oFEA_Env.Ribbon
Dim oFEA_Tab As RibbonTab = oFEA_Ribbon.RibbonTabs.Item("id_TabAFEA")
Dim oFEA_ManagePanel As RibbonPanel = oFEA_Tab.RibbonPanels.Item("id_PanelA_AFEAManage")
Dim oFEA_SettingsPanel As RibbonPanel = oFEA_Tab.RibbonPanels.Item("id_PanelA_AFEASettings")
Dim oFEA_CreateStudy As CommandControl = oFEA_ManagePanel.CommandControls.Item("FeaCreateSimCmd")
'Creates a new Study
oFEA_CreateStudy.ControlDefinition.Execute
Dim oFEA_Settings As CommandControl = oFEA_SettingsPanel.CommandControls.Item("FeaSimulationSettingsCmd")
'Opens the Settings dialog
oFEA_Settings.ControlDefinition.Execute

'The following two lines of code use keyboard keys to navigate through the Settings dialog, turn the option on or off, then choose OK to keep the changes and close the dialog.

'To check the box (turn the option on) use the following line.
System.Windows.Forms.SendKeys.SendWait("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{+}{ENTER}")

'To un-check the box (turn the option Off) use the following line.
System.Windows.Forms.SendKeys.SendWait("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{-}{ENTER}")

It does not return you to the regular modeling environment either, yet.  But probably could with some more work.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

NDU-JE
Explorer
Explorer

Hi, 

I was able to expand a bit on your code. I added the functionality to check if there are any studies in the browserpanel, so they are only created if necessary. I also tried deleting them again with browsernode.delete, but this seems to make Inventor crash when exiting the analysis again. So I select the node with DoSelect, and then send a Delete keypress instead.
I also added functionality to save and exit when done.

 

Imports Microsoft.VisualBasic.Devices

Dim oRib As String
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oRib = "Part"
ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oRib = "Assembly"
Else
	MsgBox("This rule only works from a Part or Assembly document. Exiting.")
	Return
End If

Dim oUIMgr As UserInterfaceManager = ThisApplication.UserInterfaceManager

Dim oRibbon As Ribbon = oUIMgr.Ribbons.Item(oRib)
Dim oTab As RibbonTab = oRibbon.RibbonTabs.Item("id_TabEnvironments")
Dim oPanel As RibbonPanel = oTab.RibbonPanels.Item("id_Panel_EnvironmentsBegin")
Dim oCC As CommandControl = oPanel.CommandControls.Item("FEA Environment Internal Name")
'This activates the Stress Analysis environment
oCC.ControlDefinition.Execute

Dim oFEA_Env As Inventor.Environment = oUIMgr.Environments.Item("FEA Environment Internal Name")
Dim oFEA_Ribbon As Ribbon = oFEA_Env.Ribbon
Dim oFEA_Tab As RibbonTab = oFEA_Ribbon.RibbonTabs.Item("id_TabAFEA")
Dim oFEA_ManagePanel As RibbonPanel = oFEA_Tab.RibbonPanels.Item("id_PanelA_AFEAManage")
Dim oFEA_SettingsPanel As RibbonPanel = oFEA_Tab.RibbonPanels.Item("id_PanelA_AFEASettings")
Dim oFEA_CreateStudy As CommandControl = oFEA_ManagePanel.CommandControls.Item("FeaCreateSimCmd")

'Define tab, panel and commandcontrol for exiting
Dim oFEAExit_Tab As RibbonTab = oFEA_Ribbon.RibbonTabs.Item("id_TabStressAnalysis_Exit")
Dim oFEA_ExitPanel As RibbonPanel = oFEAExit_Tab.RibbonPanels.Item("id_PanelP_StressAnalysisExit")
Dim oReturnCC As CommandControl = oFEA_ExitPanel.CommandControls.Item("AppReturnBaseEnv")

'Checking if there are any existing studies
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oBP As BrowserPane = oDoc.BrowserPanes.Item("{B3D04494-EDD2-4FDC-9EC2-30BAF8D6B77B}")
Dim oFEA_Settings As CommandControl = oFEA_SettingsPanel.CommandControls.Item("FeaSimulationSettingsCmd")

Dim DeleteStudy As Boolean = False

'Count nodes in Study browser. Each node is an analysis. 0 nodes means no analysis exists.
If oBP.TopNode.BrowserNodes.Count = 0 Then
	oFEA_CreateStudy.ControlDefinition.Execute
	DeleteStudy = True ' delete study again when done
End If

'Opens the Settings dialog
oFEA_Settings.ControlDefinition.Execute
'The following line of code use keyboard keys to navigate through the Settings dialog, turn the option off, then choose OK to keep the changes and close the dialog.
System.Windows.Forms.SendKeys.SendWait("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{-}{ENTER}")
'Doing it again seems to fix issues of where it sometimes doesn't disable the setting...
oFEA_Settings.ControlDefinition.Execute
System.Windows.Forms.SendKeys.SendWait("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{-}{ENTER}{ESC}")

'Clean up
If oBP.TopNode.BrowserNodes.Count = 1 And DeleteStudy Then
	
	'Uncommenting below will make Inventor crash when returning to normal environment
	'oBP.TopNode.BrowserNodes.Item(1).Delete
	
	'Delete by selecting node and sending a key press of delete
	oBP.TopNode.BrowserNodes.Item(1).DoSelect
	System.Windows.Forms.SendKeys.SendWait("{DELETE}")
	
End If

'Save the document
oDoc.Save()

'Return to normal environment
oReturnCC.ControlDefinition.Execute
0 Likes