Objects¶
IDFObject represents a single EnergyPlus object (e.g. a Zone or a
Material). Fields are accessed as snake_case Python attributes.
IDFCollection is a name-indexed container of objects that share the same
EnergyPlus type, providing O(1) lookup by name, iteration, and filtering.
Core object classes for IDF representation.
IDFObject: Thin wrapper around a dict with attribute access. IDFCollection: Indexed collection of IDFObjects with O(1) lookup.
IDFCollection
¶
Bases: Generic[_T]
Indexed collection of IDFObjects with O(1) lookup by name.
Provides list-like iteration and dict-like access by name.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model.add("Zone", "Core_ZN")
Zone('Core_ZN')
>>> zones = model["Zone"]
>>> len(zones)
2
O(1) lookup by name:
Attributes:
| Name | Type | Description |
|---|---|---|
_type |
str
|
The object type this collection holds |
_by_name |
dict[str, _T]
|
Dict mapping uppercase names to objects |
_items |
list[_T]
|
Ordered list of objects |
Source code in src/idfkit/objects.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
by_name
property
¶
Dict mapping uppercase names to objects.
obj_type
property
¶
The object type this collection holds.
__getitem__(key)
¶
Get object by name or index.
Source code in src/idfkit/objects.py
add(obj)
¶
Add an object to the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
_T
|
The IDFObject to add |
required |
Returns:
| Type | Description |
|---|---|
_T
|
The added object |
Raises:
| Type | Description |
|---|---|
DuplicateObjectError
|
If an object with the same name exists |
Source code in src/idfkit/objects.py
filter(predicate)
¶
Filter objects by predicate function.
Examples:
Find zones on upper floors of a multi-story building:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Ground_Office", z_origin=0.0)
Zone('Ground_Office')
>>> model.add("Zone", "Floor2_Office", z_origin=3.5)
Zone('Floor2_Office')
>>> upper = model["Zone"].filter(lambda z: (z.z_origin or 0) > 0)
>>> [z.name for z in upper]
['Floor2_Office']
Source code in src/idfkit/objects.py
first()
¶
Get the first object or None.
Examples:
Quickly grab a singleton like Building or SimulationControl:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Core_ZN")
Zone('Core_ZN')
>>> model["Zone"].first().name
'Core_ZN'
>>> model["Material"].first() is None
True
Source code in src/idfkit/objects.py
get(name, default=None)
¶
Get object by name with default.
For unnamed/singleton object types (e.g. SimulationControl), pass an empty string to retrieve the first object in the collection.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model["Zone"].get("Perimeter_ZN_1").name
'Perimeter_ZN_1'
>>> model["Zone"].get("NonExistent") is None
True
>>> model["SimulationControl"].get("") is not None
True
Source code in src/idfkit/objects.py
remove(obj)
¶
Remove an object from the collection.
to_dict()
¶
Convert all objects to list of dicts (eppy compatibility).
Useful for feeding zone/material data into pandas or other analysis tools.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1", x_origin=0.0)
Zone('Perimeter_ZN_1')
>>> dicts = model["Zone"].to_dict()
>>> dicts[0]["name"]
'Perimeter_ZN_1'
Source code in src/idfkit/objects.py
to_list()
¶
Convert to list.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> model.add("Zone", "Core_ZN")
Zone('Core_ZN')
>>> [z.name for z in model["Zone"].to_list()]
['Perimeter_ZN_1', 'Core_ZN']
Source code in src/idfkit/objects.py
IDFObject
¶
Bases: EppyObjectMixin
Lightweight wrapper around a dict representing an EnergyPlus object.
Uses slots for memory efficiency - each object is ~200 bytes. Provides attribute access to fields via getattr/setattr.
Examples:
Create a rigid insulation material and access its properties:
>>> from idfkit import new_document
>>> model = new_document()
>>> insulation = model.add("Material", "XPS_50mm",
... roughness="Rough", thickness=0.05,
... conductivity=0.034, density=35.0, specific_heat=1400.0)
Read thermal properties as attributes:
Modify for parametric analysis (double the insulation):
Export to a dictionary for use with external tools:
Attributes:
| Name | Type | Description |
|---|---|---|
_type |
str
|
The IDF object type (e.g., "Zone", "Material") |
_name |
str
|
The object's name (first field) |
_data |
dict[str, Any]
|
Dict of field_name -> value |
_schema |
dict[str, Any] | None
|
Optional schema dict for validation |
_document |
IDFDocument[bool] | None
|
Reference to parent document (for reference resolution) |
_field_order |
list[str] | None
|
Ordered list of field names from schema |
Source code in src/idfkit/objects.py
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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
data
property
¶
The field data dictionary.
field_order
property
¶
Ordered list of field names from schema.
mutation_version
property
¶
Monotonically increasing counter bumped on every field write.
Useful for caches that need to detect whether an object has been modified since a cached value was computed.
name
property
writable
¶
The object's name.
obj_type
property
¶
The IDF object type (e.g., 'Zone', 'Material').
schema_dict
property
¶
The schema dict for this object type.
source_text
property
¶
Original source text from parsing, or None if the object was mutated or created programmatically.
__dir__()
¶
Return attributes for tab completion (includes schema field names).
Source code in src/idfkit/objects.py
__getattr__(key)
¶
Get field value by attribute name.
When the parent document has strict=True, accessing a field
name that is neither present in the data dict nor recognised by
the schema raises AttributeError instead of returning
None. This catches typos during migration.
Source code in src/idfkit/objects.py
__getitem__(key)
¶
Get field value by name or index.
Source code in src/idfkit/objects.py
__setattr__(key, value)
¶
Set field value by attribute name.
Extensible field names are normalized to the epJSON schema convention
(field, field_2; vertex_x_coordinate, vertex_x_coordinate_2).
Source code in src/idfkit/objects.py
__setitem__(key, value)
¶
Set field value by name or index.
Source code in src/idfkit/objects.py
copy()
¶
Create a copy of this object.
Source code in src/idfkit/objects.py
get(key, default=None)
¶
Get field value with default.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> mat = model.add("Material", "Concrete_200mm",
... roughness="MediumRough", thickness=0.2,
... conductivity=1.4, density=2240.0, specific_heat=900.0)
>>> mat.get("conductivity")
1.4
>>> mat.get("thermal_absorptance", 0.9)
0.9
Source code in src/idfkit/objects.py
to_dict()
¶
Convert to dictionary representation.
Useful for serializing EnergyPlus objects to JSON, CSV, or DataFrames for post-processing.
Examples:
>>> from idfkit import new_document
>>> model = new_document()
>>> mat = model.add("Material", "Concrete_200mm",
... roughness="MediumRough", thickness=0.2,
... conductivity=1.4, density=2240.0, specific_heat=900.0)
>>> d = mat.to_dict()
>>> d["name"], d["thickness"], d["conductivity"]
('Concrete_200mm', 0.2, 1.4)
Source code in src/idfkit/objects.py
extensible_schema_name(base, group)
¶
Generate the epJSON schema-convention name: base for group 1, base_N for N>=2.
normalize_extensible_name(field_name, extensibles)
¶
Normalize an extensible field name to the epJSON schema convention.
Converts field_1 → field, vertex_1_x_coordinate → vertex_x_coordinate,
vertex_2_x_coordinate → vertex_x_coordinate_2, etc.
Returns the name unchanged if it is not extensible.
Source code in src/idfkit/objects.py
parse_extensible_index(field_name, extensibles)
¶
Extract the base name and 1-based group index from an extensible field name.
Handles both naming conventions:
- field_1 / field_2 (user style, base field)
- vertex_1_x_coordinate / vertex_2_x_coordinate (user style)
- field / field_2 (schema style, first group has no number)
- vertex_x_coordinate / vertex_x_coordinate_2 (schema style)
Returns (base_name, group_index) or (None, 0) if not extensible.
Source code in src/idfkit/objects.py
to_idf_name(python_name)
¶
Convert Python name back to IDF-style name.
'direction_of_relative_north' -> 'Direction of Relative North'
to_python_name(idf_name)
¶
Convert IDF field name to Python-friendly name.
'Direction of Relative North' -> 'direction_of_relative_north' 'X Origin' -> 'x_origin'