Suppress and unsuppress subassemblies based on conditions

Suppress and unsuppress subassemblies based on conditions

Ahmed.shawkyXTZHN
Enthusiast Enthusiast
747 Views
10 Replies
Message 1 of 11

Suppress and unsuppress subassemblies based on conditions

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi everyone , how I can suppress and unsuppress subassemblies based on conditions through Ilogic or VB code , thanks.

0 Likes
Accepted solutions (1)
748 Views
10 Replies
Replies (10)
Message 2 of 11

Andrii_Humeniuk
Advisor
Advisor
Accepted 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.

EESignature

0 Likes
Message 3 of 11

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
THANKS
0 Likes
Message 4 of 11

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

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.

AhmedshawkyXTZHN_0-1698569628216.png

 

 

 

0 Likes
Message 5 of 11

Andrii_Humeniuk
Advisor
Advisor

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.

EESignature

0 Likes
Message 6 of 11

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

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.

0 Likes
Message 7 of 11

Andrii_Humeniuk
Advisor
Advisor

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.

EESignature

0 Likes
Message 8 of 11

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
I received error on line 18 , Error on line 18 in rule: Rule8, in document: 00223807.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
0 Likes
Message 9 of 11

Andrii_Humeniuk
Advisor
Advisor

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.

EESignature

0 Likes
Message 10 of 11

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
thanks Andrii , I received error for line 23 for unsuppressing.
0 Likes
Message 11 of 11

Andrii_Humeniuk
Advisor
Advisor

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.

EESignature

0 Likes