## scenarios.ScenarioCollection


Collection-like access to scenarios in the database.


Usage

``` python
scenarios.ScenarioCollection(scenario_manager)
```


## Attributes


`active: Scenario`  
Currently active scenario

`base: Scenario`  
Base scenario


## Examples

``` python
>>> # Create a new scenario
>>> new_scenario = db.scenarios.create("Future Development")
>>>
>>> # Access by ID
>>> scenario = db.scenarios[new_scenario.id]
>>>
>>> # Get the active scenario
>>> active = db.scenarios.active
```


## Attributes

| Name | Description |
|----|----|
| [active](#active) | Currently active scenario. |
| [base](#base) | Base scenario. |

------------------------------------------------------------------------


#### active


Currently active scenario.


`active: Scenario`


------------------------------------------------------------------------


#### base


Base scenario.


`base: Scenario`


## Methods

| Name | Description |
|----|----|
| [__getitem__()](#__getitem__) | Access scenario by its ID. |
| [__init__()](#__init__) | ScenarioCollection constructor. |
| [__iter__()](#__iter__) | Iterate through all scenarios, parents before their children. |
| [__repr__()](#__repr__) | Get string representation of the ScenarioCollection object. |
| [by_name()](#by_name) | Find a scenario by name (returns the first match if multiple exist). |
| [create()](#create) | Create a new scenario, optionally as a child of another. |
| [delete()](#delete) | Delete a scenario by object or id. |
| [find_by_id()](#find_by_id) | Find a scenario by its exact ID (returns single item or None). |
| [find_by_name()](#find_by_name) | Find all scenarios with the given name; MIKE+ allows duplicates. |

------------------------------------------------------------------------


#### \_\_getitem\_\_()


Access scenario by its ID.


Usage

``` python
__getitem__(id)
```


##### Returns


`Scenario`  
The scenario with the given ID.


##### Raises


`KeyError`  
If no scenario matches the given ID


------------------------------------------------------------------------


#### \_\_init\_\_()


ScenarioCollection constructor.


Usage

``` python
__init__(scenario_manager)
```


##### Parameters


`scenario_manager: IScenarioManager`  
The underlying .NET scenario manager object


------------------------------------------------------------------------


#### \_\_iter\_\_()


Iterate through all scenarios, parents before their children.


Usage

``` python
__iter__()
```


------------------------------------------------------------------------


#### \_\_repr\_\_()


Get string representation of the ScenarioCollection object.


Usage

``` python
__repr__()
```


##### Returns


`str`  
The class name and the number of scenarios.


------------------------------------------------------------------------


#### by_name()


Find a scenario by name (returns the first match if multiple exist).


Usage

``` python
by_name(name)
```


##### Parameters


`name: str`  
The name of the scenario to find


##### Returns


`Scenario or None`  
The first scenario that matches the given name, or None if no match is found


------------------------------------------------------------------------


#### create()


Create a new scenario, optionally as a child of another.


Usage

``` python
create(name, parent=None)
```


##### Parameters


`name: str`  
Name for the new scenario

`parent: Scenario = None`  
Parent scenario (defaults to base scenario if None)


##### Returns


`Scenario`  
The new scenario.


##### Raises


`ValueError`  
If the scenario could not be created


------------------------------------------------------------------------


#### delete()


Delete a scenario by object or id.


Usage

``` python
delete(scenario)
```


##### Parameters


`scenario: Scenario or str`  
The scenario to delete (can be a Scenario object or its ID). Its child scenarios are deleted with it.


##### Raises


`ValueError`  
If the scenario could not be deleted

`KeyError`  
If the scenario does not exist


------------------------------------------------------------------------


#### find_by_id()


Find a scenario by its exact ID (returns single item or None).


Usage

``` python
find_by_id(id)
```


##### Parameters


`id: str`  
The ID of the scenario to find


##### Returns


`Scenario or None`  
The scenario with the given ID, or None if no scenario with that ID exists


------------------------------------------------------------------------


#### find_by_name()


Find all scenarios with the given name; MIKE+ allows duplicates.


Usage

``` python
find_by_name(name)
```


##### Parameters


`name: str`  
The name of the scenario to find


##### Returns


`list[Scenario]`  
The scenarios with the given name, or an empty list if none match
