Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Repairing Operations


Shape Processing

1 # Shape Processing
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create vertices, an edge, an arc, a wire, a face and a prism
11 p1 = geompy.MakeVertex(0,0,0)
12 p2 = geompy.MakeVertex(200,0,0)
13 p3 = geompy.MakeVertex(100,150,0)
14 edge = geompy.MakeEdge(p1,p2)
15 arc = geompy.MakeArc(p1,p3,p2)
16 wire = geompy.MakeWire([edge,arc])
17 face = geompy.MakeFace(wire, 1)
18 theShape = geompy.MakePrismVecH(face, edge, 130)
19 
20 # check the shape at the beginning
21 print "Before ProcessShape:"
22 isValid = geompy.CheckShape(theShape)
23 if isValid == 0:
24  print "The shape is not valid"
25 else:
26  print "The shape seems to be valid"
27 
28 # process the Shape
29 Operators = ["FixShape"]
30 Parameters = ["FixShape.Tolerance3d"]
31 Values = ["1e-7"]
32 PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
33 
34 # check the shape at the end
35 print "After ProcessShape:"
36 isValid = geompy.CheckShape(PS)
37 if isValid == 0:
38  print "The shape is not valid"
39  raise RuntimeError, "It seems, that the ProcessShape() has failed"
40 else:
41  print "The shape seems to be valid"
42 
43 # add in the study and display
44 Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
45 Id_PS = geompy.addToStudy(PS, "Processed Shape")
46 gg.createAndDisplayGO(Id_Shape)
47 gg.setDisplayMode(Id_Shape,1)
48 gg.createAndDisplayGO(Id_PS)
49 gg.setDisplayMode(Id_PS,1)

Download this script


Suppress Faces

1 # Suppress Faces
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create a box
11 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
12 
13 # The list of IDs (IDList) for suppress faces
14 sup_faces = []
15 sup_faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
16 
17 # get indices of the sub-shape
18 f1_id = geompy.GetSubShapeID(box, sup_faces[3])
19 
20 # remove faces from the given object (shape)
21 result = geompy.SuppressFaces(box, [f1_id])
22 
23 # add objects in the study
24 id_box = geompy.addToStudy(box, "Box")
25 id_result = geompy.addToStudy(result, "Result")
26 
27 # display the results
28 gg.createAndDisplayGO(id_box)
29 gg.setDisplayMode(id_box,1)
30 gg.createAndDisplayGO(id_result)
31 gg.setDisplayMode(id_result,1)

Download this script


Close Contour

1 # Close Contour
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create vertices and vectors
11 p0 = geompy.MakeVertex( 0., 0., 0.)
12 px = geompy.MakeVertex(100., 0., 0.)
13 py = geompy.MakeVertex( 0., 100., 0.)
14 py1 = geompy.MakeVertex( 0., 140., 0.)
15 pz = geompy.MakeVertex( 0., 0., 100.)
16 vxy = geompy.MakeVector(px, py)
17 
18 # create an arc
19 arc = geompy.MakeArc(py1, pz, px)
20 
21 # create a wire
22 wire = geompy.MakeWire([vxy, arc])
23 
24 # close an open wire by creation of an edge between ends
25 wire_close = geompy.CloseContour(wire, [1], 0)
26 
27 # add objects in the study
28 id_wire = geompy.addToStudy(wire, "Wire")
29 id_wire_close = geompy.addToStudy(wire_close, "Wire close")
30 
31 # display the results
32 gg.createAndDisplayGO(id_wire)
33 gg.createAndDisplayGO(id_wire_close)

Download this script


Suppress Internal Wires

1 # Suppress Internal Wires
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create a vertex and a vector
11 p1 = geompy.MakeVertex(55, 65, 50)
12 p2 = geompy.MakeVertex(55, 0, 50)
13 v = geompy.MakeVector(p1, p2)
14 
15 # create a cylinder
16 height = 100
17 radius1 = 40
18 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
19 
20 # create a box
21 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
22 
23 # make a cut
24 cut = geompy.MakeCut(box, cylinder)
25 
26 # suppress all internal wires
27 result = geompy.SuppressInternalWires(cut, [])
28 
29 # add objects in the study
30 id_cut = geompy.addToStudy(cut, "Cut")
31 id_result = geompy.addToStudy(result, "Result")
32 
33 # display the results
34 gg.createAndDisplayGO(id_cut)
35 gg.setDisplayMode(id_cut,1)
36 gg.createAndDisplayGO(id_result)
37 gg.setDisplayMode(id_result,1)

