How to delete or update a preset from Python

Is it possible to update or delete a preset using Python? I could not find it in the docs

My application uses some custom presets that are loaded with a script when ParaView starts.

for colormap in results["presets"]["xml"]:
    LoadLookupTable(os.path.join(results["presets"]["path"], f"{colormap}.xml"))

The problem arises when I update a preset for whatever reason. The new preset is loaded (I can see it in the list), but it is not applied.
The reason seems to be that when ParaView quits it saves the presets in .config/ParaView/ParaView-UserSettings.json. Here I can see both versions, but maybe only the first one is actually used by ApplyPreset(preset_name).

I thought of editing the ParaView-UserSettings.json directly and removing the old preset definition, but I have a mix of categorical and normal colormaps and it is not immediately obvious how to parse the content of CustomPresets in the file.

Of course there would be the nuclear option to delete the file before launching ParaView, but it would not be nice for the user :slight_smile:

Well, indeed, there is no easy API for that (i.e., nothing in But you can manage to do something with the vtkSMTransferFunctionPresets singleton, as done inside LoadLookupTable.

Something like this:;

presets = servermanager.vtkSMTransferFunctionPresets.GetInstance()
for idx in range(presets.GetNumberOfPresets()):
  if presets.GetPresetName(idx) == "MyPreset":

You cannot delete default presets.

More about this object in C++ doc here

1 Like

Thanks @nicolas.vuaille . It works perfectly.