Thank you A.Acheson for your comment,
See attached video and code.
Inventor itself bypasses the 'Import' dialog window.
You would say it shouldn't be that complicated to get the path of the file, but I don't know how.
' Expand_Browser_On_Save_Or_Open_Document
'MessageBox.Show("Wait...")
'Sub main
Logger.Info(vbNewLine & vbNewLine & vbNewLine)
Logger.Info("ThisApplication.ToString: " & ThisApplication.ToString)
Dim ActiveDoc As Inventor.Document = ThisApplication.ActiveDocument
Logger.Info("ActiveDoc: " & ActiveDoc.FullDocumentName )
Dim ActiveEditDoc As Inventor.Document = ThisApplication.ActiveEditDocument
Logger.Info("ActiveEditDoc: " & ActiveEditDoc.FullDocumentName )
Dim oDoc As Inventor.Document = ThisDoc.Document
Logger.Info("ThisDoc.Document: " & oDoc.FullDocumentName)
Logger.Info("")
If Not oDoc.FullDocumentName = "" Then GoTo EndRule
'' ONLY for Project Specific Files or Template Files to avoid annoying behavior for other files
'If Not oDoc.FullDocumentName Like "*Projecten*" Or Not oDoc.FullDocumentName Like "*Templates*" Then
' Exit Sub
'Else
' ' Do Nothing
'End If
'Dim xDoc As Inventor.Document = ThisApplication.ActiveDocument
'Dim strTime As String
'strTime = DateTime.Now.ToString(("HH:mm:ss"))
'Logger.Info(vbNewLine & vbNewLine & vbNewLine)
'Logger.Info(strTime & " InventorPLUS: Collapse Browser: oDoc.FullDocumentName = ThisApplication.ActiveEditDocument: " & oDoc.FullDocumentName)
'Logger.Info(strTime & " InventorPLUS: Collapse Browser: ThisDoc.Document.FullDocumentName : " & ThisDoc.Document.FullDocumentName)
'Logger.Info(strTime & " InventorPLUS: Collapse Browser: xDoc.FullDocumentName = ThisApplication.ActiveDocument : " & xDoc.FullDocumentName)
'Logger.Info(strTime & " InventorPLUS: Collapse Browser: ThisDoc.Document.FullDocumentName : " & oDoc.AllReferencedDocuments.Count)
'Logger.Info("")
' Check file type
If oDoc.DocumentType = kPartDocumentObject Then
'If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
' BUG in IV2022 for next line, therefore alternative approach by Krieg:
'ThisApplication.CommandManager.ControlDefinitions("AppBrowserExpandAllCmd").Execute
InventorVb.RunMacro("ApplicationProject", "Collapse_Expand_nav_bug", "CollapseAll")
' Use DoEvents to force Inventor to wait till the code is finished...
Call ThisApplication.UserInterfaceManager.DoEvents
'RunMacro()
' Fake Task, after CollapseAll Inventor did Collapse the Browser tree but did not Expand it, it looks like it takes to long for some reason.the Browser Tree
'For i = 1 To 2
'Logger.Info(i & " Fake Task to Let Inventor do his thing...")
'Next
'System.Threading.Thread.Sleep(3000)
'MessageBox.Show("Wait...")
'GoTo EndRule
' Set Home view / Zoom All
Call ThisApplication.ActiveView.GoHome
'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
' Check for Normal Part or Sheet Metal Part
If oDoc.DocumentSubType.DocumentSubTypeID = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then ' Normal Part (No Sheetmetal)
Dim oNode1 As BrowserNode
For Each oNode1 In oTopNode.BrowserNodes
Try : If oNode1.FullPath Like "*Model States*" Then oNode1.Expanded = True
Catch: End Try
'If oNode1.FullPath Like "*Folded Model*" Then oNode1.Expanded = True
Try :If oNode1.FullPath Like "*Solid Bodies*" Then oNode1.Expanded = True
Catch: End Try
Try :If oNode1.FullPath Like "*View*" Then oNode1.Expanded = True
Catch: End Try
Try :If oNode1.FullPath Like "*Origin*" Then oNode1.Expanded = True
Catch: End Try
'Dim oNode2 As BrowserNode
'For Each oNode2 In oNode1.BrowserNodes
' If oNode2.FullPath Like "*Model States*" Then oNode2.Expanded = True
' If oNode2.FullPath Like "*Folded Model*" Then oNode2.Expanded = True
' If oNode2.FullPath Like "*Solid Bodies*" Then oNode2.Expanded = True
' If oNode2.FullPath Like "*View*" Then oNode2.Expanded = True
' If oNode2.FullPath Like "*Origin*" Then oNode2.Expanded = True
'Dim oNode3 As BrowserNode
'For Each oNode3 In oNode2.BrowserNodes
' If oNode3.FullPath Like "*Model States*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Folded Model*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Solid Bodies*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*View*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Origin*" Then oNode3.Expanded = True
'Next
'Next
Next
End If
' Check for Normal Part or Sheet Metal Part
If oDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then ' Sheetmetal Part
Dim oNode1 As BrowserNode
For Each oNode1 In oTopNode.BrowserNodes
Try : If oNode1.FullPath Like "*Model States*" Then oNode1.Expanded = True
Catch:MessageBox.Show("Error when expand Model States") : End Try
Try : If oNode1.FullPath Like "*Folded Model*" Then oNode1.Expanded = True
Catch:MessageBox.Show("Error when expand Folded Model") : End Try
'Try :If oNode1.FullPath Like "Solid Bodies*" Then oNode1.Expanded = True
' Catch: End Try
'Try :If oNode1.FullPath Like "*View*" Then oNode1.Expanded = True
' Catch: End Try
'Try :If oNode1.FullPath Like "*Origin*" Then oNode1.Expanded = True
' Catch: End Try
Dim oNode2 As BrowserNode
For Each oNode2 In oNode1.BrowserNodes
'Try :If oNode2.FullPath Like "*Model States*" Then oNode2.Expanded = True
' Catch: End Try
'Try :If oNode2.FullPath Like "*Folded Model*" Then oNode2.Expanded = True
' Catch: End Try
Try :If oNode2.FullPath Like "*Solid Bodies*" Then oNode2.Expanded = True
Catch : 'MessageBox.Show("Error when expand Solid Bodies")
End Try
Try :If oNode2.FullPath Like "*Folded Model:View*" Then oNode2.Expanded = True
Catch : 'MessageBox.Show("Error when expand Folded Model:View")
End Try
Try :If oNode2.FullPath Like "*Origin*" Then oNode2.Expanded = True
Catch : 'MessageBox.Show("Error when expand Origin")
End Try
'Dim oNode3 As BrowserNode
'For Each oNode3 In oNode2.BrowserNodes
' If oNode3.FullPath Like "*Model States*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Folded Model*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Solid Bodies*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*View*" Then oNode3.Expanded = True
' If oNode3.FullPath Like "*Origin*" Then oNode3.Expanded = True
'Next
Next
Next
End If
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
'ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject And oDoc.FullDocumentName = ThisDoc.Document.FullDocumentName Then
' BUG in IV2022:
'ThisApplication.CommandManager.ControlDefinitions("AppBrowserExpandAllCmd").Execute
InventorVb.RunMacro("ApplicationProject", "Collapse_Expand_nav_bug", "CollapseAll")
' Use DoEvents to force Inventor to wait till the code is finished...
Call ThisApplication.UserInterfaceManager.DoEvents
'RunMacro()
' Fake Task, after CollapseAll Inventor did Collapse the Browser tree but did not Expand it, it looks like it takes to long for some reason.the Browser Tree
'For i = 1 To 20
' Logger.Info(i & " Fake Task to Let Inventor do his thing...")
'System.Threading.Thread.Sleep(1000)
'Next
'MessageBox.Show("Wait...")
' Set Home view / Zoom All
Call ThisApplication.ActiveView.GoHome
'TryOut()
'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
' All nodes where collapsed, expand some folders
Dim oNode1 As BrowserNode
For Each oNode1 In oTopNode.BrowserNodes
If oNode1.FullPath Like "*:Model States*" Or _
oNode1.FullPath Like "*:Representations*" Or _
oNode1.FullPath Like "*:View*" Or _
oNode1.FullPath Like "*Position*" Or _
oNode1.FullPath Like "*:Origin*" Or _
oNode1.FullPath Like "*xxWelds*" Or _
oNode1.FullPath Like "*xxBeads*" Or _
oNode1.FullPath Like "*Sheet" Then
' If the node is visible and expanded, collapse it.
If oNode1.Visible = True And oNode1.Expanded = False Then
oNode1.Expanded = True
End If
End If
Dim oNode2 As BrowserNode
For Each oNode2 In oNode1.BrowserNodes
If oNode2.FullPath Like "*Position*" Or _
oNode2.FullPath Like "*View*" Or _
oNode2.FullPath Like "*xxWelds*" Or _
oNode2.FullPath Like "*xxBeads*" Or _
oNode2.FullPath Like "*Sheet" Then
' If the node is visible and expanded, collapse it.
If oNode2.Visible = True And oNode2.Expanded = False Then
oNode2.Expanded = True
End If
End If
Next
Next
End If
EndRule:
'End Sub
'Sub RunMacro
' ' BUG in IV2022:
' 'ThisApplication.CommandManager.ControlDefinitions("AppBrowserExpandAllCmd").Execute
' InventorVb.RunMacro("ApplicationProject", "Collapse_Expand_nav_bug", "CollapseAll")
'End Sub
'Function TryOut()As Integer
'Dim oDoc As Inventor.Document = ThisApplication.ActiveEditDocument
''Set a reference to the top node of the active browser
' Dim oTopNode As BrowserNode
' oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
' ' All nodes where collapsed, expand some folders
' Dim oNode1 As BrowserNode
' For Each oNode1 In oTopNode.BrowserNodes
' If oNode1.FullPath Like "*:Model States*" Or _
' oNode1.FullPath Like "*:Representations*" Or _
' oNode1.FullPath Like "*:View*" Or _
' oNode1.FullPath Like "*Position*" Or _
' oNode1.FullPath Like "*:Origin*" Or _
' oNode1.FullPath Like "*xxWelds*" Or _
' oNode1.FullPath Like "*xxBeads*" Or _
' oNode1.FullPath Like "*Sheet" Then
' ' If the node is visible and expanded, collapse it.
' If oNode1.Visible = True And oNode1.Expanded = False Then
' oNode1.Expanded = True
' End If
' End If
' Dim oNode2 As BrowserNode
' For Each oNode2 In oNode1.BrowserNodes
' If oNode2.FullPath Like "*Position*" Or _
' oNode2.FullPath Like "*View*" Or _
' oNode2.FullPath Like "*xxWelds*" Or _
' oNode2.FullPath Like "*xxBeads*" Or _
' oNode2.FullPath Like "*Sheet" Then
' ' If the node is visible and expanded, collapse it.
' If oNode2.Visible = True And oNode2.Expanded = False Then
' oNode2.Expanded = True
' End If
' End If
' Next
' Next
'End Function