Occurrences in the assembly

Occurrences in the assembly

pavol_krasnansky
Enthusiast Enthusiast
566 Views
4 Replies
Message 1 of 5

Occurrences in the assembly

pavol_krasnansky
Enthusiast
Enthusiast

Hi. I want to get a FullFileName from a suppressed occurrences and non-suppressed occurrences in an Assembly. I tried iLogic rule below. The rule works correctly for a part or an assembly.. Issues is when the occurrence is for example a weld or a virtual component or other item that can be suppressed and does not have the FullFileName. How can I check if the item is the part or the assembly?

 

Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		
		Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
		Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
		Dim oOcc As ComponentOccurrence
		Dim List_Of_Components As New List(Of String)
		
		For Each oOcc In oOccs
			If oOcc.Suppressed = True Then
				List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - True")
			ElseIf oOcc.Suppressed = False Then
				List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - False")
			End If
		Next
		
		a = InputListBox("List Of Components:", List_Of_Components)
		
	End If
End Sub
0 Likes
Accepted solutions (1)
567 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

You can check the type of component definition

If Typeof oOcc.Definition PartComponentDefinition Then
   'Do Something
ElseIf Typeof oOcc.Definition Is AssemblyComponentDefinition Then
    'Do Something
End If

Or the same but different method of writing type

If oOcc.Definition.Type = ObjectTypeEnum.kPartComponentDefinitionObject Then
   'Do Something
ElseIf oOcc.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
    'Do Something
End If

Or check the definitiondocument type

If Typeof oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
   'Do Something
ElseIf Typeof oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
    'Do Something
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 5

pavol_krasnansky
Enthusiast
Enthusiast

Thank you, but it does not work.
Solutions 1 and 2 only work for non-suppressed components.
Solution 3 does not work for a weld (for example) because a weld is also a kAssemblyDocumentObject. I look for an universal solutions for every cases.

 

Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		
		Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
		Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
		Dim oOcc As ComponentOccurrence
		Dim List_Of_Components As New List(Of String)
		
		For Each oOcc In oOccs
		MsgBox(oOcc.Name)
		MsgBox(oOcc.DefinitionDocumentType.ToString())
			
			' If Typeof oOcc.Definition Is PartComponentDefinition Or
			' Typeof oOcc.Definition Is AssemblyComponentDefinition Then
			
			' If oOcc.Definition.Type = ObjectTypeEnum.kPartComponentDefinitionObject Or
			' oOcc.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
			
			If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Or
			oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			
				If oOcc.Suppressed = True Then
					List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - True")
				ElseIf oOcc.Suppressed = False Then
					List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - False")
				End If
			End If
		Next
		
		a = InputListBox("List Of Components:", List_Of_Components)
		
	End If
End Sub
0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor

You probably have no option but to check suppresed status then unsuppress occurrence check your filename and then suppress again.   

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 5

pavol_krasnansky
Enthusiast
Enthusiast
Accepted solution

The code below works:

 

Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		
		Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
		Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
		Dim oOcc As ComponentOccurrence
		Dim List_Of_Components As New List(Of String)
		
		For Each oOcc In oOccs
			If oOcc.ReferencedFileDescriptor IsNot Nothing Then
				If oOcc.Suppressed = True Then
					List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - True")
				ElseIf oOcc.Suppressed = False Then
					List_Of_Components.Add(oOcc.ReferencedFileDescriptor.FullFileName & "- Suppressed - False")
				End If
			End If
		Next
		
		a = InputListBox("List Of Components:", List_Of_Components)
		
	End If
End Sub