Download this script


Suppress Holes

1 # Suppress Holes
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create a vertex and a vector
11 p1 = geompy.MakeVertex(35, 35, 0)
12 p2 = geompy.MakeVertex(35, 35, 50)
13 v = geompy.MakeVector(p1, p2)
14 
15 # create a cylinder
16 height = 20
17 radius1 = 20
18 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
19 
20 # create a cone
21 cone = geompy.MakeCone(p1, v, 70, 0, 80)
22 
23 # make a cut
24 cut = geompy.MakeCut(cone, cylinder)
25 
26 # get faces as sub-shapes
27 faces = geompy.SubShapeAllSortedCentres(cut, geompy.ShapeType["FACE"])
28 f_2 = geompy.GetSubShapeID(cut, faces[2])
29 
30 # remove one face from the shape
31 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
32 
33 # get edges as sub-shapes
34 edges = geompy.SubShapeAllSortedCentres(faces[2], geompy.ShapeType["EDGE"])
35 edge = geompy.GetInPlace(cut_without_f_2, edges[0], True)
36 e_2 = geompy.GetSubShapeID(cut_without_f_2, edge)
37 
38 # suppress a hole using the selected edge
39 result = geompy.SuppressHoles(cut_without_f_2, [e_2])
40 
41 # add objects in the study
42 id_cut = geompy.addToStudy(cut, "Cut")
43 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
44 id_result = geompy.addToStudy(result, "Result")
45 
46 # display the results
47 gg.createAndDisplayGO(id_cut)
48 gg.setDisplayMode(id_cut,1)
49 gg.createAndDisplayGO(id_cut_without_f_2)
50 gg.setDisplayMode(id_cut_without_f_2,1)
51 gg.createAndDisplayGO(id_result)
52 gg.setDisplayMode(id_result,1)

Download this script


Sewing

1 # Sewing
2 
3 import salome, math
4 salome.salome_init()
5 from salome.geom import geomBuilder
6 
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create base points
11 px = geompy.MakeVertex(100., 0., 0.)
12 py = geompy.MakeVertex(0., 100., 0.)
13 pz = geompy.MakeVertex(0., 0., 100.)
14 
15 # create base geometry 2D
16 vector = geompy.MakeVector(px, py)
17 arc = geompy.MakeArc(py, pz, px)
18 
19 # create base objects
20 angle = 45. * math.pi / 180
21 WantPlanarFace = True
22 wire = geompy.MakeWire([vector, arc])
23 face = geompy.MakeFace(wire, WantPlanarFace)
24 face_rot = geompy.MakeRotation(face, vector, angle)
25 
26 # make sewing
27 precision = 0.00001
28 sewing = geompy.MakeSewing([face, face_rot], precision)
29 
30 # add objects in the study
31 id_face = geompy.addToStudy(face, "Face")
32 id_face_rot = geompy.addToStudy(face_rot, "Face rotation")
33 id_sewing = geompy.addToStudy(sewing, "Sewing")
34 
35 # display the results
36 gg.createAndDisplayGO(id_face)
37 gg.setDisplayMode(id_face,1)
38 gg.createAndDisplayGO(id_face_rot)
39 gg.setDisplayMode(id_face_rot,1)
40 gg.createAndDisplayGO(id_sewing)
41 gg.setDisplayMode(id_sewing,1)
42 
43 
44 # Example 2: make a shell of a multiply translated face
45 quad = geompy.MakeFaceHW( 10, 20, 1 )
46 quadCompound = geompy.MakeMultiTranslation1D( quad, geompy.MakeVectorDXDYDZ(1,0,0), 10, 3)
47 shell = geompy.Sew( quadCompound, 1e-6 )
48 
49 id_shell = geompy.addToStudy( shell, "3 quads shell")
50 gg.createAndDisplayGO(id_shell)

Download this script


Glue Faces

