CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [General] Python script for creating a movie (https://www.cfd-online.com/Forums/paraview/171311-python-script-creating-movie.html)

Zetison May 5, 2016 05:39

Python script for creating a movie
 
I have two sets of files (.vtu files) which are combined into two .pvd files. My script for creating a visualization is the following

Code:

from paraview.simple import *
import os

pth = "C:/Users/Jon Vegard/Dropbox/work/matlab/results/SS_RBC_BI/paraviewResults"

os.chdir(pth)
fileName = "SS_RBC_BI_0_1_exact"
inputFilename = "%s/%s_solid.pvd" % (pth,fileName)
reader = OpenDataFile(inputFilename)
wrp = WarpByVector(reader)
wrp.ScaleFactor = 4e9

Show(wrp)
Render()

inputFilename = "%s/%s_outer.pvd" % (pth,fileName)
reader = OpenDataFile(inputFilename)
clp = Clip(reader)
clp.ClipType.Normal = [0, -1, 0]
clp.ClipType.Origin = [0, 0.0001, 0]
wrp2 = WarpByVector(clp)
wrp2.ScaleFactor = 4e9

Show(wrp2)
Render()

c = GetActiveCamera()
c.SetPosition(-17.87, 16.15, 19.31)
outputFilename = "%s/%s.avi" % (pth,fileName)
AnimateReader(reader, filename=outputFilename)

outputFilename = "%s/%s.png" % (pth,fileName)
WriteImage(outputFilename)

However, the scale factors for wrp and wrp2 are not updated, how do I fix this? (I tried wrp.UpdatePipeline())

Also, how do switch on one of the scalar fields? And how do I change the frame rate?

Zetison May 6, 2016 05:40

I found some nasty work arounds to two of the problems given below

Code:

from paraview.simple import *
import os

pth = "C:/Users/Jon Vegard/Dropbox/work/matlab/results/SS_RBC_BI/paraviewResults"

os.chdir(pth)
fileName = "SS_RBC_BI_0_1_exact"

# set up the camera       
view = GetRenderView()
view.CameraPosition        = [-28.46194145575746, 32.3037816038933, 29.71970873799418]       
view.CameraFocalPoint        = [0.20237148287731366, -0.26241365028257724, -0.5087481391252592]       
view.CameraViewUp        = [0.4079595183634798, 0.7876489187391945, -0.4617122612467806]
#view.Background        = [1, 1, 1]        # white        background

##########################################################
# Create object 1
inputFilename1 = "%s/%s_solid.pvd" % (pth,fileName)

reader1 = OpenDataFile(inputFilename1)
clp1 = Clip(reader1)
clp1.ClipType.Normal = [0, -1, 0]
clp1.ClipType.Origin = [0, 6, 0]
test1 = Show(clp1)
test1.Representation = 'Surface'
test1.ColorArrayName = 'Stress rr'

wrp1 = WarpByVector(clp1)
wrp1.ScaleFactor = 4e9
Show(wrp1)
Hide(clp1)

##########################################################
# Create object 2
inputFilename2 = "%s/%s_outer.pvd" % (pth,fileName)

reader2 = OpenDataFile(inputFilename2)
clp2 = Clip(reader2)
clp2.ClipType.Normal = [0, -1, 0]
clp2.ClipType.Origin = [0, 0.0001, 0]
test2 = Show(clp2)
test2.Representation = 'Surface'
test2.ColorArrayName = 'Scalar field'

wrp2 = WarpByVector(clp2)
wrp2.ScaleFactor = 4e9
Show(wrp2)
Hide(clp2)

Render()


##########################################################
# Create movie
outputFilename = "%s/%s.avi" % (pth,fileName)
scene = servermanager.animation.AnimationScene()
scene.FramesPerTimestep=1
scene.Duration=2
scene.NumberOfFrames = 30
#test3 = AnimationSceneImageWriter()
#test3.FileName = outputFilename
#test3.FrameRate = 0.01
WriteAnimation(outputFilename, Quality=2, FrameRate=15.0, FramesPerTimestep=1, NumberOfFrames = 30, FrameRange = [0, 29])

##########################################################
# Create picture
outputFilename = "%s/%s.png" % (pth,fileName)
WriteImage(outputFilename)

But NumberOfFrames is ignored in WriteAnimation(), how to fix this?


All times are GMT -4. The time now is 19:02.