Recording a Script

Instead of writing scripts by hand, a script can be recorded.

  • Select “New Workspace” from the application menu or the toolbar button to begin with a clean workspace.
  • Right-click on the “Scripts” node, and select “New Script…”.
  • Enter “script_demo” for the script name, and select “Ok” to create the script.
  • Double click on the “script_demo.py” node to open the script in the “Scripts” pane.

The “Scripts” pane should display the beginnings of a automation script:

#!/usr/bin/env python3
import mhi.enerplot

with mhi.enerplot.application() as enerplot:
    enerplot.silence = True

A New Workspace

Press the “Record” button in the “Scripts” pane to begin recording user actions.

  • Select “New Workspace” again, to record the action of creating a new workspace in the script. Say “No” if asked to save any changes in the workspace.

The following command will be added to the script:

    enerplot.new_workspace()

Add a Datafile

  • From the workspace “Data” node, select “Load Dataset from File”.

  • Navigate to the CSV folder in Enerplot’s Examples DataFiles directory

    • C:\Users\Public\Enerplot\1.0.0\Examples\DataFiles\CSV_Files

    and select the “Cigre_47.csv” file.

  • Select “Open” to load the datafile.

The following command will be added to the script:

    enerplot.load_datafiles('C:\\Users\\Public\\Documents\\Enerplot\\1.0.0\\Examples\\DataFiles\\CSV_Files\\Cigre_47.csv', load_data=True)

Add a Graph Frame

  • From the Component’s tab on the application ribbon, select “Graph Pane”.
  • Drop the Graph Pane near the top-left corner of the “Sheet1” canvas.

Something similar to the following commands will be added to the script:

    untitled = enerplot.book('Untitled')
    sheet1 = untitled.sheet('Sheet1')
    gf = sheet1.graph_frame()
    gf.position(1, 1)
  • The first command retrieves a reference to the “Untitled” book, and stores it in a local variable untitled.
  • The second command retrieves a reference to the “Sheet1” in that book, and stores it in a local variable called sheet1.
  • The third command creates a graph frame on the sheet, with the default size and position, and stores a reference to it in the variable gf.
  • The forth command changes the position of the graph frame to be 1,1, which is one grid unit from top and left edges of the sheet.

The variables names untitled and sheet1 were generated from the names of the book and the sheet. The graph frame does not have a name, so a default name of gf was used.

Frame Properties

  • Select the graph frame’s title bar, to show the 8 control points.
  • Drag the lower right corner down, and to the right to make the graph frame larger.
  • Right click on the graph frame, and select “Edit Properties…”
    • Change the Caption to “Rectifier AC Voltage”
    • Press “Ok”

The following commands are added to the script:

    gf.extents(1, 1, 45, 32)
    gf.properties(title="Rectifier AC Voltage")

Graph Properties

  • Right click on the top graph in the frame and select “Edit Properties…”
    • Change the Y-Axis Title to “Phase Voltages (kV)”
    • Press “Ok”

The following commands are added to the script:

    graph = gf.panel(0)
    graph.properties(title="Phase Voltages (kV)")
  • The first command obtains a reference to the first (0-indexed) graph in the graph frame, and stores it in a local variable graph.
  • The second command gives a title the graph.

Adding Curves

  • Expand the “Cigre_47.csv” node, and expand the “Non-grouped” node beneath that.
  • Select the “Rectifier\AC Voltage:1” channel node.
  • Hold down the “Control” key and drag that channel node to the graph.
  • Repeat with “AC Voltage:2” and “AC Voltage:3”

The following commands will have been added to the script:

    cigre_47 = enerplot.datafile('Cigre_47.csv')
    rectifier_ac_voltage_1 = cigre_47.channel('Rectifier\\AC Voltage:1')
    graph.add_curves(rectifier_ac_voltage_1)
    rectifier_ac_voltage_2 = cigre_47.channel('Rectifier\\AC Voltage:2')
    graph.add_curves(rectifier_ac_voltage_2)
    rectifier_ac_voltage_3 = cigre_47.channel('Rectifier\\AC Voltage:3')
    graph.add_curves(rectifier_ac_voltage_3)
  • The first command obtains a reference to the data file which was loaded above.
  • The second command obtains a reference to the “Rectifier\AC Voltage:1” channel, and
  • the third command adds that channel reference to the graph.
  • The remaining commands repeat this for the other two channels.

