I would like to build a macro for different files. Those files have the same data formats. I have difficulty to achieve the goal because the macro generated by paraview use the specific variable name tailored to each file. For example: when creating a contour map for variable “H”, the command is
contour1.ContourBy = [‘POINTS’, ‘H’]
Thus, I cannot use the same command to the other variables.
Is it possible that I can replace the command by something like
contour1.ContourBy = [‘POINTS’, variable_use]
where the variable_use automatically uses the variable name I have in the file?
Are there any other potential solutions to solve this issue?
You can indeed use a variable instead of a hard-coded variable name - that works fine. The question is how to set that variable automatically.
Lets say you are reading a file and the file reader is named fileReader in your script. You can get the available variable names from it with fileReader.PointData.keys() which returns a list of names. If you have one variable, then set variable_use to the first (and only) item in that variable. If you have more than one point variable, you will need to figure out some other way to pick which variable name to use.
Hmm, maybe call fileReader.UpdatePipeline() before accessing the point data? It should be necessary. It wasn’t with a local file I tried. Feel free to post the data file so someone can see what is going on.
The easiest way to learn the Python scripting is by recording traces. Select Tools → Start Trace menu item, perform some activity in ParaView, then select Tools → Stop Trace. The actions will be recorded as a script, and you can piece together how to write scripts.
In this case, the file has only a single cell data array, not a point data array. Hence you would need to use this code instead to access the list of cell data arrays: tt = okestimate2.CellData.keys()