Project#
Project File#
Project File#
- class mhi.xml.pscad.ProjectFile(path: Path | str)#
A PSCAD Project (Library or Case)
- property version_number: tuple[int, ...]#
The PSCAD project file version number tuple (read-only)
Added in version 1.4.0.
- property namespace: str#
Namespace of the project
Read-only if the project is a case; read-write if the project is a library.
- classmethod create(path: Path | str, *, version: str = '5.0.2', overwrite: bool = False) ProjectFile#
Create a new PSCAD Library (
*.pslx) or Project Case (*.pscx)Changed in version 1.4.0: Added
version&overwriteparameters
- save()#
Write the updated XML document back to the file it was read from.
- save_as(path: Path | str) None#
Write the project’s XML document to a new location.
Updates the
ProjectFile.pathproperty. If written as a .pscx file, thenamespaceproperty is updated to keep the filename and namespace in sync.
- property definition: DefinitionMapping#
The project’s
Definitionmapping.Example:
for defn_name in project.definition: print(defn_name) main_defn = project.definition['Main'] del project.definition['not_needed']
- property substitution_set: SubstitutionSetMapping#
The global substitution set mapping.
This is a dictionary of global substitution sets, where each set is a dictionary of substitution variables and the value which will replace them.
Example:
# Create new substitution sets euro_ss = project.substitution_set.create_set('Euro') project.substitution_set.create_sets('Asia', 'Africa') # Set initial (default) global substitutions default_ss = project.substitution_set['Default'] default_ss['BaseKV'] = '230.0 [kV]' default_ss['Freq'] = '60.0 [Hz]' # Override 'Freq' in 'Euro' substitution set euro['Freq'] = '50.0 [Hz]' # Set the project's current global substitution set project.substitution_set.current = 'Euro' # Delete a global substitution set del project.substitution_set['Africa']
- property layer: LayerMapping#
The project’s Layer mapping.
Examples:
layer_1 = project.layer.create('Layer1') layer_1.state = 'Invisible' layer_2 = project.layer.create('Layer2') layer_2.state = 'Disabled' layer_2.parameters.disabled_color = 0xAA8866
- canvases_in_use() list[Schematic]#
List of canvases in use.
Note
If a module itself has been marked as disabled, the underlying canvas is not in use. If a modules is merely disabled due to being placed on a layer that happens to be disabled, the underlying canvas is still considered to be in use, since the conditions which determine whether or not a layer is disabled are not evaluated here.
- components(name, key=value, ...) Iterable[Component]#
Component search
Find the components within the project identified by the provided arguments. All arguments are optional. The name parameter, if given, must be the first and only positional parameter. All other parameters must be keyword parameters.
- Parameters:
name (str) – Name of the component (positional parameter only)
classid (str) – Component class identifier
defn (str) – Definition name
include_defns (set[str]) – Definition names to include in search
exclude_defns (set[str]) – Definition names to exclude from search
canvases_in_use_only (bool) – Ignore non-instanciated canvases (default: False)
with_params (set[str]) – Only components with have the given parameters
key=value – Components with the given parameter key=value pairs
At most one of defn, include_defns or exclude_defns may be provided.
- component(name, key=value, ...) Component | None#
Component search
Find the component within the project identified by the provided arguments. All arguments are optional. The name parameter, if given, must be the first and only positional parameter. All other parameters must be keyword parameters.
- Parameters:
name (str) – Name of the component (positional parameter only)
classid (str) – Component class identifier
defn (str) – Definition name
include_defns (set[str]) – Definition names to include in search
exclude_defns (set[str]) – Definition names to exclude from search
canvases_in_use_only (bool) – Ignore non-instanciated canvases (default: False)
raise_if_not_found (bool) – Raise an exception if component isn’t found (default: False)
raise_if_multiple_found (bool) – Raise exception if multiple are found. (default: False)
with_params (set[str]) – Only components with have the given parameters
key=value – Components with the given parameter key=value pairs
At most one of defn, include_defns or exclude_defns may be provided.
- named_components(*, classid: str | None = None, defn: str | None = None) dict[str, list[Component]]#
Find all named components (of a particular class and/or definition), and return a dictionary of name-to-components.
Note
Multiple components can share the same name, so the returned dictionary will contain a list for each name, even if only one component by that name exists.
- find_by_id(iid: int) Component#
- find_by_id(iid: int, *, raise_if_not_found: Literal[True]) Component
- find_by_id(iid: int, *, raise_if_not_found: bool) Component | None
Find a component by its PSCAD id number
Added in version 1.4.0.
- remap(old: ProjectFile, new: ProjectFile, *definition: str) set[str]#
Replace definition references from one namespace with definition references having the same definition name in another namespace.
If definition names are given, each must exist in both namespaces. If no definition names are given, all common definition names will be used.
Returns definition names remapped from
oldtonew.Raises a
ValueErrorif no common definition names are found, or if any of the given definition names are not common to botholdandnew.Added in version 1.2.0.
- property parameters: Parameters#
The project parameters structure
Project Parameters#
- class Parameters#
Project Parameters
Global Substitutions#
Substitution Set Mapping#
- class mhi.xml.pscad.substitution.SubstitutionSetMapping#
The project’s global substitution set dictionary.
Usage:
# Create new substitution sets euro_ss = project.substitution_set.create_set('Euro') project.substitution_set.create_sets('Asia', 'Africa') # Set initial (default) global substitutions default_ss = project.substitution_set['Default'] default_ss['BaseKV'] = '230.0 [kV]' default_ss['Freq'] = '60.0 [Hz]' # Override 'Freq' in 'Euro' substitution set euro['Freq'] = '50.0 [Hz]' # Set the project's current global substitution set project.substitution_set.current = 'Euro' # Delete a global substitution set del project.substitution_set['Africa']
Schematics#
Schematic#
- class mhi.xml.pscad.Schematic#
A canvas which contains a set of components.
- property definition: Definition#
Definition the schematic is part of
- components(name, key=value, ...) Iterator[Component]#
Component search
Find the components within the canvas identified by the provided arguments. All arguments are optional. The name parameter, if given, must be the first and only positional parameter. All other parameters must be keyword parameters.
- Parameters:
name (str) – Name of the component (positional parameter only)
classid (str) – Component class identifier
defn (str) – Definition name
include_defns (set[str]) – Definition names to include in search
exclude_defns (set[str]) – Definition names to exclude from search
with_params (set[str]) – Only components with have the given parameters
key=value – Components with the given parameter key=value pairs
At most one of defn, include_defns or exclude_defns may be provided.
- component(name, key=value, ...) Component | None#
Component search
Find the component within the canas identified by the provided arguments. All arguments are optional. The name parameter, if given, must be the first and only positional parameter. All other parameters must be keyword parameters.
- Parameters:
name (str) – Name of the component (positional parameter only)
classid (str) – Component class identifier
defn (str) – Definition name
include_defns (set[str]) – Definition names to include in search
exclude_defns (set[str]) – Definition names to exclude from search
raise_if_not_found (bool) – Raise an exception if component isn’t found (default: False)
with_params (set[str]) – Only components with have the given parameters
key=value – Components with the given parameter key=value pairs
At most one of defn, include_defns or exclude_defns may be provided.
- find_by_id(iid: int) Component | None#
- find_by_id(iid: int, *, raise_if_not_found: Literal[True]) Component
- find_by_id(iid: int, *, raise_if_not_found: bool) Component | None
Find a component by its PSCAD id number
Changed in version 1.4.0: added
raise_if_not_found
- add(component, x, y, orient=None) None#
Add a component to the schematic at the given XY location. If an orientation is specified, set that as well.
- property parameters: Parameters#
Retrieve the Schematic’s Parameters
Schematic Parameters#
Layers#
Layer Map#
- class mhi.xml.pscad.layer.LayerMapping#
The project’s
LayerdictionaryExamples:
# Create a layer layer = project.layer.create('Layer1') # Set layer properties layer.state = 'Invisible' layer.parameters.disabled_color = 0xAA8866 layer.parameters.disabled_opacity = 128 layer.parameters.highlight_color = 0x76FF7A layer.parameters.highlight_opacity = 100 # Delete a layer del project.layer['Layer1']
Layer#
- class mhi.xml.pscad.layer.Layer#
A project layer
- property state: str#
The layer’s state.
Possible values are ‘Enabled’, ‘Disabled’, ‘Visible’, or a custom user state.
- set_custom_state(cmp: Component, state_name: str, state: CustomLayerState)#
Set the custom state for the component
Added in version 1.4.0.
- components() Iterator[Component]#
Return all components which belong to the layer.
Added in version 1.2.0.
- property parameters: Parameters#
Retrieve the Layer Parameters object