Zoom the Graph

  • Drag the mouse from near the top-left corner of the graph to just below the x-axis, and just before the 0.2 point on the x-axis.

Something similar to the following command will be added to the script:

    graph.zoom(xmin=0, xmax=0.2, ymin=-0.2, ymax=1.2)

Additional Graphs

Later, we will be computing the zero sequence voltage, and adding that to the graph. We can’t record the calculation of the zero sequence voltage - that will add to the script by hand - but we can create the area where this will be stored.

  • Right-click on the title bar, and select “Add Overlay Graph (Analog)”, or press the “Ins” key.
  • Right click on this new graph and select “Edit Properties…”
    • Change the Y-Axis Title to “Zero Sequence Voltage (V)”
    • Press “Ok”

The following commands are added to the script:

    graph2 = gf.add_overlay_graph()
    graph2.properties(title="Zero Sequence Voltage (V)", gridvalue=0.200000, yintervalue=0.000000, ymin="-1", ymax=1)
  • The first command adds the additional graph to the graph frame. The returned reference is stored in the variable graph2, since graph is already in use.
  • The second command gives a title this new graph.

Save the Workspace

Finally, we need to save our work.

  • Right click on the “Untitled” under the workspace’s Books node,
    • Select “Save As…”,
    • Navigate to your “Documents” directory,
    • Use the filename “ScriptDemo.epbx”
    • Press the “Save” button
  • Right click on the top level workspace node, * Select “Save As…”, * Navigate to your “Documents” directory, * Use the filename “ScriptDemo.epwx” * Press the “Save” button

These final commands are added to the script:

    untitled.save_as('C:\\Users\\aneufeld\\Documents\\ScriptDemo.epbx')
    enerplot.save_workspace_as('C:\\Users\\aneufeld\\Documents\\ScriptDemo.epwx', save_projects=False)

Save the Script

Finally, ensure the script is saved.

  • Right click on the “script_demo.py” node, and select “Save”

The final script will look similar to the following:

#!/usr/bin/env python3
import mhi.enerplot

with mhi.enerplot.application() as enerplot:
    enerplot.silence = True


    enerplot.new_workspace()
    enerplot.load_datafiles('C:\\Users\\Public\\Documents\\Enerplot\\1.0.0\\Examples\\DataFiles\\CSV_Files\\Cigre_47.csv', load_data=True)
    untitled = enerplot.book('Untitled')
    sheet1 = untitled.sheet('Sheet1')
    gf = sheet1.graph_frame()
    gf.position(1, 1)
    gf.extents(1, 1, 45, 32)
    gf.properties(title="Rectifier AC Voltage")
    graph = gf.panel(0)
    graph.properties(title="Phase Voltages (kV)")
    cigre_47 = enerplot.datafile('Cigre_47.csv')
    rectifier_ac_voltage_1 = cigre_47.channel('Rectifier\\AC Voltage:1')
    graph.add_curves(rectifier_ac_voltage_1)
    rectifier_ac_voltage_2 = cigre_47.channel('Rectifier\\AC Voltage:2')
    graph.add_curves(rectifier_ac_voltage_2)
    rectifier_ac_voltage_3 = cigre_47.channel('Rectifier\\AC Voltage:3')
    graph.add_curves(rectifier_ac_voltage_3)
    graph.zoom(xmin=0, xmax=0.2, ymin=-0.2, ymax=1.2)
    graph2 = gf.add_overlay_graph()
    graph2.properties(title="Zero Sequence Voltage (V)", gridvalue=0.200000, yintervalue=0.000000, ymin="-1", ymax=1)
    untitled.save_as('C:\\Users\\aneufeld\\Documents\\ScriptDemo.epbx')
    enerplot.save_workspace_as('C:\\Users\\aneufeld\\Documents\\ScriptDemo.epwx', save_projects=False)