1 # Glue Faces
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create boxes
11 box1 = geompy.MakeBox(0,0,0,100,50,100)
12 box2 = geompy.MakeBox(100,0,0,250,50,100)
13 
14 # make compound
15 compound = geompy.MakeCompound([box1, box2])
16 
17 # glue compound's faces
18 tolerance = 1e-5
19 glue = geompy.MakeGlueFaces(compound, tolerance)
20 
21 # add objects in study
22 id_box1 = geompy.addToStudy(box1, "Box1")
23 id_box2 = geompy.addToStudy(box2, "Box2")
24 id_compound = geompy.addToStudy(compound, "Compound")
25 id_glue = geompy.addToStudy(glue, "Glue faces")
26 
27 # display results
28 gg.createAndDisplayGO(id_box1)
29 gg.setDisplayMode(id_box1,1)
30 gg.createAndDisplayGO(id_box2)
31 gg.setDisplayMode(id_box2,1)
32 gg.createAndDisplayGO(id_compound)
33 gg.setDisplayMode(id_compound,1)
34 gg.createAndDisplayGO(id_glue)
35 gg.setDisplayMode(id_glue,1)

Download this script


Glue Edges

1 # Glue Edges
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # create boxes
11 box1 = geompy.MakeBox(0,0,0,100,50,100)
12 box2 = geompy.MakeBox(100,0,0,250,50,100)
13 
14 # make compound
15 compound = geompy.MakeCompound([box1, box2])
16 
17 # glue all compound's edges
18 tolerance = 1e-5
19 glue1 = geompy.MakeGlueEdges(compound, tolerance)
20 
21 # glue some compound's edges
22 list_edges = geompy.GetGlueEdges(compound, tolerance)
23 glue2 = geompy.MakeGlueEdgesByList(compound, tolerance, [list_edges[0], list_edges[2]])
24 
25 # add objects in study
26 geompy.addToStudy(box1, "Box1")
27 geompy.addToStudy(box2, "Box2")
28 geompy.addToStudy(compound, "Compound")
29 geompy.addToStudy(glue1, "Glue all edges")
30 geompy.addToStudy(glue2, "Glue two edges")
31 
32 if salome.sg.hasDesktop():
33  salome.sg.updateObjBrowser(True)

Download this script


Limit Tolerance

1 # Limit Tolerance
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 gg = salome.ImportComponentGUI("GEOM")
9 
10 # import initial topology with bad tolerances (more than 1e-07)
11 shape1 = geompy.ImportBREP("my_shape_1.brep")
12 shape2 = geompy.ImportBREP("my_shape_2.brep")
13 
14 geompy.addToStudy(shape1, "Shape 1")
15 geompy.addToStudy(shape2, "Shape 2")
16 
17 # perform partition
18 try:
19  part = geompy.MakePartition([shape1, shape2])
20 except:
21  # limit tolerance
22  tolerance = 1e-07
23  shape1_lt = geompy.LimitTolerance(shape1, tolerance)
24  shape2_lt = geompy.LimitTolerance(shape2, tolerance)
25 
26  # process shape
27  good_shape1 = geompy.ProcessShape(shape1_lt, ["FixShape"], ["FixShape.Tolerance3d"], ["1e-7"])
28  good_shape2 = geompy.ProcessShape(shape2_lt, ["FixShape"], ["FixShape.Tolerance3d"], ["1e-7"])
29 
30  geompy.addToStudy(good_shape1, "Shape 1 corrected")
31  geompy.addToStudy(good_shape2, "Shape 2 corrected")
32 
33  # perform partition on corrected shapes
34  part = geompy.MakePartition([good_shape1, good_shape2])
35  pass
36 
37 geompy.addToStudy(part, "Partition")

Download this script


Add Point on Edge

