Entities method for a Component Instance

A component instance defines not its own entities, but refers to a definition which has an entities method. All instances of the definition thus have the same entities.

component_instance.definition.entities

Be aware that when you traverse two instances of the same definition, you will visit the same definition entities twice. Both instances have the same definition and same entities, but the instances have different instance paths (list of parent group/component instances in the nesting tree). The same face in the definition entities may occur in several places of the model with different instance paths.

When you want to traverse recursively, you first need to decide whether you are interested in visiting every occurence of an entity (visiting the same face multiple times, for polygon counting, area summing, exporting to a primitive mesh format) or only visiting it only once (for applying an operation to the definition’s entities, for exporting to a format that supports instances).

In the first case, see recursive tree traversal in SketchUp. In the second case it’s easier to traverse the definitions list (plus the direct entities of the model).

1 Like