CFD Online Discussion Forums

CFD Online Discussion Forums (
-   ParaView (
-   -   Save Animation via command line (

paraJim February 23, 2013 07:05

Save Animation via command line
Hi there,

I would like to know how to control ParaView via command line to perform the following tasks:

- Load a 3d model file (like *.stl)
- Set camera to "orbit"
- Save the animation to ogv

I simply want to create a rotating animation from a 3d model to show in a webbrowser.

If I guess correctly I have to use python to accomplish this task?

Thanks in advance

wyldckat February 23, 2013 08:10

Greetings paraJim and welcome to the forum!

I'm short on time, so I'm only able to give the following hints:
  1. You can use pvpython or pvbatch for using/controlling from the command line. But it will not have an open ParaView window, if I remember correctly.
  2. (Semi-)Official instructions available here:
  3. I don't know the level of web display you want to provide, but there is also ParaViewWeb:
Good luck!

paraJim February 24, 2013 13:39

Hi wyldckat,

thanks for the fast response.

What I have tried so far:

I opened up ParaView, loaded a STL file and executed the following code in the python shell of ParaView:


movie = servermanager.animation.AnimationScene()
movie.ViewModules = [GetActiveView()]
movie.NumberOfFrames = 10
movie_writer = servermanager.vtkSMAnimationSceneImageWriter()

(i found the code sample in a paraview mailing list)

Which actually creates an avi file.

What I didn't figure out is:
- How to load any 3d Model into the script?
- How to add the animation to the script? I want that the camera orbits around the object.

Here seems to be a solution for setting up the camera to orbit in python but i can't download the python script.

I think I am getting closer.

wyldckat February 24, 2013 16:05

Hi paraJim,

Sorry, I was so focused on the command line that I forgot to mention that you can use the "Python Trace" to help you generate the script that loads the files and so forth:

Best regards,

paraJim February 24, 2013 16:20

Hi wyldckat,

thanks for your response.

My script is almost finished. This is what I have got so far:


from paraview.simple import *

movie = servermanager.animation.AnimationScene()
movie.ViewModules = [GetActiveView()]
movie.NumberOfFrames = 48
# find view object
view = GetActiveView()

# Create an animation cue for the camera. This represents the "track" shown in cuethe Animation View.
cue = servermanager.animation.CameraAnimationCue()
cue.AnimatedProxy = [view]

# Add this cue to the scene.
movie.Cues = [cue]

# Now create keyframes. Let's say we are going to orbit around the object.
camera = view.GetActiveCamera()
num_of_keyframes = 10
listKeyframe = []
for i in range(0, num_of_keyframes):
    keyframe = servermanager.animation.CameraKeyFrame()
    # set the value of the key frame to the current camera location.
    keyframe.KeyTime = i*1.0/num_of_keyframes
    keyframe.Position = camera.GetPosition()
    keyframe.FocalPoint = camera.GetFocalPoint()
    keyframe.ViewUp = camera.GetViewUp()
    keyframe.ViewAngle = camera.GetViewAngle()

#cue.KeyFrames.append(keyframe) because 'append' don't exist for this object
cue.KeyFrames = listKeyframe

movie_writer = servermanager.vtkSMAnimationSceneImageWriter()

It successfully creates the orbit animation and saves it to disk as an avi file.

One problem still exists:

- How can I load a file to the python script if I don't know the file type?

If I have a vtk file I need to run:
reader = servermanager.sources.LegacyVTKReader(FileNames='m yFile.vtk')

If I have a stl file I need to run:
reader = STLReader( FileNames=['myFile.stl'] )

Is there a "generic" reader that can read everything?

wyldckat February 24, 2013 16:33

Not that I'm aware of. You'll probably have to use if statements:

paraJim February 24, 2013 16:35

Hi wyldckat,

I found another way in the documentation:

Alternatively, starting with ParaView 3.8, you can use OpenDataFile() function to let ParaView pick a reader using the extension of the file.
>>> reader = OpenDataFile(“.../can.ex2”)
Thank you very much for your help.

Do you know how to suppress the preview dialog when running the script with pvpython.exe or pvbatch.exe?

wyldckat February 24, 2013 17:04


Originally Posted by paraJim (Post 409825)
Do you know how to suppress the preview dialog when running the script with pvpython.exe or pvbatch.exe?

I know I've tested this in the past... but it was on Linux... it's this one I think: Using offscreen rendering post #4
Not sure how it will work on Windows...

Henning86 February 17, 2017 11:15

it is possible to load a state file and save it as animation:


from paraview.simple import *

view = GetActiveView()
scene = GetAnimationScene()

view.ViewSize = [1920,1080] # change resolution
#view.StereoRender = 1
#view.UseOffscreenRendering = 1

scene = GetAnimationScene()
scene.EndTime = 0.1
scene.PlayMode = 'Snap To TimeSteps'
scene.AnimationTime = 2.0

# save animation images/movie
WriteAnimation('./Test.ogv', Magnification=1, FrameRate=10.0, Compression=False)

worked with paraview v52 to execute type:

pvbatch FILENAME

All times are GMT -4. The time now is 03:23.