SaveData in Paraview python is not saving the file

Question:

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?

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 *   
import vtk
# 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')

I have addressed the error I am facing from the line "generateSurfaceNormals1".

[paraview ]vtkDemandDrivenPipeline:713 ERR| vtkPVCompositeDataPipeline (0x556f782fe7c0): Input port 0 of algorithm vtkPPolyDataNormals(0x556f7a16b2a0) has 0 connections but is not optional.

How to overcome this error?

Any leads will be appreciated.

Regards,
Sunag R A.

Asked By: rasunag27

||

Answers:

The error message means that mesh176_rightstl is None, so the FindSource does not find anything. Is the source name correct ? Is the data correctly loaded ?

As an error raised, the script stops and SaveData is not called. But its syntax is correct.

Minimal code to test stl writer:

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

It correctly produces the stl file with ParaView 5.9

edit

You should uncomment the line

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

Because pipeline is not executed until you ask for (e.g. with the SaveData), no default array can be found when you created the Threshold.

Answered By: Nico Vuaille
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.