What You’ll Learn
By the end of this guide, you’ll understand:- ✅ How to recursively traverse nested object structures
- ✅ How to filter objects by property values while traversing
- ✅ How to extract geometry from BIM objects
- ✅ How to handle hierarchical collections and preserve context
Prerequisites
Before starting this guide, you should:- Understand how to work with Speckle objects
- Be familiar with data traversal concepts
- Know basic Python recursion
This guide builds on traversal fundamentals from the Core Concepts. We focus on practical
patterns for finding and extracting data from real-world Speckle projects.
How do I traverse nested Speckle data?
Speckle data is often deeply nested - buildings contain levels, levels contain rooms, rooms contain elements. You need to visit every object in the tree to process or analyze them.Terminology Note: When we use terms like “levels”, “rooms”, or reference property names in
examples, these are for illustrative purposes. Real BIM data from connectors (Revit, Rhino,
etc.) uses proxy structures - for example, Revit levels are represented as
LevelProxy
objects in dedicated collections, not as direct hierarchy. See the Proxification
guide and BIM Data
Patterns for actual BIM data structures.GraphTraversal for robust traversal:
Understanding GraphTraversal Components
Understanding GraphTraversal Components
The SDK provides three key components for traversal:
-
GraphTraversal- The main traversal engine- Creates the traversal instance:
GraphTraversal([rules]) - Executes traversal:
.traverse(root)returns an iterator - Pass
[]for default behavior (traverse everything)
- Creates the traversal instance:
-
TraversalContext- Information about each visited object.current- The currentBaseobject being visited.member_name- Property name from parent (e.g., “elements”, “displayValue”).parent- ParentTraversalContext(or None if root)
-
TraversalRule- Optional rules to control behavior_conditions- When does this rule apply? (list of predicates)_members_to_traverse- What properties to traverse? (function returning list)_should_return_to_output- Include objects in results? (boolean)
- ✅ Handles all edge cases (dicts, lists, nested Base objects)
- ✅ Provides context (parent object, property name)
- ✅ Supports custom rules for filtering during traversal
- ✅ Memory efficient (uses iterators, not lists)
- ✅ Battle-tested in production SDK code
- Base case: Check if object is a
Baseinstance - Process: Do something with the current object
- Recurse: Visit all child objects via
get_member_names()
get_member_names()? It returns all property names on the
object, already filters out private members (_) and methods, and
works with both typed and dynamic properties.
How do I find specific objects?
You need to find all objects matching certain criteria - for example, all walls, all objects on a specific level, or all elements with a particular property value. Filter while traversing by checking conditions and collecting matches:About “category” property: When we reference
properties["category"] in examples, this
demonstrates the pattern. Real BIM data may organize categories differently - Revit data, for
instance, uses both properties["category"] on individual objects AND category-based proxy
collections. See BIM Data Patterns for
production patterns.True for objects you want to keep:
How do I extract geometry from BIM objects?
BIM objects from connectors (Revit, Rhino, etc.) contain geometry in thedisplayValue property. You need to extract these meshes for visualization or analysis.
Check for displayValue and collect geometry objects:
How do I work with hierarchical collections?
BIM data often has hierarchical structures: Building → Levels → Rooms → Elements. You need to process these hierarchies while maintaining context about where each object came from. Track hierarchy levels during traversal:Practical Examples
Example 1: Find All Walls on a Specific Level
Example 2: Extract Geometry by Category
Example 3: Build a Category Summary Report
Learn More
Core Concepts:- Data Traversal - Deep dive into traversal patterns
- Display Values - Understanding geometry representation
- BIM Data Patterns - Advanced BIM-specific patterns
- Working with Geometry - Geometry manipulation
- Understanding Speckle Mesh - Mesh structure details
- Advanced: Performance and Complex Patterns - Learn optimization techniques
Next Steps
Now that you can find and extract data, you’re ready to:- Optimize for performance - Build indexes for large datasets
- Handle complexity - Work with detached objects and references
- Extract Revit parameters - Access nested BIM metadata efficiently