animation python script error when loaded from state file

Hi all,
I get the following error when loading a python animation script from the state file.
After that, the animation works fine, without errors. Do you have any suggestions?

This is the error:

    start cue
    Traceback (most recent call last):
      File "<string>", line 30, in <module>
      File "<string>", line 13, in tick
      File "/home/danlipsa/projects/ParaView/build/lib/python3.6/site-packages/paraview/servermanager.py", line 523, in __getattr__
        return getattr(self.SMProxy, name)
    AttributeError: 'paraview.modules.vtkRemotingAnimation.vtkSMAnimati' object has no attribute 'frameIndex'
    end cue

This is the animation script.

    from paraview.simple import *

    def start_cue(self):
      a = GetAnimationScene()
      s = FindSource("allFrames.vtp")
      SetActiveSource(s)
      a.add_attribute("frameIndex", 0)
      print("start cue")

    def tick(self):
      a = GetAnimationScene()
      print(a.frameIndex)
      allFramesvtp = GetActiveSource()
      dp = GetDisplayProperties(allFramesvtp)
      if a.frameIndex < 3:
        s = GetActiveSource()
        frameArray = s.PointData.keys()[a.frameIndex]
        print(frameArray)
        ColorBy(dp, ('POINTS', frameArray, 'Magnitude'))
      else:
        ColorBy(dp, None)
        dp.DiffuseColor = [0.7, 0.7, 0.7]
      a.frameIndex = a.frameIndex + 1

    def end_cue(self):
      print("end cue")

I suspect the python object gotten in start_cue is getting garbage collected.

A workaround is to preserve it by doing something as follows:

def start_cue(self):
  global a
  a = GetAnimationScene()
  ...

def tick(self):
  global a
  print(a.frameIndex)
  ...

Thanks Utkarsh,
That moved things along, but I am still getting an error because ParaView tries to execute the animation before the view is created. Here is the new error

None
start cue
Traceback (most recent call last):
  File "<string>", line 34, in <module>
  File "<string>", line 20, in tick
  File "/home/danlipsa/projects/ParaView/build/lib/python3.6/site-packages/paraview/simple.py", line 498, in GetDisplayProperties
    return GetRepresentation(proxy, view)
  File "/home/danlipsa/projects/ParaView/build/lib/python3.6/site-packages/paraview/simple.py", line 483, in GetRepresentation
    raise ValueError ("view argument cannot be None.")
ValueError: view argument cannot be None.
0
end cue

And the new script:

from paraview.simple import *

def start_cue(self):
  global a
  global s
  global v
  a = GetAnimationScene()
  s = FindSource("allFrames.vtp")
  v = GetActiveView()
  print(v)
  SetActiveSource(s)
  a.add_attribute("frameIndex", 0)
  print("start cue")

def tick(self):
  global a
  global s
  print(a.frameIndex)
  dp = GetDisplayProperties(s, v)
  if a.frameIndex < 3:
    frameArray = s.PointData.keys()[a.frameIndex]
    print(frameArray)
    ColorBy(dp, ('POINTS', frameArray, 'Magnitude'))
  else:
    ColorBy(dp, None)
    dp.DiffuseColor = [0.7, 0.7, 0.7]
  a.frameIndex = a.frameIndex + 1

def end_cue(self):
  print("end cue")

sorry, no clue of the top of my head. I’d put guards in the tick to confirm view is present to get around this. I suspect when loading state “tick” may get called before everything is setup.

Yes, that is a good idea. Indeed, that is what is happening.

Thanks Utkarsh!

Dan

I’d recommend reporting a bug…we should track this down and fix it, when possible.

See

https://gitlab.kitware.com/paraview/paraview/-/issues/19943