Can all features/subparts be suppressed within an assembly using an ilogic rule?

Can all features/subparts be suppressed within an assembly using an ilogic rule?

tyler_prather
Observer Observer
521 Views
8 Replies
Message 1 of 9

Can all features/subparts be suppressed within an assembly using an ilogic rule?

tyler_prather
Observer
Observer

I was curious if there was a simple way to suppress everything within an assembly file using ilogic. I have looked at other examples posted here and each scenario required you to name all of the individual parts or subassemblies within the master assembly. The assemblies that I am working with would vary in the quantity of parts/assemblies within, but most of them would have an extremely large list of parts to suppress. For my scenario, it would be easier for me to suppress everything within and then name the few parts to unsuppress.

0 Likes
522 Views
8 Replies
Replies (8)
Message 2 of 9

Frederick_Law
Mentor
Mentor

Try

 

Dim oDoc As Document
Dim oCompDef As ComponentDefinition
Dim oOccu As ComponentOccurrence

oDoc = ThisDoc.Document
Logger.Info("Doc Name " & oDoc.DisplayName)
oCompDef = oDoc.ComponentDefinition
For Each oOccu In oCompDef.Occurrences
oOccu.Suppress
'oOccu.UnSuppress
Next

 

 

This is VBA code, you might need to change it for iLogic.

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

Here is another fairly basic iLogic example which first ensures you are working with an assembly.  Then loops through all of its features to make sure they are suppressed.  Then loops through all components to make sure they are suppressed.  It uses Try...Catch blocks because suppressing, and unsuppressing things often needs to be done in the correct order or else they will cause problems.  I am also suppressing the features first, before the components, because suppressing the components that features are based on will often cause the features to fail, and throw errors.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oFeats As Features = oADef.Features
If oFeats.Count = 0 Then  GoTo SuppOccs
For Each oFeat As PartFeature In oFeats
	If Not oFeat.Suppressed Then
		Try : oFeat.Suppressed = True: Catch : End Try
	End If
Next
SuppOccs :
Dim oOccs As ComponentOccurrences = oADef.Occurrences
If oOccs.Count = 0 Then Exit Sub
For Each oOcc As ComponentOccurrence In oOccs
	If Not oOcc.Suppressed Then
		Try : oOcc.Suppress : Catch : End Try
	End If
Next

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

tyler_prather
Observer
Observer

Your answer did do exactly what I described, but I discovered a new issue. Sorry in advance for this lengthy response. My reason for asking how to suppress everything was because after I had established this; I was planning on naming the few elements to unsuppress, rather than naming the large amount to suppress.

Typically, I was manually creating a LOD, expanding several assemblies/subassemblies, and suppressing nearly all of the parts within.

If the very top level assembly is A, has several B subassemblies within, and within the B assembly there are several parts and C subassemblies. I was suppressing nearly all of the parts in the C subassembly, and suppressing all parts in the B assemblies. In your ilogic example, once element B is suppressed it eliminates the ability to unsuppress anything within the assembly. (browser tree example below)

+A main assembly

      +B subassembly

             +C subassembly

                  ipt

                  ipt

                  many more parts and assemblies within.

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

OK.  So, are you saying that you want the code to dig down to the lowest level 'child' components that represent parts and suppress their features and components first, then suppress their 'parent' sub assembly's features and components, and work back upwards from the bottom, suppressing every feature and component it encounters along the way?  That can get pretty complicated to manage.  Do you want the code to create any new ModelStates within any of the sub assemblies along the way, to save the suppression state at those levels, or do you only want the code to effect the top level assembly only?  If you only want to effect the top level assembly, then we could always use the ComponentOccurrence.SubOccurrences way of stepping down, instead of the ComponentOccurrence.Definition.Occurrences way of stepping down.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 9

Frederick_Law
Mentor
Mentor

The loop is not a problem.

Memory use could be.  It is recursive loop.

The loops will be as deep as the assembly.

 

A sample VBA recursive loop:

 

 

Sub SaveThumbnail()
Dim oDoc As Inventor.Document
Set oDoc = ThisApplication.ActiveDocument
Dim oView As View
Set oView = ThisApplication.ActiveView
Dim oCamera As Camera
Set oCamera = oView.Camera
oCamera.ViewOrientationType = kIsoTopRightViewOrientation
oCamera.Apply
oCamera.Fit
oCamera.Apply
oDoc.SetThumbnailSaveOption (kActiveWindow)
oDoc.Update
oDoc.Save
End Sub


