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__
__getitem__
Return an object view by case-insensitive configured ID.
| PARAMETER | DESCRIPTION |
|---|---|
|
Object ID as a string or non-boolean integer. |
| RETURNS | DESCRIPTION |
|---|---|
_T
|
Generation-bound object view. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no configured object has the requested ID. |
TypeError
|
If |
__iter__
Return an iterator over object IDs in configured project order.
by_index
Return an object view by its zero-based configured position.
| PARAMETER | DESCRIPTION |
|---|---|
|
Zero-based position in configured project order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_T
|
Generation-bound object view. |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If |
TypeError
|
If |