References¶
ReferenceGraph maintains a bidirectional index of cross-object references.
It powers doc.get_referencing() and doc.get_references() and is
automatically kept in sync as objects are added, removed, or renamed.
Reference graph for tracking object dependencies.
Provides O(1) lookups for: - What objects reference a given name? - What names does an object reference? - Validation of reference integrity
ReferenceGraph
¶
Tracks object references for instant dependency queries.
The graph maintains two indexes: - _referenced_by: name -> set of objects that reference it - _references: object -> set of names it references
This enables O(1) lookups for common operations like: - Finding all surfaces in a zone - Finding all objects using a construction - Detecting dangling references
The reference graph is automatically maintained by IDFDocument when objects are added, removed, or when reference fields are modified.
Examples:
The reference graph automatically tracks which objects point to which names. For instance, when a surface references a zone, that link is available for instant queries:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="",
... zone_name="Perimeter_ZN_1",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... validate=False)
BuildingSurface:Detailed('South_Wall')
>>> model.references.is_referenced("Perimeter_ZN_1")
True
>>> stats = model.references.stats()
>>> stats["total_references"] >= 1
True
Source code in src/idfkit/references.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
__len__()
¶
clear()
¶
get_dangling_references(valid_names)
¶
Find all references to non-existent objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid_names
|
set[str]
|
Set of valid object names (uppercase) |
required |
Yields:
| Type | Description |
|---|---|
tuple[IDFObject, str, str]
|
Tuples of (source_object, field_name, referenced_name) |
Source code in src/idfkit/references.py
get_references(obj)
¶
get_references_with_fields(obj)
¶
get_referencing(name)
¶
O(1): Get all objects that reference a given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to look up |
required |
Returns:
| Type | Description |
|---|---|
set[IDFObject]
|
Set of IDFObjects that reference this name |
Examples:
Find all surfaces assigned to a zone (O(1)):
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="",
... zone_name="Perimeter_ZN_1",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... validate=False)
BuildingSurface:Detailed('South_Wall')
>>> len(model.references.get_referencing("Perimeter_ZN_1"))
1
Source code in src/idfkit/references.py
get_referencing_with_fields(name)
¶
is_referenced(name)
¶
Check if a name is referenced by any object.
Examples:
Check whether a zone is used by any surface before deleting it:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model.references.is_referenced("Perimeter_ZN_1")
False
>>> model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="",
... zone_name="Perimeter_ZN_1",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... validate=False)
BuildingSurface:Detailed('South_Wall')
>>> model.references.is_referenced("Perimeter_ZN_1")
True
Source code in src/idfkit/references.py
register(obj, field_name, referenced_name)
¶
Register that an object references another name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
IDFObject
|
The object that contains the reference |
required |
field_name
|
str
|
The field that contains the reference |
required |
referenced_name
|
str
|
The name being referenced |
required |
Source code in src/idfkit/references.py
register_object_list(list_name, obj_type)
¶
rename_target(old_name, new_name)
¶
Update indexes when a referenced target is renamed.
Moves _referenced_by[OLD] -> _referenced_by[NEW] and updates corresponding _references entries for all affected objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The old target name |
required |
new_name
|
str
|
The new target name |
required |
Source code in src/idfkit/references.py
stats()
¶
Return statistics about the reference graph.
Source code in src/idfkit/references.py
unregister(obj)
¶
Remove all reference tracking for an object.
Source code in src/idfkit/references.py
update_reference(obj, field_name, old_value, new_value)
¶
Update indexes when an object's reference field changes.
Removes the old entry from both indexes and adds the new entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
IDFObject
|
The object whose field changed |
required |
field_name
|
str
|
The field that changed |
required |
old_value
|
str | None
|
The previous referenced name (or None) |
required |
new_value
|
str | None
|
The new referenced name (or None) |
required |