3

In Paraview, one can do Edit -> Reset Session. It brings a clean state.

How can that be done programmatically, from a python script? I mean it to work for both the GUI (at the python shell and as a macro) and CLI (pvpython).

PS: I wouldn't know what are the differences between Reset Session and closing / reopening Paraview. I did not test it thoroughly, but in all I could observe, they behave the same.

PS2: I am currently using a contrived way, but it is not quite equivalent to Reset Session.

def reset_session() :
    RemoveViewsAndLayouts()
    clear_pipeline()
    return

def clear_pipeline() :
    srcs = GetSources()
    for key, val in srcs.items() :
        #print( "key = " + str(key) + ", value = " + str(val) )
        #print( "   (" + str(type(key)) + "),  (" + str(type(val)) + ")" )
        Delete(val)
        del val
    return

PS3: I tested an answer with this minimal code, executed from the GUI from Macros -> mymacro, and it crashes.

Disconnect()
Connect()

2 Answers2

4

For ParaView <= 5.7.1 : Reset Session remove all the proxies. It is really close to closing reopening the application and can be considered as such.

To do that in Python, since ResetSession is not implemented, use the following :

Disconnect()
Connect()
Mathieu Westphal
  • 2,544
  • 1
  • 19
  • 33
2

ParaView 5.8.0 now has a ResetSession() method.

Mathieu Westphal
  • 2,544
  • 1
  • 19
  • 33