There's a subtlety first in that a component is distinct from an occurrence which is, essentially, a component instance. They are used interchangeably sometimes!
Anyway. If you start with the rootComponent say (or any component but root is most obvious), and look at its occurrences property - this is a collection of the Occurrences associated with that component (yes, it's mildly headwrecking initially). You will see it has a "asList" property which yields the collection as a list - with the usual count property and item() method. If you traverse that list that will give you a component tree:
for i in range(occurrencelist.count):
occ = occurrencelist.item(i)
So each occ.component is the component that occurrence references. If occ.childOccurrences is non Null, the occurrence has a subtree of occurrences which gives you another list of occurrences and so on down the tree. You can do a classic recursive action to traverse the tree:
def traverse(occurrences):
for i in range(occurrences.count):
occ = occurrences.item(i)
.... do stuff with occ like look at occ.component ....
if occ.childOccurrences:
traverse(occ.childOccurrences)
Something like that anyway 🙂
Conor.