Hey there,
It’s Robin from CFD Engine & when I hear macros I think of lost days “automating” Excel with Visual Basic 😰
Thankfully, automating stuff in ParaView is nowhere near as painful, flaky or troublesome 🙏
I’ve written about scripting ParaView and about custom filters in the past, but this week we’re all about automating things using ParaView macros.
It’s not just about recording & replaying clicks either, so let’s get into it…
What’s a ParaView macro?
It’s pretty simple, it’s a button that triggers a Python script.
But as you can replicate almost any GUI task via Python, this is your gateway to automation super-powers.
The macro scripts are stashed in your home directory, loaded automatically & shown as buttons on your toolbar. No need to go hunting for scripts when you need to use them.
They can be created & edited within ParaView & easily shared amongst your workgroup.
What’s not to like?
What if I can’t Python?
Don’t worry, neither can I.
ParaView has the ability to record what you’re doing in the GUI & translate it into a Python script, using Trace
Click Tools > Start Trace
, do the steps you want to automate, click Tools > Stop Trace
& up pops the built-in script editor, with the Python equivalent of what you just did.
Click File > Save As Macro
from the script editor, give it a name & you’re done.
A button will be added to the GUI showing the name of the script, just click it to repeat your steps.
Use Cases
You could do almost anything with a macro, but they don’t have to be super-complicated, here are a few trivial (but really handy) use cases…
Frank’s camera levelling
This one was sent in by a reader (thanks Frank 🙏) the idea is to use a macro to set the camera View Up
to one of the Cartesian axes (Z-Up for example). This levels out the horizon, for more natural looking screenshots, without having to use the fiddly camera settings dialog.
Donut dummy data
I often need to double-check the settings for a filter whilst writing these emails. But, you can’t apply a filter to thin air, so I use a macro to create some dummy data. It creates a donut (Superquadric
) & adds a data field using the Elevation
filter – an instant dummy dataset for testing & checking stuff.
Lazy ranger
I’m often working with normalised fields & (because I’m lazy) I have a macro that grabs the current field & sets the range to ±0.8. A nice symmetrical range that suits the default cool-to-warm colour map & is good enough most of the time.
Why not use a state file?
There are loads of ways to save a few clicks in ParaView (state files, Python scripts, custom filters & macros) and they’re often interchangeable. Here’s how I use them for different tasks…
If I want to recreate a full scene, either to pick up where I left off previously, or to apply the same settings to a different dataset, then I’ll use a state file (.pvsm
).
If I wanted to translate a scene into a Python script, for use in batch, then I’d use a Python state file (.py
) as they’re easier to customise & extend than a .pvsm
.
If I wanted to combine several filters into one, to hide some of the complexity in my pipeline whilst still exposing some key parameters, then I’d use a Custom Filter (although creating them melts my brain) 🤯
If I was making the same changes repeatedly (or building the same pipelines) as part of an interactive GUI session, then I’d use a macro.
Give ’em a try
What actions are you repeating in almost every ParaView session? Are you navigating several menus to change a single setting? Do you need to change a handful of display toggles to get your scene looking just right?
These are your macro candidates. Start with something small – you can always edit it at a later date.
You probably don’t need a data donut or a lazy range, but I’m sure there are at least a couple of macros that would be useful in your day-to-day ParaView sessions.
Have you already got some good ones? Are there any you’d like to share with the class? Let me know, I’m always up for a tricksy automation 🤖
Until next week, stay safe,