Sub SaveAsmThumbnail()
Dim oDoc As Inventor.Document
Dim oRefDoc As Inventor.Document
Dim oCompDoc As Inventor.Document
Set oDoc = ThisApplication.ActiveDocument
SaveThumbnail
For Each oRefDoc In oDoc.ReferencedDocuments
    If oRefDoc.IsModifiable Then
        Set oCompDoc = ThisApplication.Documents.Open(oRefDoc.FullFileName)
        SaveThumbnail
        If oCompDoc.ReferencedDocuments.Count > 0 Then
            Call procAllThumb(oRefDoc)
        End If
        oCompDoc.Close
    End If
Next
End Sub


Private Sub procAllThumb(ByVal oSubDoc As Inventor.Document)
    
    Dim oCompDoc As Inventor.Document
    Dim oRefDoc As Inventor.Document
    For Each oRefDoc In oSubDoc.ReferencedDocuments
        If oRefDoc.ReferencedDocuments.Count > 0 Then
            Call procAllThumb(oRefDoc)
        End If
        If oRefDoc.IsModifiable Then
        Set oCompDoc = ThisApplication.Documents.Open(oRefDoc.FullFileName)
        SaveThumbnail
        oCompDoc.Close
        End If
    Next
End Sub

 

 

 

0 Likes
Message 7 of 9

tyler_prather
Observer
Observer

Your first statement summarizes what effect I would like it to have. Suppressing items from deeper within the model and working its way back up. This would also only have to make the changes in the top level assembly.

 

Also, in reply to the strand about using looping. It was my understanding that I would have to name each of the components within the model that I wanted to suppress and unsuppress if using the looping method. I had also tried using the code that was provided and received an error upon saving. I didn't have time to decipher what was wrong.

0 Likes
Message 8 of 9

Frederick_Law
Mentor
Mentor

@tyler_prather wrote:

I didn't have time to decipher what was wrong.


Just let you know we don't get paid to code here.

We're just trying to help 😉

0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

I did actually do a bit of work on this yesterday, but did not have anything ready to present yet.  This can be a fairly complex task to automate correctly, without any errors.  I have this code, but I have not tested it out yet, because I just haven't had time, or a good test subject, outside of our production stuff to give it a really good test on.  If you test it, maybe test in on something that is not critical first, just to be safe.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	Dim oAllLeafOccs As ComponentOccurrencesEnumerator = oOccs.AllLeafOccurrences
	'first suppress all parts only, in all levels
	For Each oLeafOcc As ComponentOccurrence In oAllLeafOccs
		If oLeafOcc.Suppressed = False Then
			Try : oLeafOcc.Suppress : Catch : End Try
		End If
	Next
	'now recustively suppress all of the remaining sub assemblies, from bottom ot top
	RecurseComponents(oOccs, AddressOf ProcessComponent)
	
End Sub

Sub RecurseComponents(oComps As ComponentOccurrences, ComponentProcess As Action(Of ComponentOccurrence))
	If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
	For Each oComp As ComponentOccurrence In oComps
		ComponentProcess(oComp)
		If oComp.Suppressed = False AndAlso _
			oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			RecurseComponents(oComp.SubOccurrences, ComponentProcess)
		End If
	Next
End Sub

Sub ProcessComponent(oComp As ComponentOccurrence)
	If IsNothing(oComp) OrElse oComp.Suppressed Then Exit Sub
	If TypeOf oComp.Definition Is VirtualComponentDefinition Or _
		TypeOf oComp.Definition Is WeldsComponentDefinition Or _
		oComp.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Try : oComp.Suppress(True) : Catch : End Try 'True = skip saving the source document
	ElseIf oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject And _
		oComp.SubOccurrences.Count > 0 Then
		'if all of the sub assembly's components are not suppressed yet, to not suppress this sub assembly yet
		Dim bAllOccsSuppressed As Boolean = True
		For Each oSubOcc As ComponentOccurrence In oComp.SubOccurrences
			If oSubOcc.Suppressed = False Then
				bAllOccsSuppressed = False
				Exit For
			End If
		Next 'oSubOcc
		If bAllOccsSuppressed = True Then
			Try : oComp.Suppress(True) : Catch : End Try 'True = skip saving the source document
		End If
	End If
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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes