stl file is not saving using SaveData in python.

Dear All,

I used one stl file to split the stl using Paraview. I traced the method using python trace in paraview.

Now, I used the code in python to run it. It runs perfectly, but it does not save the splitted mesh as needed. The code is used as per the trace obtained from paraview. Below is the snipped of the code where SaveData is used to save the file. How to save stl file?

# create a new 'Extract Surface'
extractSurface1 = ExtractSurface(Input=threshold1)

    # save data
    SaveData('surf.stl', proxy=extractSurface1, FileType='Ascii')

This is not saving anything. Any leads will be appreciated.

Regards,
Sunag R A.

This code is saving a surf.stl file in the location ParaView is run from.

This is my question. It is actually not saving anything. I am running the python file from IDE by giving ParaviewBuildPath. Below is the full code along with original stl mesh. Let me know if the file is saved after splitting the stl mesh from original mesh.

Please change the build path accordingly, in case of running.

import sys  #sys- append path
import numpy as np

ParaViewBuildPath = "/home/ParaView-5.7.0/"
sys.path.append(ParaViewBuildPath + "lib/") 
sys.path.append(ParaViewBuildPath + "lib/python3.7/site-packages")
sys.path.append(ParaViewBuildPath + "lib/python3.7/site-packages/vtkmodules")

from paraview.simple import *   
# find source
mesh176_rightstl = FindSource('mesh176_right.stl')
generateSurfaceNormals1 = GenerateSurfaceNormals(Input=mesh176_rightstl)
# Properties modified on generateSurfaceNormals1
generateSurfaceNormals1.FeatureAngle = 15.0
# create a new 'Connectivity'
connectivity1 = Connectivity(Input=generateSurfaceNormals1)

# create a new 'Threshold'
threshold1 = Threshold(Input=connectivity1)
#threshold1.Scalars = ['POINTS', 'RegionId']

# Properties modified on threshold1
threshold1.ThresholdRange = [10.0, 982.0]

# create a new 'Extract Surface'
extractSurface1 = ExtractSurface(Input=threshold1)

# save data
SaveData('surf176.stl', proxy=extractSurface1, FileType='Ascii')

Link for stl file: mesh

Dear Mathieu Westphal,

Thank you very much for the reply. I worked on printing the mesh.

print(mesh176_rightstl) shows ‘None’.

I changed the directory, now the error is not there, but still the file is not saving.!! I tried with basic work example as

s = Sphere()
SaveData( ‘sphere.stl’, proxy = s, FileType=‘Ascii’)

This works and saves the stl file. But not the one I needed.

Mesh link: Mesh

Regards,
Sunag R A.

Uncomment this line in your script:

#threshold1.Scalars = ['POINTS', 'RegionId']

Well, I did try that too…!! But, still same issue. I also tried working with Paraview 5.9.0 with python 3.8. Also, same issue. I have addressed the full paraview trace in below link. It has all “display” things. So, removed those and shortened the code which is before post.

Full paraview trace link: stlsplit_paraview1.py (6.3 KB)

The following script works perfectly for me with ParaView 5.9.0

from paraview.simple import *   
# find source
mesh176_rightstl = OpenDataFile("/home/glow/tmp/mesh176_right.stl");
#mesh176_rightstl = FindSource('mesh176_right.stl')
generateSurfaceNormals1 = GenerateSurfaceNormals(Input=mesh176_rightstl)
# Properties modified on generateSurfaceNormals1
generateSurfaceNormals1.FeatureAngle = 15.0
# create a new 'Connectivity'
connectivity1 = Connectivity(Input=generateSurfaceNormals1)

# create a new 'Threshold'
threshold1 = Threshold(Input=connectivity1)
threshold1.Scalars = ['POINTS', 'RegionId']

# Properties modified on threshold1
threshold1.ThresholdRange = [10.0, 982.0]

# create a new 'Extract Surface'
extractSurface1 = ExtractSurface(Input=threshold1)

# save data
SaveData('surf176.stl', proxy=extractSurface1, FileType='Ascii')
1 Like

This works perfectly for me too…!! This is awesome…!!

I changed from FindSource to OpenDataFile as you have written.!!

Thank you so much for this…!! Just a line made me go out of line for few days…!! :smiley: :zipper_mouth_face:

Regards,
Sunag R A.