Hello Krieg,
I knock again for help.
I manage to make the feature dimensions visible, but I can't get them invisible.
I would also like to expand the browser nodes of the component being edited and see them at the top of the browser. In that case you get an immediate overview of how the component is built without having to click everything open first. Is it possible to make the browser scroll to a certain position through code?
Perhaps unnecessarily:
Throughout this story, I'm using two separate macros, 'Expand Browser' and 'Collapse Browser' which I have under the + and - keys of my numeric keyboard part. Both macros btw use your solution to be able to expand and collapse the browser because of the BUG. 'Collapse Browser' collapses the browser for both a part and an assembly and then opens up several browser nodes such as Model States, Representations-View and -Position and finally Origin. 'Expand Browser' expands everything for an assembly and collapses what I don't want to see, such as Relationships. For a part, among other things, the sketches are unfolded and made visible and now also the dimensions of the features. My wish now is that this also works when the document is edited 'in place'.
Please find both code attached.
' Expand_Browser
' Write to textfile
'Dim strDateAndTime = DateTime.Now.ToString(("yyyy-MM-dd HHmmss"))
'Dim LogFileName As String = "C:\temp\iLogic_Log_" & strDateAndTime & ".txt"
'oWrite = System.IO.File.CreateText(LogFileName)
''oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
' Calculate elapsed time
Dim oWatch As New Stopwatch : oWatch.Start()
InventorVb.RunMacro("ApplicationProject", "Collapse_Expand_nav_bug","ExpandAll")
'ThisApplication.CommandManager.ControlDefinitions("AppBrowserCollapseChildrenCmd").Execute
' BUG in IV2022:
'ThisApplication.CommandManager.ControlDefinitions("AppBrowserExpandAllCmd").Execute
'oDoc = ThisDoc.ModelDocument
Dim oDoc As Inventor.Document = ThisApplication.ActiveEditDocument
' Check file type
'If oDoc.DocumentType = kPartDocumentObject Then
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
'MessageBox.Show("Wait...")
'----------------------------------------------------------------------------------------------------
'Undo Wrapper
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Do your thing")
'----------------------------------------------------------------------------------------------------
' Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode
For Each oNode In oTopNode.BrowserNodes
''oWrite.WriteLine("1st :" & oNode.FullPath)
If oNode.FullPath Like "*Solid*" Then
' If the node is visible and expanded, collapse it.
'If oNode.Visible = True And oNode.Expanded = True Then
Try : oNode.Expanded = False
Catch: End Try
'End If
End If
Dim oNode2 As BrowserNode
For Each oNode2 In oNode.BrowserNodes
''oWrite.WriteLine(" 2nd :" & oNode2.FullPath)
If oNode2.FullPath Like "*Solid*" Then
' If the node is visible and expanded, collapse it.
'If oNode2.Visible = True And oNode2.Expanded = True Then
Try : oNode2.Expanded = False
Catch: End Try
'End If
End If
Dim oNode3 As BrowserNode
For Each oNode3 In oNode2.BrowserNodes
''oWrite.WriteLine(" 3th :" & oNode3.FullPath)
If oNode3.FullPath Like "*Folded Model:Solid*" Then
' If the node Is visible And expanded, collapse it.
If oNode3.Visible = True And oNode3.Expanded = True Then
Try : oNode3.Expanded = False
Catch: End Try
End If
End If
' Dim oNode4 As BrowserNode
' For Each oNode4 In oNode3.BrowserNodes
' oWrite.WriteLine(" 4th:" & oNode4.FullPath)
' If oNode4.FullPath Like "*Solid Bodies*" Then
' ' If the node is visible and expanded, collapse it.
' 'If oNode4.Visible = True And oNode4.Expanded = True Then
' Try: oNode4.Expanded = False
'Catch: End Try
' 'End If
' End If
' Next
Next
Next
Next
' Make Sketches visible
For Each oSketch In oDoc.ComponentDefinition.Sketches
oSketch.Visible = True
Next
For Each oSketch In oDoc.ComponentDefinition.Sketches3d
oSketch.Visible = True
Next
InventorVb.DocumentUpdate()
'iLogicVb.UpdateWhenDone = True
'----------------------------------------------------------------------------------------------------
' Show also the feature dimensions like fillets, flanges etc.
Dim oFeature As PartFeature
For Each oFeature In oDoc.ComponentDefinition.Features
oDoc.SelectSet.Select(oFeature)
Next
ThisApplication.CommandManager.ControlDefinitions.Item("PartShowDimensionsCtxCmd").Execute
' Deselect Features to hide the dotted line round the model
For Each oFeature In oDoc.ComponentDefinition.Features
oDoc.SelectSet.Remove(oFeature)
Next
'----------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------
'Undo Wrapper
trans.End()
'----------------------------------------------------------------------------------------------------
End If
'check file type
'If oDoc.DocumentType = kAssemblyDocumentObject Then
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'MessageBox.Show("Assembly Document Section")
'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode
For Each oNode In oTopNode.BrowserNodes
''oWrite.WriteLine("1st :" & oNode.FullPath)
If oNode.FullPath Like "*:Relationships*" Then
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = True Then
oNode.Expanded = False
End If
End If
Dim oNode2 As BrowserNode
For Each oNode2 In oNode.BrowserNodes
''oWrite.WriteLine(" 2nd :" & oNode2.FullPath)
If oNode2.FullPath Like "*:Relationships*" Then
' If the node is visible and expanded, collapse it.
If oNode2.Visible = True And oNode2.Expanded = True Then
oNode2.Expanded = False
End If
End If
Next
Next
' For Each oSketch In oDoc.ComponentDefinition.Sketches
' oSketch.Visible = True
' Next
InventorVb.DocumentUpdate()
'----------------------------------------------------------------------------------------------------
' Show also the feature dimensions like fillets, flanges etc.
Try
oAssDoc = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence = oAssDoc.ComponentDefinition.ActiveOccurrence
Dim oFeatureProxy As Object
For Each oFeature In oOcc.Definition.Features
oOcc.CreateGeometryProxy(oFeature, oFeatureProxy)
oAssDoc.SelectSet.Select(oFeatureProxy)
Next
ThisApplication.CommandManager.ControlDefinitions.Item("PartShowDimensionsCtxCmd").Execute
' ' Deselect Features to hide the dotted line round the model
' For Each oFeature In oOcc.Definition.Features
' oOcc.CreateGeometryProxy(oFeature, oFeatureProxy)
' oAssDoc.SelectSet.Remove(oFeatureProxy)
' Next
Catch
End Try
'----------------------------------------------------------------------------------------------------
End If
' Help
'Collapse All - AppBrowserCollapseAllCmd
'Collapse Children - AppBrowserCollapseChildrenCmd
'Expand All - AppBrowserExpandAllCmd
' - AppBrowserExpandAllFoldersCmd
'Expand Children - AppBrowserExpandChildrenCmd
' - AppBrowserExpandFolderCmd
''Calculate elapsed time.
'oWatch.Stop()
'oWrite.WriteLine(vbNewLine & "Done!" & vbNewLine & ("Elapsed Time: " & oWatch.ElapsedMilliseconds.ToString & " Milliseconds"))
''MsgBox (vbNewLine & "Done!" & vbNewLine & ("Elapsed Time: " & oWatch.ElapsedMilliseconds.ToString & " Milliseconds"))
'oWrite.Close()
''Dim p As System.Diagnostics.Process = Process.Start(LogFileName)
''ThisDoc.Launch(LogFileName)
''ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")
' Collapse_Browser
Dim oDoc As Inventor.Document = ThisApplication.ActiveEditDocument
' BUG in IV2022:
'ThisApplication.CommandManager.ControlDefinitions("AppBrowserExpandAllCmd").Execute
InventorVb.RunMacro("ApplicationProject", "Collapse_Expand_nav_bug","CollapseAll")
' Check file type
If oDoc.DocumentType = kPartDocumentObject Then
'If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Logger.Info(oDoc.FullDocumentName)
'Try
'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
'Catch
'End Try
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Turn on Sketches
For Each oSketch In oDoc.ComponentDefinition.Sketches
oSketch.Visible = False
Next
For Each oSketch In oDoc.ComponentDefinition.Sketches3D
oSketch.Visible = False
Next
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Rebuild
Try
iLogicVb.UpdateWhenDone = True
Catch
MessageBox.Show("File Is Not Checked Out?")
End Try
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
'' Deselect Features to hide the dotted line round the model
'For Each oFeature In oDoc.ComponentDefinition.Features
' oDoc.SelectSet.Remove(oFeature)
'Next
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
'ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Do your thing...")
'----------------------------------------------------------------------------------------------------
'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
' Eerder hebben we alles INgeklapt, nu willen we een aantal folders UITgeklapt hebben
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
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
trans.End()
'----------------------------------------------------------------------------------------------------
'MessageBox.Show("Wait...")
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' ' Deselect Features to hide the dotted line round the model
' oAssDoc = ThisApplication.ActiveDocument
' Dim oOcc As ComponentOccurrence = oAssDoc.ComponentDefinition.ActiveOccurrence
' Dim oFeatureProxy As Object
' For Each oFeature In oOcc.Definition.Features
' oOcc.CreateGeometryProxy(oFeature, oFeatureProxy)
' oAssDoc.SelectSet.Remove(oFeatureProxy)
' Next
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
Try
InventorVb.DocumentUpdate()
Catch
MessageBox.Show("File Is Not Checked Out?")
End Try
'----------------------------------------------------------------------------------------------------
End If
'MessageBox.Show("Done")