Ich habe ein Python Skript geschrieben in dem ich mit der paraview über das Modul paraview.simple verschiedene Operationen mit einem Körper ausführe.
Hier ein vereinfachtes Beispielskript
Code: Alles auswählen
from paraview.simple import *
import tkinter as tk
from tkinter.filedialog import askopenfilename
import sys
import ctypes # An included library with Python install.
import numpy as np
def setData():
d.append(GetActiveSource())
app.destroy()
def Quit():
app.destroy()
sys.exit(0)
class Inputbox():
def __init__(self, text=""):
self.root = tk.Tk()
self.get = ""
self.root.geometry("300x100")
self.root.title("Input Number")
self.label_file_name = tk.Label(self.root, text=text)
self.label_file_name.pack(pady=10)
self.entry = tk.Entry(self.root)
self.entry.pack(pady=10)
self.entry.focus()
self.entry.bind("<Return>", lambda x: self.getinput(self.entry.get()))
self.root.mainloop()
def getinput(self, value):
self.get = value
self.root.destroy()
def open_it(x):
global designfile
global scanfile
root = tk.Tk()
root.file = askopenfilename(filetypes=[(x+' -stl Files','.stl')])
d.append(root.file)
#if x=="DESIGN":
# designfile=root.file
#if x=="SCAN":
# scanfile=root.file
root.destroy()
d=[]
open_it("DESIGN")
open_it("SCAN")
inp = Inputbox(text="Nummer:")
print(inp.get)
for i in range(0,2):
if i==0:
Data=inp.get+"DESIGN"
elif i==1:
Data=inp.get+"SCAN"
else:
print(ERROR)
sys.exit(0)
Path = "C://............/Desktop//calc//"
teststl= STLReader(FileNames=[d[i]])
#teststl=SetActiveSource(d[i])
#renderView1 = GetActiveViewOrCreate('RenderView')
#teststlDisplay = Show(teststl, renderView1)
#python_calc=PythonCalculator(Input=teststl)
generateSurfaceNormals1 = GenerateSurfaceNormals(Input=teststl)
Radius = Calculator(Input=generateSurfaceNormals1)
Radius.AttributeType = 'Point Data'
Radius.Function = 'sqrt(coordsY^2+coordsZ^2)'
Radius.ResultArrayName='R'
b=paraview.servermanager.Fetch(Radius)
c=b.GetPointData().GetArray("R").GetRange()
Dia=c[-1]
Dia=round(Dia,2)
p = Calculator(Input=Radius)
p.AttributeType = 'Point Data'
p.Function = '0*iHat+jHat*coordsY^-1-kHat*coordsZ^-1'
p.ResultArrayName='p'
Pitch_vec = Calculator(Input=p)
Pitch_vec.AttributeType = 'Point Data'
Pitch_vec.Function = '((-p_Y*Normals_Y-p_Z*Normals_Z)/Normals_X)*iHat+jHat*p_Y+kHat*p_Z'
Pitch_vec.ResultArrayName='Pitch_vec'
Pitch_angle = Calculator(Input=Pitch_vec)
Pitch_angle.AttributeType = 'Point Data'
Pitch_angle.Function = 'acos((p_X*Pitch_vec_X+p_Y*Pitch_vec_Y+p_Z*Pitch_vec_Z)/(sqrt(p_X^2+p_Y^2+p_Z^2)*sqrt(Pitch_vec_X^2+Pitch_vec_Y^2+Pitch_vec_Z^2)))'
Pitch_angle.ResultArrayName='Pitch_angle'
PitchMM = Calculator(Input=Pitch_angle)
PitchMM.AttributeType = 'Point Data'
PitchMM.Function = '2*3.14159265*R*1000*tan(Pitch_angle)'
PitchMM.ResultArrayName='PitchInMM'
HoeheMM = Calculator(Input=PitchMM)
HoeheMM.AttributeType = 'Point Data'
HoeheMM.Function = 'coordsX'
HoeheMM.ResultArrayName='HoeheinMM'
Phi = PythonCalculator(Input=HoeheMM)
Phi.Expression = 'arctan2(points[:,2], points[:,1])*180/3.14159265+180'
Phi.ArrayName = 'Phi'
clipHub = Clip(Phi)
clipHub.ClipType = 'Scalar'
clipHub.Scalars = ['POINTS', 'R']
clipHub.Value = 0.2
clipHub.Invert = 0
RegionId = Connectivity(Input=clipHub)
RegionId.RegionIdAssignmentMode = 'Cell Count Descending'
BladeId = Calculator(Input=RegionId)
BladeId.AttributeType = 'Point Data'
BladeId.Function = 'RegionId'
BladeId.ResultArrayName='BladeId'
SectionId = Calculator(Input=BladeId)
SectionId.AttributeType = 'Point Data'
SectionId.Function = 'BladeId+R'
SectionId.ResultArrayName='SectionId'
# Properties modified on contour1
RadiiContour1 = Contour(Input=SectionId)
RadiiContour1.ContourBy = ['POINTS', 'R']
RadiiContour1.Isosurfaces = [float(0.2*Dia), float(0.25*Dia), float(0.3*Dia), float(0.4*Dia),float(0.5*Dia), float(0.6*Dia), float(0.7*Dia),float(0.8*Dia), float(0.9*Dia), float(0.95*Dia)]
#renderView1 = GetActiveViewOrCreate('RenderView')
#contour1Display = Show(RadiiContour1, renderView1)
#teststlDisplay = Show(SectionId, renderView1)
#teststlDisplay = Show(RadiiContour1, renderView1)
#teststlDisplay = Hide(teststl, renderView1)
print("paraview"+Data)
writer = CreateWriter(Path+Data+".csv",RadiiContour1)
writer.FieldAssociation = "Points"
#writer.FieldAssociation = "Cells"
writer.UpdatePipeline()
del writer
print("paraview"+Data)
Ich starte das Skript aus der Spyder GUI.
Hat jemand eine Idee woran das liegen könnte?