Follow

How can I calculate weighted average statistics via Grapher automation?

This article contains a Grapher 4 sample script for adding a fit curve to a line/scatter plot and using the Send Keys command to add weighted average statistics.

To run this script:

  1. Copy the script below, or click here to download the BAS file: G4 Weighted Average Weights.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

Sub Main

 Dim GrapherApp As Object
 Set GrapherApp = CreateObject("Grapher.Application")
 GrapherApp.Visible = True

'Add a plot document
 Set Plot = GrapherApp.Documents.Add(grfPlotDoc)

 'Add a graph
 Set Graph = Plot.Shapes.AddLinePlotGraph(GrapherApp.Path+"\samples\sample3.dat")

 'Add a fit curve to the first curve
 Set FitWtgAvg = Graph.Plots(1).AddFit(grfWeightedAvgFit)

 'Select Fit curve -- Must be the only item selected to use the next SendKeys commands
 FitWtgAvg.selected = True

 'Use Send Keys to choose Edit | Properties to open Fit curve dialog
 AppActivate "Grapher"
  'SendKeys "{DoubleClickLeft x,y}"
 SendKeys "%E"
 SendKeys "o"

 'Change Window Width to 3
 SendKeys "3"

 'Tab to Weights button and press Enter
 SendKeys "{Tab}"
 SendKeys"{Enter}"

 'The Weights dialog is open.  Go to first entry, tab to Set Weight button and press Enter
 SendKeys "{Down}"
 SendKeys "{Tab}"
 SendKeys "{Enter}"

 'Set the weight for the first item using SendKeys
 SendKeys "5"
 SendKeys "{Enter}"

 'Go to the second entry, tab to Set Weight button and press Enter
 SendKeys"+{Tab}"	'+ indicates Shift is pressed
 SendKeys "{Down}"
 SendKeys"{Tab}"
 SendKeys "{Enter}"

 'Set the weight for the second item using SendKeys
 SendKeys "2"
 SendKeys "{Enter}"

 'Go to the third entry, tab to Set Weight button and press Enter
 SendKeys"+{Tab}"	'+ indicates Shift is pressed
 SendKeys "{Down}"
 SendKeys"{Tab}"
 SendKeys "{Enter}"

 'Set the weight for the third item using SendKeys
 SendKeys "3"
 SendKeys "{Enter}"

'Close dialog
 SendKeys"{Tab}"
 SendKeys"{Enter}"
 Wait 1
 'Close dialog  SendKeys"{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}"
 SendKeys"{Enter}"


End Sub

 

Updated October 25, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.