Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone , how I can suppress and unsuppress subassemblies based on conditions through Ilogic or VB code , thanks.
Solved! Go to Solution.
Hi everyone , how I can suppress and unsuppress subassemblies based on conditions through Ilogic or VB code , thanks.
Solved! Go to Solution.
Hi @Ahmed.shawkyXTZHN . This is a simple iLogic rule that suppresses all first-level subassembly. Describe how the rule should work, what the conditions should be, whether you need to add a message box with a question (suppress/unsuppress).
Dim oDoc As Document = ThisApplication.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
If Not oOcc.Suppressed Then oOcc.Suppress(True)
Next
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.
Hi @Andrii_Humeniuk is it possible to suppress all parts that has certain name "INNER" with simple code instead of using the below method , thanks.
Yes, it is not difficult. Here is the rule that Suppress and Unsuppress all first-level details with the word INNER in the name depending on the Double_SKIN parameter.
Dim oDoc As Document = ThisApplication.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim bSKIN As Boolean
Try : oParam = oAsmDef.Parameters("Double_SKIN").Value
Catch : Exit Sub : End Try
Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If Not oOcc.Name.Contains("INNER") Then Continue For
If bSKIN Then : oOcc.Unsuppress()
Else : oOcc.Suppress(False)
End If
Next
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.
thanks for your response , it works fine for parts in assembly but can it work for all levels for parts in sub assemblies as well , also it's suppressing but once I tick double skin again it is kept suppressed although it require to unsuppress, thanks.
Please try this code:
Sub main
Dim oDoc As Document = ThisApplication.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim bSKIN As Boolean
Try : oParam = oAsmDef.Parameters("Double_SKIN").Value
Catch : Exit Sub : End Try
Call SuppressINNER(oAsmDef.Occurrences, "INNER", bSKIN)
Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences
End Sub
Private Function SuppressINNER(ByVal oOccs As ComponentOccurrences,
ByVal sName As String,
ByVal bSKIN As Boolean)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType <> kAssemblyDocumentObject Then
If oOcc.SubOccurrences Is Nothing Then Continue For
Dim oSubOccs As ComponentOccurrencesEnumerator = oOcc.SubOccurrences
Dim iQTY As Integer = oSubOccs.Count
If iQTY = 0 Then Continue For
Call SuppressINNER(oSubOccs, sName, bSKIN)
Else
If Not oOcc.Name.Contains(sName) Then Continue For
If bSKIN Then : oOcc.Unsuppress()
Else : oOcc.Suppress(False)
End If
End If
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.
Because of my self-confidence, I didn't run tests after writing the code, so there were stupid errors. Now this code is working fine, please test it.
Sub main
Dim oDoc As Document = ThisApplication.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim bSKIN As Boolean
Try : bSKIN = oAsmDef.Parameters("Double_SKIN").Expression
Catch : Exit Sub : End Try
Call SuppressINNER(oAsmDef.Occurrences, "INNER", bSKIN)
End Sub
Private Function SuppressINNER(ByVal oOccs As ComponentOccurrences,
ByVal sName As String,
ByVal bSKIN As Boolean)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count = 0 Then Continue For
Call SuppressINNER(oOcc.SubOccurrences, sName, bSKIN)
Else
If Not oOcc.Name.Contains(sName) Then Continue For
If bSKIN Then : oOcc.Unsuppress()
Else : oOcc.Suppress(False)
End If
End If
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 hope these changes help you. Please try this code:
Sub main
Dim oInveApp As Inventor.Application = ThisApplication
Dim oDoc As Document = oInveApp.ActiveDocument
oDocs = oInveApp.Documents
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim bSKIN As Boolean
Try : bSKIN = oAsmDef.Parameters("Double_SKIN").Expression
Catch : Exit Sub : End Try
Call SuppressINNER(oAsmDef.Occurrences, "INNER", bSKIN)
End Sub
Dim oDocs As Documents
Private Sub SuppressINNER(ByVal oOccs As ComponentOccurrences, ByVal sName As String, ByVal bSKIN As Boolean)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count = 0 Then Continue For
Dim oRefDoc As AssemblyDocument = oDocs.Open(oOcc.Definition.Document.FullDocumentName, False)
Call SuppressINNER(oRefDoc.ComponentDefinition.Occurrences, sName, bSKIN)
Call oRefDoc.Close(True)
Else
If Not oOcc.Name.Contains(sName) Then Continue For
If bSKIN Then : oOcc.Unsuppress()
Else
Try : oOcc.Suppress(True)
Catch : MessageBox.Show(oOcc.Name, "Don`t suppress") : End Try
End If
End If
Next
End Sub
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.