# animation python script error when loaded from state file

**URL:** https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375
**Category:** ParaView Support
**Created:** [May 20, 2020, 5:47pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375 "2020-05-20T17:47:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 20, 2020, 5:47pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/1 "2020-05-20T17:47:40Z")

</div>

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:

```python
    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.

```python
    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")

```

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 20, 2020, 6:09pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/2 "2020-05-20T18:09:47Z")

</div>

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

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

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

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

```

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 20, 2020, 6:43pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/3 "2020-05-20T18:43:41Z")

</div>

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")
```

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 20, 2020, 6:48pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/4 "2020-05-20T18:48:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 20, 2020, 6:59pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/5 "2020-05-20T18:59:12Z")

</div>

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

Thanks Utkarsh!

Dan

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 20, 2020, 7:15pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/6 "2020-05-20T19:15:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 20, 2020, 11:00pm UTC](https://discourse.paraview.org/t/animation-python-script-error-when-loaded-from-state-file/4375/7 "2020-05-20T23:00:58Z")

</div>

See

[https://gitlab.kitware.com/paraview/paraview/-/issues/19943](https://gitlab.kitware.com/paraview/paraview/-/issues/19943)
