7.4 KiB
GraphPad Prism Script Examples
Overview
Seven examples demonstrating scripting use cases: repeated imports, Monte Carlo analysis, multi-file consolidation, template workflows, embedded data, multi-table operations, and batch graph formatting.
Example 1: Repeatedly Import Data
Use case: Import multiple data files sequentially into separate tables.
Key commands:
GoTo D, N- Navigate to data table NImport filename.txt- Import external file- Manual repetition of commands for each file/table
Workflow:
- Navigate to target table
- Import file
- Repeat for each additional file
Limitation: No loop construct in this basic example; requires explicit command repetition.
Example 2: Monte Carlo Analysis
Use case: Perform iterative simulations with randomization.
Key commands:
ForEach N- Loop N timesGoTo R, N- Navigate to results table NAnalyzeData- Execute analysisNext- End loop iteration
Workflow:
- Set up analysis on initial data
- Loop through iterations:
- Generate random data variation
- Execute analysis
- Store results in indexed table
- Aggregate results across iterations
Pattern:
ForEach 100
GoTo R, %N
AnalyzeData
Next
Variable: %N holds current iteration number (1-based).
Example 3: Import Several Files onto One Table
Use case: Consolidate multiple data files into columns of single table.
Key commands:
GoTo D, 1- Navigate to data table 1Import filename.txt, column=N- Import into specific column N- Column parameter specifies destination
Workflow:
- Navigate to target table
- Import first file to column 1
- Import subsequent files to columns 2, 3, etc.
Syntax: Import Data1.txt, column=1
Note: Files must have compatible row structure.
Example 4: Open Template and Import Data
Use case: Automate data import into pre-configured analysis template.
Key commands:
Open template.pzfx- Load template fileGoTo D, 1- Navigate to data tableImport datafile.txt- Import dataSaveAs output.pzfx- Save populated file
Workflow:
- Open template with pre-configured graphs/analyses
- Navigate to data table
- Import new data
- Save as new file (preserves template)
Advantage: Template contains all formatting, analysis settings, and graph configurations.
Example 5: Import Data and Info Constants from Script File
Use case: Embed data and metadata directly in script (no external files).
Key commands:
<DATA>...</DATA>- Data block delimiterInsertData N, M- Insert data block N starting at column MSetInfo constant_name, value- Set info constant
Data block syntax:
<DATA>
value1\tvalue2\tvalue3
value4\tvalue5\tvalue6
</DATA>
Info constant syntax:
SetInfo Experiment, "Drug Study A"
SetInfo Date, "2024-01-15"
SetInfo Concentration, 10.5
Workflow:
- Define data blocks in script using
<DATA>tags - Navigate to target table:
GoTo D, 1 - Insert data:
InsertData 1, 0(block 1, starting column 0) - Navigate to info table:
GoTo I, 2 - Set info constants with name/value pairs
Data format: Tab-delimited values within DATA tags, numbered sequentially (1-based).
Info types: String (quoted), numeric (unquoted), date (quoted).
Example 6: Import Data into Several Tables
Use case: Batch import multiple files into multiple tables using loop.
Prerequisites: Prism file with N data tables, each linked to graph, all graphs on one layout.
Key commands:
ForEach N- Loop N timesGoTo %N- Navigate to table using iteration variableImport Data%N.txt- Dynamic filename with variable substitutionNext- End loopGoTo L, 1- Navigate to layoutPrint- Print layout
Script pattern:
GoTo D
ForEach 9
GoTo %N
Import Data%N.txt
Next
GoTo L, 1
Print
Variable substitution: %N replaced with current iteration number (1, 2, 3, ..., 9).
Dynamic filenames: Data1.txt, Data2.txt, ..., Data9.txt matched to tables 1-9.
Result: All tables populated, layout printed with all graphs updated.
Example 7: Changing X-Axis Title of All Graphs
Use case: Apply uniform formatting change across all graphs in file.
Key commands:
GoTo G- Navigate to graphs familyForEachSheet- Iterate over all sheets in current familySetAxisTitle axis, "title"- Set axis titleNext- End loop
Script pattern:
GoTo G
ForEachSheet
SetAxisTitle X, "Time (minutes)"
Next
Axis parameter: X (X-axis), Y (Y-axis), Y2 (secondary Y-axis).
Scope: Operates on all graph sheets in current family.
Alternative axes: SetAxisTitle Y, "Response (units)" for Y-axis.
Common Scripting Patterns
Loop Constructs
ForEach N/Next- Fixed iteration countForEachSheet/Next- Iterate over sheets in family%Nvariable - Current iteration number (1-based)
Navigation
GoTo family, N- Navigate to specific sheetD, N- Data table NR, N- Results table NG, N- Graph NI, N- Info table NL, N- Layout N
GoTo family- Navigate to family without specific sheetGoTo %N- Navigate using iteration variable
Data Operations
Import filename.txt- Import external fileImport filename.txt, column=N- Import to specific columnInsertData N, M- Insert embedded data block N at column M<DATA>...</DATA>- Embed data in script (tab-delimited)
Info Constants
SetInfo name, value- Set named constant- String values: quoted
- Numeric values: unquoted
File Operations
Open filename.pzfx- Load Prism fileSaveAs filename.pzfx- Save with new name
Analysis and Output
AnalyzeData- Execute analysisPrint- Print current sheet/layout
Variable Substitution
%N - Current iteration number in loops
- Use in navigation:
GoTo %N - Use in filenames:
Import Data%N.txt - Use in any string context requiring iteration number
- 1-based indexing (first iteration = 1)
Data Formats
External files: Tab-delimited or comma-delimited text files.
Embedded data: Tab-delimited within <DATA> tags, multiple blocks numbered sequentially.
Info constants: Name/value pairs, supports strings (quoted), numbers (unquoted), dates (quoted).
Script Structure Best Practices
- Navigate before operating: Always
GoTotarget before import/analysis - Use loops for repetitive operations:
ForEachwith%Nvariable - Embed small datasets: Use
<DATA>blocks for portability - Template workflows: Separate data from analysis configuration
- Batch operations: Combine loops with variable substitution for file series
- Layout printing: Navigate to layout after updating all graphs
Limitations and Notes
- No automatic file discovery: Must specify exact filenames or use predictable naming pattern
- Fixed iteration counts:
ForEach Nrequires known count, no dynamic termination - Sequential execution: No parallel processing
- Column compatibility: Multi-file imports require matching row structures
- Variable scope:
%Nonly valid within loop construct - 1-based indexing: All sheet numbers, iteration counts, and data blocks start at 1