Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Suppress Parts within Subassemblies ilogic

23 REPLIES 23
Reply
Message 1 of 24
mlatif
2543 Views, 23 Replies

Suppress Parts within Subassemblies ilogic

I am trying to suppress part that are labeled as "Reference" on the BOM Strutcture and I can't get the program to cycle through the subassemblies.  The following code runs through all the components on the top-level assembly but I can't get it to cycle through the subassemblies.  Any help would be great, thanks.

oCompDef = ThisDoc.Document.ComponentDefinition
oAssemblyComponents = oCompDef.Occurrences
Dim oOccurrence As ComponentOccurrence
Dim oSubOccurrence1 As ComponentOccurrence


For Each oOccurrence In oAssemblyComponents
     If (oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure) Then
            Component.IsActive(oOccurrence.Name) = False
     Else
            Component.IsActive(oOccurrence.Name) = True
     End If
Next

 

23 REPLIES 23
Message 21 of 24

Thanks a lot for posting this as I'm pretty sure I'll be working on something similar again soon!
Message 22 of 24
tadej.grahek
in reply to: mlatif

I have an easy task for you guys....

 

I have main assembly where iLogic rule is placed. In main assembly is subassemly (lets call it "ASS2"). In this subassembly is part (lets call it "PART1") which I want to suppress if something is true.

So my if sentence goes like this:

 

if LENGHT > 500 then 'LENGHT is dimension in main assembly

       component.isactive("PART1") = FALSE????                      ' here I want to suppress in ASS2 PART1

else component.isactive("PART1") = TRUE???? 

end if

 

help please

thank you very much

Tadej

 

 

Message 23 of 24
A.Acheson
in reply to: tadej.grahek

In my testing the ilogic snippet "component.isactive("PART")" can only take effect on the first level of the main assembly or if used internally in the sub assembly. You have to use the API to access the occurrence in the context of the main assembly. A custom level of detail needs to be activated first. Hopefully this is what you were thinking of. 

 

The basics of the occurrence recursive loop is referenced from this link. 

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

 Sub Main
    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    
	Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	
	'Create a level of detail so we can change the suppression state of the occurrences
	Try
	oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations("LevelofDetail1").Activate
	Catch
	oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("LevelofDetail1")
	End Try
	
	Logger.Info("Main Assembly:" & oAsmDoc.DisplayName)

    ' Call the function that does the recursion.
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)
	
End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    For Each oOcc In Occurrences
      
        ' Check to see if this occurrence represents a subassembly
        ' and recursively call this function to traverse through it.
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
			'Print occurrence to see the structure
			Logger.Info("Assy Occurrence:" & Space(Level * 3) & oOcc.Name)
			
			'We know the sub assembly we want to target is in the first level
			If oOcc.Name = "ASS2" Then
				'Recursive loop  sub assembly and supply back suboccurrences
            	Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
			End If
        End If
		'------------------------Do Something with occurrences found---------------------------------------

			If oOcc.DefinitionDocumentType = kPartDocumentObject Then
				
				Logger.Info("Part Occurrence:" & Space(Level * 4) & oOcc.Name)
			
					If oOcc.Name = "PART1" Then
						If LENGTH > 500 Then
oOcc.Unsuppress Else oOcc.Suppress End If End If End If Next End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 24 of 24
tadej.grahek
in reply to: A.Acheson

thank you very much, it works likes a charm,
cheers

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report