Use "name" option in paraview.simple.LoadState

Hi,

I am trying to use a single state file (.pvsm) to analyse several different simulations with pvpython. In order to repoint paraview to the different files needed, I am using the filenames option to paraview.simple.LoadState:

paraview.simple.LoadState(
  "template.pvsm",
  filenames=[{"id": 5975, "FileName": new_filenames}])

This works, and I am able to load in the state with the new filenames. However, the “id”, which I found from visually inspecting the state file,

    <Proxy group="sources" type="XMLUnstructuredGridReader" id="5975" servers="1">
      <Property name="FileName" id="5975.FileName" number_of_elements="76">

is quite fragile, and if I created a new state file with a different analysis, I would need to go and look for the new ID. From the documentation, it seems that I should be able to specify a “name” instead, but I can’t get this to work. I can’t tell from the XML file what the name would be.

And even if I did know, I would need to be able to specify it without specifying the “id”. But the code, converts the “id” to an integer, and if this is left at the default of None, this fails with

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

So unless I specify an “id”, I cannot call LoadState with filenames. Is there any way to call this without knowing the ID of the reader?

I guess I will parse the XML file and search for it, but surely there is a better way!

Hi @ianhinder ,

I dont think this usecase is handled. You should be able to change the filename after loading the state though.

Alternatively, you could use a python state file but that would be a different approach entirely.

Hi,

Thanks for the speedy response!

Won’t loading the state file attempt to load all the original files though? In general, they might be very large, which could take a long time, or not be available on the machine I’m running on, which would presumably cause an error. So that doesn’t seem like a good solution.

I originally started off using Python state files, but this was also problematic. Suppose I have set up the visualisation I want in the GUI, and save the Python state file. This will programatically list all the input files explicitly. If I then want to change these files, I need to edit the state file. The first time I did this, I did exactly that, and made the directory containing the files a parameter to the python state file, which I would then run as a script with pvpython. However, if I want to edit the visualisation, doing this in pvpython is much more complicated than doing it in the GUI. But if I do it in the GUI, when I save the Python state file again, of course it will lose all my changes. This approach also requires me to make these edits to the state file for each new visualisation I want to create. It’s not a good solution, unfortunately.

It seems that the Python state file is only really good for the initial setup of the visualisation if you’re not comfortable with the ParaView API (which I’m not). But any further edits need to be made in Python, which is only really practical if you are an expert, or to tweak minor details. Large-scale changes such as adding a new filter or a new view would be difficult.

Saving “state” in an imperative language also seems wrong; I think the XML approach is probably the right one, but it’s necessary to be able to adapt at least the sources programatically.

If this use case is not currently supported, I will have to search for the ID from the XML file using a parser I think.

I would be surprised if I was the first person to want to use a single visualisation state file to analyse more than one dataset from a script. Surely other people also need to do this; what does everyone else do?

I would be surprised if I was the first person to want to use a single visualisation state file to analyse more than one dataset from a script. Surely other people also need to do this; what does everyone else do?

In ParaView it is trivial to do so as there is a dedicated dialog that lets you do that. We would need to investigate to see if there is a easier way in Python to do that.