I am treversing an assembly and are trying to delete, hide, and suppress components. I have no problem with the components on the top level assembly (main assembly), but I have a problem with the lower level components, specificly patterns.
I kind of figured out that if I wanted to delete, hide or suppress lower level components I need a proxy object. That is easy for regular components that are of the type componentOccurrence. I get those throu the property SubOccurrences on the specified assembly.
But I can't figure out how to get the proxys of the type occurrencePattern. There seams to be no property for those, or any other way for searching for them.
Hi @jaka73LU2 . Wrote for you an example of obtaining all patterns (in the main assembly and subassemblies).
Private Sub Main()
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns, oDoc.DisplayName)
Call GetAllOccs(oDef.Occurrences)
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
Call GetAllPatterns(oOccDef.OccurrencePatterns, oOcc.Name)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences)
End If
End If
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, sNameParent As String)
For Each oOccPatt As OccurrencePattern In oOccsPatt
MessageBox.Show(oOccPatt.Name, sNameParent)
Next
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
I already tryed that but thought that it was not the right way, because the object I get back does not react to anything I would expect it to react to.
It does not react to visibility, suppression or adding it to selectSet. Example:
occPatt.Visibility = False
occPatt.Suppression()
This.Application.ActiveDocument.SelectSet.Select(occPatt)
When I try visibility it goes throo without an error, but nothing happens.
When I try suppress it gives error: Public member 'Suppress' on type 'RectangularOccurrencePattern' not found.
When I try SelectSet.Select I get an error: The parameter is incorect
Hi @jaka73LU2 . The visibility and suppression functions work perfectly, but SelectSet throws an error when trying to select items in a subassembly.
Private Sub Main()
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns, oColl)
Call GetAllOccs(oDef.Occurrences, oColl)
' If oColl Is Nothing Then Exit Sub
' Call oDoc.SelectSet.SelectMultiple(oColl)
' oDoc.Rebuild()
' oDoc.Update()
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences, ByRef oColl As ObjectCollection)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
Dim oOccDoc As AssemblyDocument = oOccDef.Document
If oOccDef.OccurrencePatterns.Count > 0 Then Call GetAllPatterns(oOccDef.OccurrencePatterns, oColl)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences, oColl)
End If
End If
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, ByRef oColl As ObjectCollection)
For Each oOccPatt As OccurrencePattern In oOccsPatt
' Work with visible
oOccPatt.Visible = False
MessageBox.Show(oOccPatt.Name & " - Visible", oOccPatt.Parent.Document.DisplayName)
oOccPatt.Visible = True
' Work with suppress
oOccPatt.Suppress(True)
MessageBox.Show(oOccPatt.Name & " - Suppress", oOccPatt.Parent.Document.DisplayName)
oOccPatt.Unsuppress()
'Select patterns
oColl.Add(oOccPatt)
Next
End Function
Also an example of working with the components of the opening subassembly:
Private Sub Main()
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns)
Call GetAllOccs(oDef.Occurrences)
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
if oOccDef.OccurrencePatterns.Count > 0 then Call GetAllPatterns(oOccDef.OccurrencePatterns, oOcc)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences)
End If
End If
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, Optional oOcc As ComponentOccurrence = Nothing)
If oOcc IsNot Nothing Then oOcc.Edit()
For Each oOccPatt As OccurrencePattern In oOccsPatt
MessageBox.Show(oOccPatt.Name, oOccPatt.Parent.Document.DisplayName)
Next
If oOcc IsNot Nothing Then oOcc.ExitEdit(ExitTypeEnum.kExitToParent)
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
I copied and pasted your code, but i am getting the same result.I would like to mention that I am making an AddIn so I slightly had to correct the code so a button is triggering the function.
Private Sub Button_test_Click(sender As Object, e As EventArgs) Handles Button_test.Click
Try
Dim oDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
Dim oColl As ObjectCollection = g_inventorApplication.TransientObjects.CreateObjectCollection
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns, oColl)
Call GetAllOccs(oDef.Occurrences, oColl)
If oColl Is Nothing Then Exit Sub
For Each obj In oColl
PrintToLog(obj.Name)
Next
oDoc.SelectSet.SelectMultiple(oColl)
'oDoc.Rebuild()
'oDoc.Update()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences, ByRef oColl As ObjectCollection)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
Dim oOccDoc As AssemblyDocument = oOccDef.Document
Call GetAllPatterns(oOccDef.OccurrencePatterns, oColl)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences, oColl)
End If
End If
oColl.Add(oOcc)
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, ByRef oColl As ObjectCollection)
For Each oOccPatt As OccurrencePattern In oOccsPatt
' Work with visible
oOccPatt.Visible = False
' Work with suppress
oOccPatt.Suppress(True)
'Select patterns
oColl.Add(oOccPatt)
Next
End Function
If I leave the line where it should suppress the patterns it gives an error: Public member 'Suppress' on type 'RectangularOccurrencePattern' not found.
If I comment out that line it gives an error at the 'SelectSet.SelectMultiple' where it gives an error: The parameter is incorrect.
The visibility line is ignored every time.
I need to point out that this problem persists only on lower level patterns. If I only look for top level patterns it works fine as expected.
Can't find what you're looking for? Ask the community or share your knowledge.