7.5 KiB
GraphPad Prism Scripts - Overview & Running Scripts
What are Prism Scripts?
Purpose: Automate analysis of multiple files or perform Monte Carlo simulations. Scripts (.pzc files) can open/close Prism files, import data, export/print results and graphs.
Key Limitation: Scripts do NOT control how Prism analyzes or graphs data - that's defined in the Prism project file. Scripts only import data, specify which results to export/print, and manage file operations.
Automation Built-in: Prism links data→graphs→analyses. Editing/replacing data or info constants auto-updates everything (analyses, graphs, paste-linked data). Scripts extend this for batch processing.
Skill Level: Creating scripts slightly harder than using Prism. Scripting/macro language experience helpful but not required.
Alternatives to Scripting
PZFX File Format: Other programs can manipulate Prism files without scripts:
- Prism saves project files in PZFX format (plain text XML)
- Analysis/graphing sections encrypted, but data/info tables are plain XML
- External programs can:
- Open PZFX file with text editor
- Edit/replace data and info constants in XML
- Resave file
- When user opens in Prism, graphs/analyses auto-update
Workflow:
- Create Prism file with desired analysis/graphs
- Save as PZFX
- Open in text editor - see encrypted analysis + plain XML data
- Edit XML data
- Resave
- Open in Prism - updates automatically
Advantages: Cross-platform, no need for simultaneous execution, simpler for some use cases.
Running Scripts from Prism (Development/Testing)
Access: Prism button → File menu → Run Script
Creating New Script:
- Choose "Run Script"
- Select "New Script"
- Choose blank screen or copy existing script
- Edit script in left pane, view syntax reference in right pane
- Test with "1 step" button (step through line-by-line)
- Use "12 steps" for batch testing
- Click "Run" when ready - Prism and dialog minimize during execution
Editing Existing Script:
- Choose "Run Script"
- Select from script list OR "Open Script file" for external file
- Follow steps 4-7 above
Running Scripts on Mac (Automator, MacScript, AppleScript)
Automator (OSX 10.4+)
- Prism installs Automator Action for script launching
- Input: File containing script OR script text
- Output: "Done" or error message
MacScript (from Microsoft Office VBA)
Launch syntax:
MacScript "tell application ""HD:Prism4:Prism""" + Chr(13) + _
"activate" + Chr(13) + _
"open file ""Macintosh HD:Prism4:Scripts:dr2""" + Chr(13) + _
"end tell"
Synchronization Pattern (VBA doesn't wait for Prism):
- Prism script creates completion file:
OpenOutput "done.txt" WText "done" CloseOutput - VBA deletes done.txt before launching Prism
- VBA loops until done.txt exists:
Do Until Dir$("HD:prism 5:done.txt") > "" Application.Wait Now + TimeValue("00:00:1") Loop - VBA quits Prism:
MacScript "tell application ""HD:Prism4:Prism""" + Chr(13) + _ "quit" + Chr(13) + _ "end tell"
AppleScript
HFS Path Example:
tell application "HD:Applications:Prism4 Folder:Prism"
activate
open file "HD:P4scripts:DR2.pzc"
end tell
POSIX Path Example:
tell application "HD:Applications:Prism4 Folder:Prism"
activate
open POSIX file "/P4scripts/DR2.pzc"
end tell
Note: POSIX paths use slashes (not colons), must start with /.
Running Scripts on Windows
Desktop Shortcut
Syntax:
"C:\PRISM5\PRISM.EXE" @"C:\PROGRAM FILES\PRISM 6\SCRIPTS\DOIT.PZC"
- Use
@symbol before script path - Quote paths containing spaces
Shell Command (from VBA/other programs)
Basic syntax:
Shell ("C:\prism 5\prism.exe @C:\prism 6\dr2.pzc")
Behavior:
- Prism runs invisibly
- Shell returns immediately (doesn't wait for completion)
Synchronization Pattern (same as Mac):
- Prism script creates done.txt:
OpenOutput "done.txt" WText "done" CloseOutput - VBA deletes done.txt, launches Prism, then loops:
Do Until Dir$("C:\prism 6\done.txt") > "" Application.Wait Now + TimeValue("00:00:1") Loop
OLE/ActiveX Automation
Full example:
Set Prism = CreateObject("Prism.command")
Prism.SetPath ("C:\data\july99")
Prism.visible
Prism.runcommand ("c:\prism5\doseresp.pzc")
Prism.quit
Set Prism = Nothing
Commands:
CreateObject("Prism.command")- Creates Prism object (Windows finds prism.exe via registry)SetPath (path)- Optional, sets working directory for data files/templatesvisible- Shows progress dialog (remove for invisible operation)runcommand (scriptpath)- Launches script (requires full path)quit- Exits Prism
Advantages over Shell:
- Sequential execution - VBA waits for Prism completion (no synchronization file needed)
- Can set working directory without modifying script
Intranet Launch (Batch File)
Create StartPrism.bat:
Call "N:\Program Files\PRISM5\PRISM.EXE" -OC:\WINDOWS\prism5.cnf
OR:
Call F:\Prism\Prism.exe @"F:\PRISM\PRISMSCRIPTS\DOIT.PZC"
HTML link: Link text to StartPrism.bat file.
Excel Integration
Export Excel Data to CSV (VBA)
Open "C:\data\july97\dr2.csv" For Output As #1
For I = 1 To 12
For J = 1 to 6
Print #1, Worksheets(1).Cells(I,J).Value; ",";
Next
Write #1,
Next
Close #1
Note: Exporting to CSV faster than opening Excel files directly from Prism.
Generate PZC File from Excel (VBA)
Open "C:\Prism4\auto.pzc" For Output As #1
Print #1, "Shortlog"
Print #1, "SetPath C:\gp\prism25\"
Print #1, "Open generate.pzm"
Print #1, "openOutput fit.txt"
Print #1, " ForEach 500"
Print #1, " GoTo R 1"
Print #1, " Regenerate"
Print #1, " GoTo R 2"
Print #1, " WCell 5,1"
Print #1, " Next"
Close #1
Shell ("C:\program files\prism5\prism.exe @C:\prism5\auto.pzc")
Workflow:
- All script commands in one Excel VBA file
- Each line prefaced with
Print #1,and in quotes - Simplifies editing (one file vs two)
- Trade-off: More complex syntax
Import Prism Graph to Excel (VBA)
Prerequisites:
- Manually create picture object in Excel (Control toolbar → Image button → drag)
- Name the object (e.g., "DRGraph")
VBA code:
Sheet2.DRGraph.Picture = LoadPicture(Path$ + "dr2.wmf")
Note: Prism script must export graph as WMF first. No VBA command to directly import pictures, so must change existing picture object's contents.
Key Concepts Summary
File Extensions:
.pzc- Prism script file.pzfx- Prism XML format file (editable data).pzm- Prism template/master file
Script Execution Modes:
- From Prism: Interactive testing/development
- Desktop/Shortcuts: User-initiated batch processing
- Shell/Automation: Programmatic integration
- Intranet: Web-based launching
Cross-Platform Differences:
- Windows: Shell, OLE/ActiveX, batch files
- Mac: Automator, MacScript, AppleScript (HFS/POSIX paths)
Synchronization:
- Shell/MacScript return immediately
- Use completion file pattern (done.txt) with polling loop
- OLE automation waits automatically
No API: Prism has no direct API - use scripts or PZFX file manipulation instead.