Getting all occurrences of a subassembly that is set to a Custom LOD

Getting all occurrences of a subassembly that is set to a Custom LOD

sergio_duran
Advocate Advocate
992 Views
4 Replies
Message 1 of 5

Getting all occurrences of a subassembly that is set to a Custom LOD

sergio_duran
Advocate
Advocate

Hi everyone,

 

I want to get all occurrences of a subassembly and I've always used this method in a Top Level Assembly.

 

ComponentOccurrences.AllReferencedOccurrences( Object As Object )

In my case, the object is a Document

 

However, I have a problem when I have multiple instances/occurrences of the same subassembly in the Top Level Assembly and not all of them are set to the Master LOD. For instance, a Top Level Assembly has 4 subassembly occurrences (same subassembly file placed 4 times in the Top Level Assembly) . 2 of the instances are set to Master LOD (default LOD when the subassembly is placed) and 2 of them are set to a custom LOD named 'LOD1'. The method to get AllReferencedOccurrences will only get 2 instead of 4 since it only gets the ones that are set to Master LOD.

 

How can I get all occurrences regardless of the LOD they are set to? I need to count all subassembly occurrences and this method is pretty handy only when subassemblies are using Master LOD. Thanks!

0 Likes
993 Views
4 Replies
Replies (4)
Message 2 of 5

basnederveen
Advocate
Advocate

If I understand your question correctly you are looking for AllLeafOccurrences.

0 Likes
Message 3 of 5

sergio_duran
Advocate
Advocate

Thanks for your reply! I'm not looking for AllLeafOccurences because they are parts. I'm looking for all subassemblies in an assembly regardless of the level and also regardless of the Level Of Detail they are using. I hope this make it clearer.

0 Likes
Message 4 of 5

basnederveen
Advocate
Advocate

ComponentDefinition.Occurrences should give you all occurrences, you should check the fullfilename to see if it matches. This will only give top-level. 

 

Sub TestASM()

Dim asm As AssemblyDocument
Set asm = ThisApplication.ActiveDocument

Dim cdef As ComponentDefinition
Set cdef = asm.ComponentDefinition

Dim occ As ComponentOccurrence
For Each occ In cdef.Occurrences
If occ.Definition.Document.fullFileName = "YOUR OCCURRENCE" Then
' Do something
End If
Next

End Sub

 

0 Likes
Message 5 of 5

sergio_duran
Advocate
Advocate

Thanks for your reply! I was trying to use Files rather than Occurrences to avoid traversing the entire assembly, because I need to count all subassemblies (regardless of the LOD the subassemblies are using - Custom LOD or Master LOD). Don't you think using your code structure will take longer to count all subassemblies? I need to get the total quantity of subassemblies (regardless of the level in the assembly structure and also the LOD). Thanks!

 

I've always used:

' Get the occurrences that represent this document. 
    Dim oOccs As ComponentOccurrencesEnumerator 
    Set oOccs = oAsmDef.Occurrences.AllReferencedOccurrences(oDoc) 

 

But this only works for master subassemblies. How can I count or get the total quantity of subassemblies with your code? I need to traverse the entire assembly anyhow, right? Thanks!

 

0 Likes