CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] Python script for creating a movie

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 5, 2016, 05:39
Default Python script for creating a movie
  #1
New Member
 
Jon Vegard Venås
Join Date: Apr 2014
Posts: 16
Rep Power: 12
Zetison is on a distinguished road
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 is offline   Reply With Quote

Old   May 6, 2016, 05:40
Default
  #2
New Member
 
Jon Vegard Venås
Join Date: Apr 2014
Posts: 16
Rep Power: 12
Zetison is on a distinguished road
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?
Zetison is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM] Using python script for automatic post processing of openFoam vPaquet ParaView 12 December 16, 2021 03:30
[General] Generating isosurface from vtk file with python script Leios ParaView 1 March 26, 2018 12:33
python script to create geometry for salome, and then mesh 6863523 Mesh Generation & Pre-Processing 4 March 18, 2017 09:00
[General] Transfer variables into python script from bash-shell cfdFreshman ParaView 0 December 3, 2015 03:33
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 09:36


All times are GMT -4. The time now is 05:09.