import salome import GEOM from salome.geom import geomBuilder geompy = geomBuilder.New(salome.myStudy) # Load data # If file is not opened, determine path with os library # import os # os.chdir(os.path.expanduser('~/')) with open('data.txt','r') as f: fileread = f.readlines() content = [x.strip() for x in fileread] # Define data list data = [] for coord in content: data.append([x.strip() for x in coord.split(" ")]) f.close() coord_x = [] coord_y = [] # convert coordinates to mm and to float type for i in range(len(data)): data[i][0] = float(data[i][0])*(1000) data[i][1] = float(data[i][1])*(1000) data[i][2] = float(data[i][1])*(1000) coord_x.append(data[i][0]) coord_y.append(data[i][1]) # mirror x coordinatex over yz - plane coord_mirror_x = coord_x[::-1] for n in range(len(coord_mirror_x)): coord_mirror_x[n] = coord_mirror_x[n]*(-1) coord_mirror_y = coord_y[::-1] # Iterate over coord_x and create geompy vertices and store those # vertices into python list. points_x = [] for i in range(len(coord_x)): point_x = geompy.MakeVertex(coord_x[i],coord_y[i],0) points_x.append(point_x) points_y = [] for i in range(len(coord_x)): point_y = geompy.MakeVertex(coord_mirror_x[i],coord_mirror_y[i],0) points_y.append(point_y) # Create B-Spline curve on the set of points with # geompy.MakeInterpol() and add curve to Salome study. b_spline = geompy.MakeInterpol(points_x) b_splineID = geompy.addToStudy(b_spline,"b_spline_ft") b_spline_mirror = geompy.MakeInterpol(points_y) b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored") # Create line between both curves. ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0) ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0) middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2) middle_lineID = geompy.addToStudy(middle_line,"middle_line") # Create wire out of all three components wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline]) wireID = geompy.addToStudy(wire,"wire") # Load data for extrusion dataExtrusion = [] with open('dataPolyline.txt','r') as f: fileread = f.readlines() content = [x.strip() for x in fileread] # Define data list for coord in content: dataExtrusion.append([x.strip() for x in coord.split(" ")]) f.close() # Read data for extrusion coord_xe = [] coord_ye = [] coord_ze = [] for n in range(len(dataExtrusion)): coord_xe.append(float(dataExtrusion[n][0])) coord_ye.append(float(dataExtrusion[n][1])) coord_ze.append(float(dataExtrusion[n][2])) # Convert data to geompy point and store it in a list. points_e = [] for coord_e in range(len(coord_xe)): point_e = geompy.MakeVertex(coord_xe[coord_e],coord_ye[coord_e],coord_ze[coord_e]) points_e.append(point_e) # Create polyline for extrusion and add it to study. polylineVert = geompy.MakePolyline(points_e) polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert") # Create panel shape panel_FW = geompy.MakePipe(polylineVert, wire) geompy.addToStudy(panel_FW,'Panel') salome.sg.updateObjBrowser(True)