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) '---- Grapher 14 and newer support using the commands below. ---- LineFit.Option = 5 LineFit.SetWeight(1,1) 'Sets the order 1 weight to 1 LineFit.SetWeight(2,1) 'Sets the order 2 weight to 1 LineFit.SetWeight(3,2) 'Sets the order 3 weight to 2 LineFit.SetWeight(4,2) 'Sets the order 4 weight to 2 LineFit.SetWeight(5,1) 'Sets the order 5 weight to 1 '----- Graphern 13 and older use SendKeys to set the weight parameters---- '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