Skip to content

Object collections

Use ObjectCollection to look up configured project definitions by name or position. String lookup is case-insensitive, iteration follows configured project order, and by_index() accepts a zero-based position. Collections and their objects are Live Views tied to the current project generation. Reopening a project means getting fresh views.

from swmmrs import Simulation, StaleViewError

simulation = Simulation("model.inp", "model.rpt")
curves = simulation.curves
print(tuple(curves))  # Configured IDs in project order.
curve = curves["pump-curve"]  # Case-insensitive ID lookup.
assert curves.by_index(0).id == tuple(curves)[0]
assert "PUMP-CURVE" in curves

simulation.close()
try:
    print(curve.id)
except StaleViewError:
    print("Reopen the project and reacquire the collection and object views")

Typed, generation-bound views over configured SWMM project objects.

All view instances retain the simulation and project generation that created them. They validate that identity before accessing native state, so retained views cannot silently address a subsequently reopened project.

CLASS DESCRIPTION
ObjectCollection

Provide mapping-style access to configured project objects.

ObjectCollection


              flowchart TD
              swmmrs.objects.ObjectCollection[ObjectCollection]
              swmmrs.objects._collections._Collection[_Collection]

                              swmmrs.objects._collections._Collection --> swmmrs.objects.ObjectCollection
                


              click swmmrs.objects.ObjectCollection href "" "swmmrs.objects.ObjectCollection"
              click swmmrs.objects._collections._Collection href "" "swmmrs.objects._collections._Collection"
            

Provide mapping-style access to configured project objects.

Notes

Object IDs are case-insensitive. Use by_index() for configured order.

METHOD DESCRIPTION
__contains__

Return whether a case-insensitive object ID is configured.

__getitem__

Return an object view by case-insensitive configured ID.

__iter__

Return an iterator over object IDs in configured project order.

__len__

Return the number of configured objects in this collection.

by_index

Return an object view by its zero-based configured position.

__contains__

__contains__(key: object) -> bool

Return whether a case-insensitive object ID is configured.

PARAMETER DESCRIPTION
key

Candidate object ID.

TYPE: object

RETURNS DESCRIPTION
bool

True when key identifies a configured object; otherwise False.

__getitem__

__getitem__(key: str | int) -> _T

Return an object view by case-insensitive configured ID.

PARAMETER DESCRIPTION
key

Object ID as a string or non-boolean integer.

TYPE: str | int

RETURNS DESCRIPTION
_T

Generation-bound object view.

RAISES DESCRIPTION
KeyError

If no configured object has the requested ID.

TypeError

If key is not a string or non-boolean integer.

__iter__

__iter__() -> Iterator[str]

Return an iterator over object IDs in configured project order.

__len__

__len__() -> int

Return the number of configured objects in this collection.

by_index

by_index(index: int) -> _T

Return an object view by its zero-based configured position.

PARAMETER DESCRIPTION
index

Zero-based position in configured project order.

TYPE: int

RETURNS DESCRIPTION
_T

Generation-bound object view.

RAISES DESCRIPTION
IndexError

If index is outside the configured collection.

TypeError

If index is not a non-boolean integer.