------------------
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:

.. literalinclude:: step-10.py
	:end-at: enerplot.silence

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:

.. literalinclude:: step-10.py
	:start-at: new_workspace
	:end-at: 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:

.. literalinclude:: step-10.py
	:start-at: load_datafiles
	:end-at: load_datafiles

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:

.. literalinclude:: step-10.py
	:start-at: enerplot.book
	:end-at: gf.position

* 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:

.. literalinclude:: step-10.py
	:start-at: gf.extents
	:end-at: gf.properties

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:

.. literalinclude:: step-10.py
	:start-at: gf.panel
	:end-at: graph.properties

* 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:

.. literalinclude:: step-10.py
	:start-at: enerplot.datafile
	:end-at: 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:

.. literalinclude:: step-10.py
	:start-at: graph.zoom
	:end-at: graph.zoom
  

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:

.. literalinclude:: step-10.py
	:start-at: add_overlay_graph
	:end-at: graph2.properties

* 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:

.. literalinclude:: step-10.py
	:start-at: save_as
	:end-at: save_workspace_as

Save the Script
===============

Finally, ensure the script is saved.

* Right click on the "script_demo.py" node, and select "Save"

The final :download:`script <step-10.py>` will look similar to the following:

.. literalinclude:: step-10.py


