Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic rule to unsuppress subassemblies and their components

anandax
Advocate

iLogic rule to unsuppress subassemblies and their components

anandax
Advocate
Advocate

Hi, 

 

i have a code to unsuppress the components in the assembly. Unfortunately, no subassemblies are considered. How i can unsuppress subassemblies and their components?

 

Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences

oComps = ThisDoc.Document.ComponentDefinition.Occurrences

For Each oComp In oComps
	If Component.IsActive(oComp.Name) = False Then oComp.Unsuppress
Next

 

0 Likes
Reply
Accepted solutions (2)
1,153 Views
10 Replies
Replies (10)

WCrihfield
Mentor
Mentor

Hi @anandax.  Are you simply wanting a rule that will un-suppress every component in every level of the assembly, without any other requirements or checks?  If you want to work with ComponentOccurrence objects, and you want your code to reach all levels of an assembly structure, then you will need a recursive sub routine.  Below is a very basic example of a rule like that with no error checking/handling.

Sub Main
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	RecurseComponents(oOccs)
End Sub

Sub RecurseComponents(oComps As ComponentOccurrences)
	If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
	For Each oComp As ComponentOccurrence In oComps
		If oComp.Suppressed Then oComp.Unsuppress
		If oComp.SubOccurrences.Count > 0 Then
			RecurseComponents(oComp.SubOccurrences)
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

anandax
Advocate
Advocate

 

Hi @WCrihfield. Thank you for your help. 

When I run it, I get the following message


Error in line 10 ("If oComp.Suppressed Then oComp.Unsuppress")

 