1 # Add Point on Edge
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 # Variant 1: using DivideEdge()
10 
11 # create vertices
12 p1 = geompy.MakeVertex(0,0,50)
13 p2 = geompy.MakeVertex(60,0,50)
14 
15 # make an edge
16 edge = geompy.MakeEdge(p1, p2) #geompy.GetSubShape(box, edge_ind)
17 
18 # divide an edge
19 divide = geompy.DivideEdge(edge, -1, 0.5, 0)
20 
21 # add objects in the study
22 id_edge = geompy.addToStudy(edge, "Edge")
23 edge_points = geompy.SubShapeAllSortedCentres(edge, geompy.ShapeType["VERTEX"])
24 for point in edge_points:
25  geompy.addToStudyInFather(edge, point, "Edge's point")
26 
27 id_divide = geompy.addToStudy(divide, "Divided edge")
28 edge_points = geompy.SubShapeAllSortedCentres(divide, geompy.ShapeType["VERTEX"])
29 for point in edge_points:
30  geompy.addToStudyInFather(divide, point, "Edge's point after divide")
31 
32 
33 # Variant 2: using DivideEdgeByPoint()
34 
35 box = geompy.MakeBox(0,0,0, 10,10,10, theName="box")
36 p1 = geompy.MakeVertex( 3, -2, 1, theName="point 1 to project" )
37 p2 = geompy.MakeVertex( 7, -2, 1, theName="point 2 to project" )
38 edge = geompy.GetEdgeNearPoint( box, p1, theName="edge to split")
39 
40 div = geompy.DivideEdgeByPoint( box, edge, [p1, p2], theName="box (edge divided)")
41 
42 
43 salome.sg.updateObjBrowser(True)

Download this script


Fuse Collinear Edges within a Wire

1 # Fuse Collinear Edges within a Wire
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 # create vertices
10 p1 = geompy.MakeVertex(0, 0, 0)
11 p2 = geompy.MakeVertex(70, 0, 0)
12 p3 = geompy.MakeVertex(70, 50, 0)
13 p4 = geompy.MakeVertex(70, 80, 0)
14 p5 = geompy.MakeVertex(50, 80, 0)
15 p6 = geompy.MakeVertex(20, 80, 0)
16 p7 = geompy.MakeVertex(0, 80, 0)
17 p8 = geompy.MakeVertex(0, 30, 0)
18 
19 points = [p1, p2, p3, p4, p5, p6, p7, p8]
20 
21 # make a wire
22 wire_1 = geompy.MakePolyline(points, True)
23 
24 # suppress some vertices in the wire
25 wire_2 = geompy.FuseCollinearEdgesWithinWire(wire_1, [p3])
26 wire_3 = geompy.FuseCollinearEdgesWithinWire(wire_1, [p5, p6])
27 
28 # suppress all suitable vertices in the wire
29 wire_4 = geompy.FuseCollinearEdgesWithinWire(wire_1, [])
30 
31 wires = [wire_1, wire_2, wire_3, wire_4]
32 
33 # add objects in the study
34 ii = 1
35 for point in points:
36  geompy.addToStudy(point, "p%d"%ii)
37  ii = ii + 1
38  pass
39 
40 ii = 1
41 for wire in wires:
42  geompy.addToStudy(wire, "wire_%d"%ii)
43  wire_points = geompy.SubShapeAllSortedCentres(wire, geompy.ShapeType["VERTEX"])
44  jj = 1
45  for point in wire_points:
46  geompy.addToStudyInFather(wire, point, "point_%d"%jj)
47  jj = jj + 1
48  pass
49  ii = ii + 1
50  pass
51 
52 salome.sg.updateObjBrowser(True)

Download this script


Remove internal(shared) faces

1 # Remove internal(shared) faces from a compound
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 # create solids with some coincident faces
10 Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
11 Translation_1 = geompy.MakeTranslation(Box_1, 200, 0, 0)
12 Translation_2 = geompy.MakeTranslation(Box_1, 200, 200, 0)
13 
14 geompy.addToStudy(Box_1, 'Box_1')
15 geompy.addToStudy(Translation_1, 'Translation_1')
16 geompy.addToStudy(Translation_2, 'Translation_2')
17 
18 # partition three solids to obtain shared faces
19 Partition_1 = geompy.MakePartition([Box_1, Translation_1, Translation_2])
20 geompy.addToStudy(Partition_1, 'Partition_1')
21 
22 # remove shared faces to obtain one solid instead of three
23 Joined_1 = geompy.RemoveInternalFaces(Partition_1)
24 geompy.addToStudy(Joined_1, 'Joined_1')
25 
26 salome.sg.updateObjBrowser(True)

Download this script