@kresh.bell
One more attempt🤣
Sub Main()
' Check that the active document is a drawing
If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
MessageBox.Show("This code must be executed in a drawing environment.", "Error")
Exit Sub
End If
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Iterate through all sheets in the drawing
For Each oSheet As Sheet In oDrawDoc.Sheets
' Iterate through all views on the sheet
For Each oView As DrawingView In oSheet.DrawingViews
' Get the model document associated with the view
Dim oRefDoc As Document
oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
' Check if referenced document is valid
If oRefDoc Is Nothing Then Continue For
' Check document type and call processing
If oRefDoc.DocumentType = kPartDocumentObject Then
ProcessPartInView(oView, oRefDoc)
ElseIf oRefDoc.DocumentType = kAssemblyDocumentObject Then
ProcessAssemblyInView(oView, oRefDoc, New Collection)
End If
Next
Next
' Update the drawing
oDrawDoc.Update
End Sub
Sub ProcessPartInView(oView As DrawingView, oDoc As PartDocument)
' Check if inputs are valid
If oView Is Nothing Or oDoc Is Nothing Then Exit Sub
' Get the component definition of the part
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Check if component definition is valid
If oCompDef Is Nothing Then Exit Sub
' Iterate through all solid bodies in the part
For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
' Check if body is valid and its name starts with "-"
If oBody IsNot Nothing AndAlso Left(oBody.Name, 1) = "-" Then
Try
' Turn off visibility of the body in the drawing view
oView.SetVisibility(oBody, False)
Catch ex As Exception
' Log error silently or handle as needed
End Try
End If
Next
End Sub
Sub ProcessAssemblyInView(oView As DrawingView, oDoc As AssemblyDocument, oParentOccurrences As Collection)
' Check if inputs are valid
If oView Is Nothing Or oDoc Is Nothing Then Exit Sub
' Get the component definition of the assembly
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Check if component definition is valid
If oCompDef Is Nothing Then Exit Sub
' Iterate through all component occurrences in the assembly
For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
' Check if occurrence is valid
If oOcc Is Nothing Then Continue For
' Get the document associated with the occurrence
Dim oSubDoc As Document
Try
oSubDoc = oOcc.Definition.Document
Catch ex As Exception
Continue For ' Skip if document cannot be accessed
End Try
' Check if sub-document is valid
If oSubDoc Is Nothing Then Continue For
' Clone the parent occurrences collection and add the current occurrence
Dim oNewParentOccurrences As New Collection
For Each item In oParentOccurrences
oNewParentOccurrences.Add (item)
Next
oNewParentOccurrences.Add (oOcc)
' Process nested parts
If oSubDoc.DocumentType = kPartDocumentObject Then
ProcessNestedPartInView(oView, oSubDoc, oNewParentOccurrences)
ElseIf oSubDoc.DocumentType = kAssemblyDocumentObject Then
' Recursively process nested assemblies
ProcessAssemblyInView(oView, oSubDoc, oNewParentOccurrences)
End If
Next
End Sub
Sub ProcessNestedPartInView(oView As DrawingView, oDoc As PartDocument, oParentOccurrences As Collection)
' Check if inputs are valid
If oView Is Nothing Or oDoc Is Nothing Or oParentOccurrences Is Nothing Then Exit Sub
' Get the component definition of the part
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Check if component definition is valid
If oCompDef Is Nothing Then Exit Sub
' Iterate through all solid bodies in the part
For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
' Check if body is valid and its name starts with "-"
If oBody IsNot Nothing AndAlso Left(oBody.Name, 1) = "-" Then
Try
' Create a proxy for the surface body in the context of the full occurrence path
Dim oBodyProxy As Object = oBody
If oParentOccurrences.Count > 0 Then
Dim oCurrentOcc As ComponentOccurrence
' Apply proxy creation for each level of nesting in reverse order
For i = oParentOccurrences.Count To 1 Step -1
oCurrentOcc = oParentOccurrences(i)
Dim oTempProxy As Object
oCurrentOcc.CreateGeometryProxy(oBodyProxy, oTempProxy)
If oTempProxy IsNot Nothing Then
oBodyProxy = oTempProxy
End If
Next
End If
' Turn off visibility of the body proxy in the drawing view
If oBodyProxy IsNot Nothing Then
oView.SetVisibility(oBodyProxy, False)
End If
Catch ex As Exception
' Log error silently or handle as needed
End Try
End If
Next
End Sub
Edited: UPD.
INV 2025.3