Unknown error (Exception from HRESULT: 0x80004005 (E_FAIL)

0 Likes

WCrihfield
Mentor
Mentor

Hmm...  I was trying to think of some reason why it would not allow you to un-suppress a component, and one thing that comes to mind is that the assembly is ReadOnly for some reason.  One way the assembly may be ReadOnly is if we were dealing with a ModelState 'member' version of the document reference.

Try changing this:

ThisDoc.Document

...to this:

ThisDoc.FactoryDocument

...and see if that changes things.

When you suppress components, that suppressed or unsuppressed state is recorded in the ModelStates.  Or, if you are using a version of Inventor previous to 2022, they would be recorded in the LOD's (LevelOfDetailRepresentations), and that alternate line I suggested above would not work for you.  Which version are you using?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

anandax
Advocate
Advocate

Unfortunately this also does not work. With your code only the components or assemblies directly in the assembly are unsuppressed. Components in a subassembly are still suppressed. The error message still appears

I am using version 2023.2.1. All files have write access (attrib -R C:\Workspace\*.* /D /S)

0 Likes

WCrihfield
Mentor
Mentor

I attached one more version of the code, but I am not that confident that it will work for you either, because I have not tested it on any local files.  I do not use this type of routine myself, because I control component suppression in my assemblies at each level, as I am building my model files, with ModelStates.  Then when I put my model into an assembly as a component, I set the component to the ModelState I want, which controls which sub-components will be suppressed.  So, I haven't tried a multi-level, top to bottom, wave of un-suppressing components since the ModelStates were involved.

 

If this code still does not work, I would suggest that you set-up the needed ModelStates within each of your sub-components, in which the component suppression is the way you want it, then just set the component's ActiveModelState to the one you have prepared for that situation, instead of trying to control all levels of suppression, down from the top level, all at once.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

anandax
Advocate
Advocate

Unfortunately it still does not work.

 

Enclosed is the iLogic Log

 

INFO| 1: >>---------------------------
TRACE|Entering rule: unsuppress_all (in Assembly_test_suppress.iam)
	ERROR|Error Unsuppressing component named Part2-circle_green:1
Unknown error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ComponentOccurrence.Unsuppress()
   at ThisRule.RecurseComponents(ComponentOccurrences oComps) in C:\Users\admin\AppData\Local\Temp\iLogic Rules\Assembly_test_suppress.iam.unsuppress_all.vb:line 21
	ERROR|Error Unsuppressing component named Part3_polygon_green:1
Unknown error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ComponentOccurrence.Unsuppress()
   at ThisRule.RecurseComponents(ComponentOccurrences oComps) in C:\Users\admin\AppData\Local\Temp\iLogic Rules\Assembly_test_suppress.iam.unsuppress_all.vb:line 21
	ERROR|Error Unsuppressing component named Part2-circle_green:1
Unknown error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ComponentOccurrence.Unsuppress()
   at ThisRule.RecurseComponents(ComponentOccurrences oComps) in C:\Users\admin\AppData\Local\Temp\iLogic Rules\Assembly_test_suppress.iam.unsuppress_all.vb:line 21
	ERROR|Error Unsuppressing component named Part3_polygon_green:1
Unknown error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ComponentOccurrence.Unsuppress()
   at ThisRule.RecurseComponents(ComponentOccurrences oComps) in C:\Users\admin\AppData\Local\Temp\iLogic Rules\Assembly_test_suppress.iam.unsuppress_all.vb:line 21
TRACE|Exiting rule: unsuppress_all (in Assembly_test_suppress.iam)

.

I have attached a test assembly (Test_Suppress.zip )

Currently I am analyzing a problem with Vault and suppressed components ( Link ).

For me, it would have been helpful if I could have restored all suppressed components.

 

The procedure with the Model States is also an option. If there is no other way, we will adapt it for existing assemblies. 

0 Likes

JelteDeJong
Mentor
Mentor
Accepted solution

try this

Sub Main()
    Dim doc = ThisDoc.Document
    res(ThisDoc.Document)
    doc.Update2()
End Sub

Sub res(doc As Document)
    If (doc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then Return

    Dim aDoc As AssemblyDocument = doc
    If (aDoc.ComponentDefinition.IsiAssemblyMember) Then
        aDoc = aDoc.ComponentDefinition.FactoryDocument
    End If

    Dim occs As ComponentOccurrences = aDoc.ComponentDefinition.Occurrences

    For Each occ As ComponentOccurrence In occs
        occ.Unsuppress()
        res(occ.Definition.Document)
    Next
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

anandax
Advocate
Advocate

@JelteDeJong 

 

Thank you very much. It works fine! :clapping_hands: :thumbs_up:

0 Likes

WCrihfield
Mentor
Mentor

OK. Now I feel like I have to ask the question...Why are you checking the "IsiAssemblyMember" property?  And if it was an iAssemblyMember, then why are you using the "FactoryDocument" property to get the correct version of the document.  The AssemblyComponentDefinition already has 4 direct properties specifically for iAssembly's  (IsiAssemblyFactory, IsiAssemblyMember, iAssemblyFactory, & iAssemblyMember).  So, if you are truly checking to see if it represented an iAssemblyMember, then why not use either the AssemblyComponentDefinition's iAssemblyMember property or its iAssemblyFactory property to get that reference, instead of using the FactoryDocument property, which relates to ModelStates?  If you were checking to see if the document represented a ModelState Member document, wouldn't you instead check the "IsModelStateMember" property, or maybe even the "IsModelStateFactory" property?  So, I am confused by how/why that code worked.  Does the IsiAssemblyMember property always return True when it really represents a ModelState member?  If so, that seems like a bug, because last I heard was that the ModelStates and the iParts & iAssemblies were going to remain two separate things that can't be present in the same document at the same time.  Also, if there is only one ModelState in any model document, its ComponentDefinition.FactoryDocument property will return 'Nothing', which seems like that could cause problems if checking IsiAssemblyMember returned True, because the following line is attempting to get components from that document reference that was just set to Nothing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

JelteDeJong
Mentor
Mentor
Accepted solution

@WCrihfield Your are absolute right. (This is not the first time I do this wrong....) the code should look more like this:

Sub Main()
    Dim doc = ThisDoc.Document
    res(ThisDoc.Document)
    doc.Update2()
End Sub

Sub res(doc As Document)
    If (doc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then Return

    Dim aDoc As AssemblyDocument = doc
    If (aDoc.ComponentDefinition.IsModelStateMember) Then
        aDoc = aDoc.ComponentDefinition.FactoryDocument
    End If

    Dim occs As ComponentOccurrences = aDoc.ComponentDefinition.Occurrences

    For Each occ As ComponentOccurrence In occs
        occ.Unsuppress()
        res(occ.Definition.Document)
    Next
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com