CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > ParaView

Save Animation via command line

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By wyldckat
  • 2 Post By paraJim

Reply
 
LinkBack Thread Tools Display Modes
Old   February 23, 2013, 07:05
Smile Save Animation via command line
  #1
New Member
 
Join Date: Feb 2013
Posts: 4
Rep Power: 4
paraJim is on a distinguished road
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
paraJim is offline   Reply With Quote

Old   February 23, 2013, 08:10
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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 likes this.
wyldckat is offline   Reply With Quote

Old   February 24, 2013, 13:39
Lightbulb
  #3
New Member
 
Join Date: Feb 2013
Posts: 4
Rep Power: 4
paraJim is on a distinguished road
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.
paraJim is offline   Reply With Quote

Old   February 24, 2013, 16:05
Default
  #4
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
wyldckat is offline   Reply With Quote

Old   February 24, 2013, 16:20
Smile
  #5
New Member
 
Join Date: Feb 2013
Posts: 4
Rep Power: 4
paraJim is on a distinguished road
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?
paraJim is offline   Reply With Quote

Old   February 24, 2013, 16:33
Default
  #6
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Not that I'm aware of. You'll probably have to use if statements: http://www.tutorialspoint.com/python/python_if_else.htm
wyldckat is offline   Reply With Quote

Old   February 24, 2013, 16:35
Thumbs up
  #7
New Member
 
Join Date: Feb 2013
Posts: 4
Rep Power: 4
paraJim is on a distinguished road
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 and deepinheart like this.

Last edited by paraJim; February 24, 2013 at 16:58.
paraJim is offline   Reply With Quote

Old   February 24, 2013, 17:04
Default
  #8
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Quote:
Originally Posted by paraJim View Post
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...
wyldckat is offline   Reply With Quote

Reply

Tags
animation, command line

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paraview Animation jignesh_thaker2007 OpenFOAM 3 February 18, 2012 07:36
Save animation bug in paraFoam on Mac OSX deinstein OpenFOAM Paraview & paraFoam 3 May 1, 2010 15:29
How to save an animation to mpeg file jack FLUENT 1 June 25, 2008 13:26
save run animation Anis Phoenics 2 November 26, 2007 22:40
Creating an animation Jason FLUENT 3 May 18, 2005 05:13


All times are GMT -4. The time now is 06:25.