CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   ParaView (http://www.cfd-online.com/Forums/paraview/)
-   -   Save Animation via command line (http://www.cfd-online.com/Forums/paraview/113619-save-animation-via-command-line.html)

paraJim February 23, 2013 06: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 07: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: http://www.paraview.org/Wiki/ParaView/Python_Scripting
  3. I don't know the level of web display you want to provide, but there is also ParaViewWeb: http://www.paraview.org/Wiki/ParaViewWeb
Good luck!
Bruno

paraJim February 24, 2013 12: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:

Code:

movie = servermanager.animation.AnimationScene()
movie.ViewModules = [GetActiveView()]
movie.NumberOfFrames = 10
movie_writer = servermanager.vtkSMAnimationSceneImageWriter()
movie_writer.SetFileName("C:\movie.avi")
movie_writer.SetFrameRate(1)
movie_writer.SetQuality(2)
movie_writer.SetAnimationScene(movie.SMProxy)
movie_writer.Save()

(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. http://www.paraview.org/pipermail/pa...ch/011400.html

I think I am getting closer.

wyldckat February 24, 2013 15: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: http://www.paraview.org/Wiki/Python_GUI_Tools

Best regards,
Bruno

paraJim February 24, 2013 15:20

Hi wyldckat,

thanks for your response.

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

Code:

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):
    camera.Azimuth(360.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()
    listKeyframe.append(keyframe)

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

movie_writer = servermanager.vtkSMAnimationSceneImageWriter()
movie_writer.SetFileName("C:\movie.avi")
movie_writer.SetFrameRate(24)
movie_writer.SetQuality(2)
movie_writer.SetAnimationScene(movie.SMProxy)
movie_writer.Save()

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 15:33

Not that I'm aware of. You'll probably have to use if statements: http://www.tutorialspoint.com/python/python_if_else.htm

paraJim February 24, 2013 15: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.

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

wyldckat February 24, 2013 16:04

Quote:

Originally Posted by paraJim (Post 409825)
EDIT:
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...


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