Project#
Project File#
- class mhi.xml.pscad.ProjectFile(path: Path | str)#
A PSCAD Project (Library or Case)
- property namespace: str#
Namespace of the project
Read-only if the project is a case; read-write if the project is a library.
- 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.
- 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
- class Parameters#
Project Parameters
Global Substitutions#
- 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']
Definitions#
Definition Map#
- class mhi.xml.pscad.definitions.DefinitionMapping#
The project’s
Definitiondictionary.Example:
for defn_name in project.definition: print(defn_name) main_defn = project.definition['Main'] del project.definition['not_needed']
- create(name: str) UserCmpDefn#
Create a new UserCmp Definition
Definition#
- class mhi.xml.pscad.Definition#
Definition node
- property group: str#
A comma separated list of groups this definition belongs to.
Examples:
'(null)' 'Miscellaneous,I/O Devices' 'Meters,Breakers Faults,Machines,Miscellaneous'
Form#
- class mhi.xml.pscad.Form#
A collection of categories of parameters, along with their descriptions and validity constraints.
Examples:
form = definition.form # Create a "Extra" category, add 'Author', 'Version' parameters. extra = form.category.create("Extra") extra.add_text('Author', "Creator") extra.add_integer('Version', "Revision number", min=1, default=1) # Remove the "Extra" category del form.category["Extra"]
- property w: int#
Width of the dialog form, in pixels.
Does not include additional width added by dynamic help.
- property category: KeyMapping[Category]#
Form category dictionary
- property parameter: KeyMapping[Parameter]#
Form parameter dictionary
Form Category#
- class mhi.xml.pscad.Category#
A form category
Contains 1 or more parameters, and a condition for when the category is enabled.
- property cond#
Category enabled condition expression (read/write)
- property parameter: KeyMapping[Parameter]#
Category parameter dictionary
- add_text(name: str, description: str, default: str = '', empty_allowed=True, **kwargs) Parameter#
Create a text parameter.
Form Parameter#
- class mhi.xml.pscad.Parameter#
A parameter definition.
Gives the parameter a symbol name, description, type, units, default value, validation attributes (minimum and/or maximum limits, regex), and help attributes.
Graphics#
- class mhi.xml.pscad.Graphics#
A <graphics/> container node
- add_text(*coords, text: str, color: str = 'Black', full_font: str = 'Tahoma, 12world', font_size: int = 0, align: str | Align | int = Align.CENTER, angle: int = 0, cond: str = 'true')#
Add a line of text to the definition graphics
- add_line(*coords, color: str = 'Black', line_style: str | LineStyle | int = LineStyle.SOLID, thickness: int = 0, port: str = '', cond: str = 'true')#
Add a line to the definition graphics
- add_rect(*coords, color: str = 'Black', line_style: str | LineStyle | int = LineStyle.SOLID, thickness: int = 0, port: str = '', fill_style: str | FillStyle | int = FillStyle.HOLLOW, fill_fg: str = 'Black', fill_bg: str = 'White', cond: str = 'true')#
Add a rectangle to the definition graphics
- add_ellipse(*coords, color: str = 'Black', line_style: str | LineStyle | int = LineStyle.SOLID, thickness: int = 0, port: str = '', fill_style: str | FillStyle | int = FillStyle.HOLLOW, fill_fg: str = 'Black', fill_bg: str = 'White', cond: str = 'true')#
Add an ellipse to the definition graphics
- add_circle(*coords, color: str = 'Black', line_style: str | LineStyle | int = LineStyle.SOLID, thickness: int = 0, port: str = '', fill_style: str | FillStyle | int = FillStyle.HOLLOW, fill_fg: str = 'Black', fill_bg: str = 'White', cond: str = 'true')#
Add a circle to the definition graphics
- ports(name: str | None = None) list[Port]#
Retrieve the list of ports defined in the component graphics
- add_input(x: int, y: int, name: str, *, dim: int = 1, cond: str = 'true', internal: bool = False, datatype: SignalType | str | int = SignalType.REAL) Port#
Add an input port to the graphic definition
Graphic Elements#
- class mhi.xml.pscad.GfxText#
Gfx Text
- property color: Colour#
The ‘color’ property of a visible Gfx item
- class mhi.xml.pscad.GfxLine#
Gfx Line
- property color: Colour#
The ‘color’ property of a visible Gfx item
- class mhi.xml.pscad.GfxRectangle#
Gfx Rectangle
- property color: Colour#
The ‘color’ property of a visible Gfx item
- property fill_fg: Colour#
The ‘Foreground color’ of a painted Gfx item
- property fill_bg: Colour#
The ‘Background Color’ of a painted Gfx item
- class mhi.xml.pscad.GfxEllipse#
Gfx Ellipse
- property color: Colour#
The ‘color’ property of a visible Gfx item
- property fill_fg: Colour#
The ‘Foreground color’ of a painted Gfx item
- property fill_bg: Colour#
The ‘Background Color’ of a painted Gfx item
- class mhi.xml.pscad.Port#
Graphics Port
- property datatype: SignalType#
The ‘data type’ of input/output Port (Logical, Integer, Real, …)
- property electype: ElectricalType#
The ‘type’ of an Electrical Port (Fixed, Removable, Ground, …)
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.
- 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#
- class Schematic.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.
- 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
Layer Parameters#
Components#
Component#
- class mhi.xml.pscad.Component#
A Component
- property classid: str#
The classid of the component.
Typically “UserCmp” but other possibilities include “WireOthogonal”, “Sticky”, “GraphFrame”, “ControlFrame”, and so on.
- property scope_and_defn: tuple[str, str]#
Returns the component definitions’s scope and definition names.
- property name: str | None#
Returns the component’s assigned name value.
The name must be stored in a parameter called name, `Name or NAME.
- property params: ParamListNode | None#
The parameter list node of the component
Individual parameters can be set and retrieved using index notation:
name = cmp['Name'] cmp['BaseKV'] = '230.0 [kV]'
- property enabled: bool#
Is this component enabled.
Note
This does not check if the component is on a disabled layer.
UserCmp#
- class mhi.xml.pscad.UserCmp#
A component with a definition defined in a ‘.pslx’ file
Wires#
Utility Classes#
Vertex#
XY#
Enum Types#
Resources#
Ports#
- class mhi.xml.pscad.NodeType(*values)#
Node Input/Output/Electrical Type
- UNKNOWN = '0'#
- INPUT = '1'#
- OUTPUT = '2'#
- ELECTRICAL = '3'#
- SHORT = '4'#
Graphics#
- class mhi.xml.pscad.LineStyle(*values)#
Line Styles
- SOLID = '0'#
- DASH = '1'#
- DOT = '2'#
- DASHDOT = '3'#
- class mhi.xml.pscad.FillStyle(*values)#
Fill Styles
- HOLLOW = '0'#
- SOLID = '1'#
- BACKWARD_DIAGONAL = '2'#
- FORWARD_DIAGONAL = '3'#
- CROSS = '4'#
- DIAGONAL_CROSS = '5'#
- HORIZONTAL = '6'#
- VERTICAL = '7'#
- GRADIENT_HORZ = '8'#
- GRADIENT_VERT = '9'#
- GRADIENT_BACK_DIAG = '10'#
- GRADIENT_FORE_DIAG = '11'#
- GRADIENT_RADIAL = '12'#