Follow

How can I use Grapher automation to set the weights for my weighted average fit curve?

This article contains a sample script for setting the weights for a weighted average fit curve. It works in Grapher 5 and beyond.

To run this script:

  1. Copy the script below, or click here to download the BAS file: 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 plot window
  Set Plot = GrapherApp.Documents.Add(grfPlotDoc)
  'Add graph
  Set LineGraph = Plot.Shapes.AddLinePlotGraph(GrapherApp.Path+"\samples\sample3.dat")
  'Set LinePlot to the line plot object
  Set LinePlot = LineGraph.Plots.Item(1)
  'Add fit
  LinePlot.AddFit(grfWeightedAvgFit)
  'Set LineFit to the fit curve object
  Set LineFit = LinePlot.Fits.Item(1)

  'Set the LineFit options -- for weighted fit, this is the window width
  LineFit.Option = 3

  'Select the fit curve
  LineFit.selected = True

  'Linefit weighted fits -- how to set the weights in G5 through PI
   AppActivate "Grapher"
   SendKeys "%{Enter}"       	'activates PI
   SendKeys "{Left}"           	'insure Plot section Is closed
   SendKeys "{Right}"          	'expand Plot section
   SendKeys "{Down}"         	'move selection down To Weights Dialog control
   SendKeys "{Down}"
   SendKeys "{Down}"
   SendKeys "{Enter}"         	'bring up Weights Dialog

    '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}"


End Sub

 

Updated October 28, 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.