Scripting > Plotting Basics


Templates

Template files saved interactively from HEC-DSSVue may be applied to plots via scripting.  When saving a template interactively from the plot window via the “Save Template…” entry on the “File” menu, HEC-DSSVue:

  1. Chooses the “My Documents” subdirectory of the directory specified in the USERPROFILE environment variable as the default location for the template file.
  2. Appends “.template” to the end of the specified file name.

The applyTemplate(string filename) G2dDialog method requires the actual file name for the template file.  To apply a template saved in the default directory, the complete template file name must be re-created as demonstrated in the example below.
     

Example: Applying Template Saved in Default Directory

 

import os                                                                                             # for getenv() & sep

from hec.script import *                                                                       # for Plot class

from hec.heclib.dss import *                                                                 # for DSS class

thePlot = Plot.newPlot()                                                                        # create a Plot

dssFile = HecDss.open(“C:/mydb.dss”)                                                  # open the DSS file

flow = dssFile.get(“/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/”)      # read a data set

thePlot.addData(flow)                                                                          # add the data set

thePlot.showPlot()                                                                               # show the plot

templateName = “myTemplate”                                                             # template base name

templateFileName =                            \                                                # re-create the file name

  os.getenv(“userprofile”)                    \

  + os.sep                                          \

  + “My Documents”                          \

  + os.sep                                          \

  + templateName                               \

  + “.template”

thePlot.applyTemplate(templateFileName)                                               # apply the template