Obtain information if proxy is visible

Can anyone tell me how I can have my paraview batch script find out if an object is visible or not?

Here is a small example:

from paraview.simple import *

renderView1 = GetActiveViewOrCreate('RenderView')
source = FastUniformGrid()
display = Show(source, renderView1) 

I can Hide the source's display with

Hide(source, renderView1)

but where is the objects display status actually stored?

It is stored in the representation associated with the source. The representation controls how the source is displayed in ParaView, and it includes a Visibility property.

You can use display.Visibility to check whether the representation associated with source is visibile.

I had tried that, but it didn’t quite work reliably.

I think that there is a bug and here is how to reproduce it:

  1. Set up a renderView (RenderView1) with some hidden object in the pipeline

  2. Create a second renderView (RenderView2). By default, all objects are hidden.

  3. Execute the following lines and observe how GetDisplayProperties makes the hidden object visible:

    renderView = FindViewOrCreate('RenderView2', viewtype='RenderView')
    name, source = GetSources().items()[0]
    display = GetDisplayProperties(source, view=renderView)

I believe that there is a bug in the initialization of existing objects when creating a new renderView.
Manually switching the visibility of all objects from hidden to visible and back to hidden again after creating a new renderView is a workaround.

Here is a MWE: state.pvsm (189.6 KB)

Running the following script: run.py (507 Bytes)

#!/usr/bin/env pvpython

from paraview.simple import *



for renderViewName in ['RenderView1', 'RenderView2']:
    renderView = FindViewOrCreate(renderViewName, viewtype='RenderView')
    name, source = GetSources().items()[0]
    display = GetDisplayProperties(source, view=renderView) # this makes the object visible!
    print('{} : display.Visibility={}'.format(renderViewName, display.Visibility))

produces this output:

RenderView1 : display.Visibility=0
RenderView2 : display.Visibility=1

Okay, this is a little subtle, and has to do with representations being lazily created.

After you load your state file, the representation in RenderView1 is created, exists, and is not visible. There is no representation created for the FastUniformGrid1 object in RenderView2. When your script processes RenderView2, it invokes GetDisplayProperties() which will create a representation for FastUniformGrid1 (since it does not exist for RenderView2) and shows the representation. Hence, the visibility is on in RenderView2, even though it is off in the first renderview.

The behavior arises because the mechanism for creating a representation is to call Show() (realy ts equivalent deeper in the ParaView libraries). We could potentially separate the representation creation from showing it and call the creation function if needed in GetDisplayProperties(). There may be some technical difficulties doing that that I am not aware of, but it’s a possibility.

The behavior is still present and it’s really annoying when working with multiple render views.

Currently, for every filter you add in one render view, you’ll have to go through all the other render views and manually make the filter visible and then invisible again.
Otherwise, loading the session in pvbatch, these filters will be visible in the other render views.

Have you encountered this issue, @wascott?

No, but I haven’t tried. I will run through these examples after our meeting.

Man, this one was interesting. Definately down the rabbit hole for me.

  • I had to hack the python slightly. I am sure my crude sollution is due to my not understanding dictionaries. I had to change the GetSources line to be:
    ** sources = GetSources()
    ** source = FindSource(‘FastUniformGrid1’)
  • My users don’t use different layouts (I believe), mainly because I don’t teach them about layouts.
  • My users generally don’t use scripting that isn’t created with the trace recorder.
  • My users have never complained about this issue.

My $0.02 is that this is a very rare bug with a workaround. Should be fixed, but probably low on the queue. @cory.quammen, you agree? I know how to replicate it now, want me to write it up?

@bastian This is one of the best bug reports I have seen. Thanks for the time writing it, and well done.

I agree, it should be cleaned up, but priority is low. If you could write it up @wascott, that would be great.


I had the same problem. Maybe these will be helpful to someone.

  • This line will list only visible sources without triggering initialization.
[(n, s) for n, s in GetSources().items() if servermanager.GetRepresentation(s, v) is not None and GetDisplayProperties(s, view=v).Visibility==1]
  • This one will initialize and hide uninitialized sources:
[GetDisplayProperties(s, v).Visibility for s in GetSources().values()]

after which listing visible sources may be done without any problems

[(n[0], s, GetDisplayProperties(s, v).Visibility==1) for n, s in GetSources().items()]