CFD Online Logo CFD Online URL
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] Generating isosurface from vtk file with python script

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

LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2018, 08:53
Default Generating isosurface from vtk file with python script
New Member
James Schloss
Join Date: Mar 2018
Posts: 1
Rep Power: 0
Leios is on a distinguished road
I have a vtk file that is generated via auxiliary code and would like to generate isosurfaces of this (3D) data. I can read this in correctly and create the necessary isosurfaces manually, and can even do the same with the python shell when the gui is up by doing the following:

import paraview.simple as ps

# reads in a vtk file
test = ps.OpenDataFile("/path/to/test.vtk")
c = ps.Contour(Input=test, Isosurfaces=[0.5])

If I enter these commands line-by-line into the python shell, the correct isosurface is generated; however, if I run the script by using either the "Run Script" button or pvbatch, the isosurface is not created. In both cases, the vtk data is (test) is generated correctly. Interestingly, when I click the "Apply" button (with no other input on my end) on the isosurface in the paraview window, the isosurface is also generated correctly, which means that I must be missing some scriptable "Apply" button.

The closest solution to this can be found here: https://colorsfordirectors.wordpress...ython-scripts/

# 1. import the paraview.simple module (here renammed 'pvs')
import paraview.simple as pvs
# 2. create the filter with desired input
my_filter = pvs.FilterName(Input=my_data)
# 3. set properties
my_filter.PropertyOne = [0, 0, 0]
# 4. update the filter (optionnal)
I added the UpdatePipeline() function to my script and this seemed to do nothing.

I will test this out on another paraview installation / linux distribution tomorrow when I get back into the office. I am currently running Arch and paraview 5.4.1 .

If anyone has any advice, I would love to hear it! I'm new to paraview python scripting and am having a bit of trouble figuring everything out. Thanks for reading and any help you can provide!
Leios is offline   Reply With Quote

Old   March 26, 2018, 12:33
New Member
Forge Analytics
Join Date: Jan 2018
Posts: 16
Rep Power: 8
forgeanalytics is on a distinguished road
You'll probably want something like the following:

import paraview.simple as ps

view = ps.GetActiveViewOrCreate('RenderView')

# reads in a vtk file
test = ps.OpenDataFile("/path/to/test.vtk")
test_display = ps.Show(test, view)


c = ps.Contour(Input=test, Isosurfaces=[0.5])
c_display = ps.Show(c, view)

# If you want to hide the original data (or don't show in first place)
# ps.Hide(test, view)


# set camera position...

ps.SaveScreenshot('/path/to/img.png', view, ImageResolution=[1920,1080])

# or ps.RenderAllViews()

ParaView has a Python script recorder at "Tools >> Start Trace" and "Tools >> Stop Trace" that you'll find useful (if you weren't using it already).

Let me know if you have any problems.
__________________ | Data Management for Scientists and Engineers
forgeanalytics is offline   Reply With Quote


isosurface, paraview, python, python script

Thread Tools Search this Thread
Search this Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 03:30
OpenFoam "Permission denied" and "command not found" problems. OpenFOAM Running, Solving & CFD 11 January 2, 2018 06:47
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 06:42
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 10:57

All times are GMT -4. The time now is 20:44.