Loop the slice filter on the 3D dataset

Hi.
I applied slice x normal and y normal on my 3D data to get a set of points coordinates. I set the slice filter as the customize filter. I could run the data and collect the points coordinates one by one using Macros. But when I placed a number of dataset, it couldnt extract the coordinates exactly on the surface.
It is tedious to do the process individually. Is there any better way that I can loop the process automatically on a huge dataset?

Thanks!

My code…

paraview.simple._DisableFirstRenderCameraReset()
reader = LegacyVTKReader(FileNames=['H.vtk'])
renderView1 = GetActiveViewOrCreate('RenderView')
readerDisplay = Show(reader, renderView1)

readerDisplay.ColorArrayName = [None, '']
renderView1.ResetCamera()
a1NTX1 = a1NTX(Input=reader)
a1NTX1Display = Show(a1NTX1, renderView1)
a1NTX1Display.ColorArrayName = [None, '']
Hide(reader, renderView1)

a1NTY1 = a1NTY(Input=a1NTX1)
a1NTY1Display = Show(a1NTY1, renderView1)
a1NTY1Display.ColorArrayName = [None, '']
Hide(a1NTX1, renderView1)
SetActiveSource(reader)

a2LEBX1 = a2LEBX(Input=reader)
a2LEBX1Display = Show(a2LEBX1, renderView1)
a2LEBX1Display.ColorArrayName = [None, '']
Hide(reader, renderView1)

renderView1.CameraPosition = [3.6, -16.08, -1141.25]
renderView1.CameraFocalPoint = [3.60, -16.08, -1519.90]
renderView1.CameraParallelScale = 98.0

you may add three backquotes before and after the code part, so it will be formated as code.

1 Like

You’ll need to add some kind of loop, likely a for loop, the loops over all the data files you want to process. The body of the loop should open the file, runs the macros(?) a1NTY and a2LEBX like above, and end by saving the result either to a file or result array that you do something with later.

Thanks for your reply.
Do you have any links that I can refer as a tutorial? I am new in Python script in Paraview. The results I googled are mostly on Python itself but not on Paraview script. I tried on the following code but it failed.

\\\
from paraview.simple import *

disable automatic camera reset on ‘Show’

paraview.simple._DisableFirstRenderCameraReset()

import os
Path = “D:\PhD\BU3DFE_data_vtk\AN04_30”
filelist = os.listdir(Path)
for i in filelist:
if i.endswith(".vtk"):
with open(Path + i, ‘r’) as file:
for line in file:

reader = line
renderView1 = GetActiveViewOrCreate(‘RenderView’)
readerDisplay = Show(reader, renderView1)
readerDisplay.ColorArrayName = [None, ‘’]
renderView1.ResetCamera()

a1NTX1 = a1NTX(Input=reader)
a1NTX1Display = Show(a1NTX1, renderView1)
a1NTX1Display.ColorArrayName = [None, ‘’]
Hide(reader, renderView1)

a1NTY1 = a1NTY(Input=a1NTX1)
a1NTY1Display = Show(a1NTY1, renderView1)
a1NTY1Display.ColorArrayName = [None, ‘’]
Hide(a1NTX1, renderView1)

SetActiveSource(reader)

a2LEBX1 = a2LEBX(Input=reader)
a2LEBX1Display = Show(a2LEBX1, renderView1)
a2LEBX1Display.ColorArrayName = [None, ‘’]
Hide(reader, renderView1)

a2LEBY1 = a2LEBY(Input=a2LEBX1)
a2LEBY1Display = Show(a2LEBY, renderView1)
a2LEBY1Display.ColorArrayName = [None, ‘’]
Hide(a2LEBX1, renderView1)

SetActiveSource(reader)

renderView1.CameraPosition = [3.6, -16.08, -1141.25]
renderView1.CameraFocalPoint = [3.60, -16.08, -1519.90]
renderView1.CameraParallelScale = 98.0

SaveData(‘D:/001.csv’, proxy=a1NTY1)
SaveData(‘D:/002.csv’, proxy=a1LEBY1)
endswith
\\\

Hi. To format code use three back ticks (```) at the beginning and ending instead of backslashes. The code format is important to understanding what it does, especially in Python, so without it it is hard to give you advice about this piece of code. It is important to indent the body of the if, with, and for statements in Python, otherwise the code won’t work as expected. Also, if code doesn’t work, please report the error that it gives you or the incorrect behavior it produces.

If you have some programming background, a Python tutorial like this one should give you the basics of what you need to know for effective ParaView scripting. The ParaView-specific parts are just Python classes and functions that you use - the rest is all Python.

Hi Polli, I am not sure what you really want to do but in principle you have to write a Python Macro as following and run it via pvpython. Here are some code snippets which maybe could help you.

So first, collect all your vtk data as you already did:
filelist = [f for f in os.listdir(path) if f.endswith('.vtk')]

Next define a function what Paraview should do, in this example I am clippingVolumes let’s say in x-direction
points=np.linspace(0,100,100)
normal=np.array([1,0,0])

def slice(file,points,normal):   
    print('Read Elementlist ' + file)
                                           
    for i in range(0,len(points)):   
            # create a new 'Clip Closed Surface'
            clipClosedSurface1 = ClipClosedSurface(Input=file)
            clipClosedSurface1.ClippingPlane = 'Plane'
            clipClosedSurface1.ClippingPlane.Origin = [points[i],points[1],points[2]]
            clipClosedSurface1.ClippingPlane.Normal = [normal[i],normal[1],normal[2]]  
            clipClosedSurface1.InsideOut = 1 #insideOutClip....and so on

Last but not least, you can now loop over your filelist with a further for loop:

for files in filelist:
    slice(files,points,normal)

Run this script directly via GUI or pvpython in batch mode.