« Back

Can ChatGPT Write PyTecplot Scripts?

No question ChatGPT is a game changer when it comes to generating content. I’ve used it myself to write snippets of Python code, tell me what the warning lights on my dashboard mean, and to summarize a book I read. It did a pretty good job.

A colleague recently mentioned “ChatGPT knows PyTecplot!” – so I checked. It does!

Sort of. Here’s a brief recap of my experience.

Prompt: “How do I install PyTecplot”


ChatGPT prompt How to Install PyTecplot

Assessment: Mostly right

PyTecplot is officially supported on the latest version of Python and the two previous. As of this writing, that’s 3.9, 3.10, 3.11. PyTecplot has a hard requirement of Python 3.7 or later (if you’re running ‘connected’ to the 360 GUI). PyTecplot might work with Python 3.6, but we no longer test against it.

Just importing the module will indicate a successful installation, but you need to actually invoke a PyTecplot command to ensure you can run a script. PyTecplot relies on an install of Tecplot 360 and the invocation of a PyTecplot command will trigger the loading of the 360 libraries on which PyTecplot depends. A good test script to run is:

import tecplot as tp
print(“PyTecplot version:”, tp.version_info)
print(“360 version:”, tp.sdk_version_info)

On Linux or macOS, make sure to start Python using the ‘tec360-env’ script to ensure Python can find the Tecplot 360 libraries. Apple Silicon macOS machines (M1/M2 chip) will need to use the Intel version of Python, which should be installed by default. Examples:

Linux: /path/to/tecplot/bin/tec360-env ‐‐ python myscript.py
macOS Intel: /Applications/Tecplot 360 EX [VERSION]/bin/tec360-env ‐‐ python myscript.py
macOS Apple Silicon: /Applications/Tecplot 360 EX [VERSION]/bin/tec360-env ‐‐ python3-intel64 myscript.py

PyTecplot requires a Tecplot 360 license with our TecPLUS maintenance plan.

Prompt: “Write a PyTecplot script to load OpenFOAM data”


Chat GPT's prompt answer for Write a PyTecplot script to load OpenFOAM data

Assessment: Reasonable

Loading OpenFOAM data could be distilled down to two lines of code:

import tecplot as tp

Notice that PyTecplot takes the ‘system/controlDict’ file as input, not the ‘case directory’ as ChatGPT indicates.

The call to ‘tp.session.connect()’ is optional – it’s used to connect to a running GUI instance of Tecplot 360, in which case these commands will drive the user interface.

The call to ‘dataset.zone(0)’ is unnecessary, but that and the print statements could provide useful information if you’re interested.

The call to ‘tp.session.close()’ is incorrect, that API doesn’t exist. The nearest correct API would be ‘tp.session.disconnect()’ which will disconnect from the running instance of Tecplot 360.

Prompt: “Write me a Python script using PyTecplot to load Fluent data, draw a slice, and export an image”


ChatGPT answer to prompt Write me a Python script using PyTecplot to load Fluent data, draw a slice, and export an image

 Assessment: On the right track, but incorrect.

There are a number of things wrong with the script above, but there are hints of correctness here and there. Here’s an example of a correct script to load Fluent data, add a slice, and export an image:

import tecplot as tp
from tecplot.constant import *

dataset = tp.data.load_fluent(case_filenames=['elbow.cas'], data_filenames=['elbow.dat'])
plot = tp.active_frame().plot()
plot.contour(0).variable = dataset.variable("Pressure")
plot.use_translucency = True
plot.show_slices = True
plot.slice(0).orientation = SliceSurface.Arbitrary
plot.slice(0).origin = (0.094, -0.126, 0.018)
plot.slice(0).arbitrary_normal = (0.73325708, 0.67985592, 0.011401222)
tp.export.save_png('output_image.png', width=800)

Example of a correct script to load Fluent data, add a slice, and export an image.


ChatGPT, while impressive, is not sufficient for authoring PyTecplot scripts for you. I’m sure it will improve, but at this point I have the following suggestions:

1. Consult the documentation. We’ve put a lot of effort into the PyTecplot documentation, and it has nice snippets of code throughout: https://tecplot.com/docs/pytecplot/
2. Record a PyTecplot script using Tecplot 360. We have a handy Quick Start guide here: https://tecplot.com/2019/09/17/getting-started-pytecplot-scripting/.

Record a PyTecplot Script using Tecplot 360

3. Ask our support staff for help. They’re still smarter than ChatGPT and pretty friendly too. Reach out at support@tecplot.com.