Automation Reference - JMP
Automation Reference - JMP
Automation Reference - JMP
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Application Object <strong>Reference</strong> for Automating <strong>JMP</strong><br />
Automating <strong>JMP</strong> through Visual Basic<br />
‘This is the most important part.<br />
‘After the first piece of data has been changed, generate a control chart.<br />
‘After every 5 changes to Excel worksheet cells, generate a new PNG of the Control Chart.<br />
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)<br />
Counter = Counter + 1<br />
‘Save the control chart to a PNG every time 5 elements get updated<br />
If (Counter Mod 5 = 0 Or Counter = 1) Then<br />
‘If the Control Chart has not been created yet, do so<br />
If Not (ChartOpen) Then<br />
Set CChart = <strong>JMP</strong>Doc.CreateControlChart ‘create chart<br />
CChart.LaunchAddProcess "Column 1" ‘Add column<br />
CChart.LaunchAddSampleUnitSize 5<br />
CChart.LaunchSetChartType jmpControlChartVar<br />
CChart.Launch ‘launch the chart<br />
ChartOpen = True 'set flag to remember that a chart is open<br />
End If<br />
CChart.SaveGraphicOutputAs "C:\ControlChart.png", jmpPNG<br />
End If<br />
End Sub<br />
The Workbook_Open subroutine is called when the Excel table is initially loaded. It initializes some variables, starts<br />
<strong>JMP</strong>, and tells <strong>JMP</strong> to open (through ODBC) the same Excel file that is currently loaded into Excel 2007. Note that<br />
<strong>JMP</strong> opens the Excel file as a database object rather than opening it as a file. This is necessary because <strong>JMP</strong> does not<br />
open a file that is already open in another application.<br />
The Workbook_Change event is generated every time a user changes the data in any cell in any worksheet in the<br />
workbook. This sample assumes that there is only one active worksheet in the workbook. The first time the user<br />
changes a cell value in the worksheet, the Workbook_Change subroutine creates a Control Chart in <strong>JMP</strong> using the<br />
current data table.<br />
In this sample, the Workbook_change subroutine also creates a PNG graphic file of the Control Chart output and<br />
updates it on the disk every fifth time a change is made to the workbook. This just gives some ideas on how Excel<br />
events and <strong>JMP</strong> automation can be used together to create output.<br />
Finally, the Workbook_BeforeClose subroutine is invoked when the Excel workbook is closed, but before the<br />
window goes away. The code within this subroutine instructs <strong>JMP</strong> to close down as well.<br />
Note that there are some limitations in this method. This example is good if the only activities that occur with the<br />
data are additions or changes. The Excel Worksheet_Change event is very limited in the reporting that it provides.<br />
In particular, cell-by-cell updating of a <strong>JMP</strong> data table can be difficult in instances where deletion, drag and drop, or<br />
block replication needs support.<br />
If these are problem cases, it is probably better to rely on a brute-force approach. One way is to reload the data into<br />
<strong>JMP</strong> every time a certain number of changes occur. An example is shown here.<br />
Private Sub Workbook_SheetChange(ByVal Sh as Object, ByVal Source as Range)<br />
Counter = Counter + 1<br />
If (Counter Mod 10 = 0) Then<br />
‘If there is a previous chart of Table opened, close it first<br />
If(DocOpen) Then<br />
<strong>JMP</strong>Doc.Close False, ""<br />
CChart.CloseWindow<br />
End If<br />
Set <strong>JMP</strong>Doc = My<strong>JMP</strong>.OpenDocument(InstallDir + "C:\BOOK1.XLS")<br />
Set DT = <strong>JMP</strong>Doc.GetDataTable<br />
Page 7