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


Partition

1 # Partition
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 p0 = geompy.MakeVertex( 0., 0., 0.)
12 p200 = geompy.MakeVertex(200., 200., 200.)
13 pz = geompy.MakeVertex( 0., 0., 100.)
14 
15 # create a vector
16 vxyz = geompy.MakeVectorDXDYDZ(100., 100., 100.)
17 
18 # create a box from two points
19 box = geompy.MakeBoxTwoPnt(p0, p200)
20 
21 # create a plane
22 trimsize = 500.
23 plane = geompy.MakePlane(pz, vxyz, trimsize)
24 
25 # create partition
26 partition = geompy.MakePartition([box], [plane])
27 
28 # add objects in the study
29 id_box = geompy.addToStudy(box,"Box")
30 id_plane = geompy.addToStudy(plane,"Plane")
31 id_partition = geompy.addToStudy(partition,"Partition")
32 
33 # display the partition objects and the plane
34 gg.createAndDisplayGO(id_box)
35 gg.setDisplayMode(id_box,1)
36 gg.createAndDisplayGO(id_plane)
37 gg.setDisplayMode(id_plane,1)
38 gg.createAndDisplayGO(id_partition)

Download this script


Archimede

1 # Archimede
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 p0 = geompy.MakeVertex( 0., 0., 0.)
12 p200 = geompy.MakeVertex(200., 200., 200.)
13 
14 # create a box from two points
15 box = geompy.MakeBoxTwoPnt(p0, p200)
16 
17 # perform an Archimede operation on the selected shape with selected parameters
18 weight = 1000000.
19 waterdensity = 1.
20 meshingdeflection = 0.01
21 archimede = geompy.Archimede(box, weight, waterdensity, meshingdeflection)
22 
23 # add objects in the study
24 id_box = geompy.addToStudy(box,"Box")
25 id_archimede = geompy.addToStudy(archimede,"Archimede")
26 
27 # display the box and the result of Archimede operation
28 gg.createAndDisplayGO(id_box)
29 gg.setDisplayMode(id_box,1)
30 gg.createAndDisplayGO(id_archimede)
31 gg.setDisplayMode(id_archimede,1)

Download this script


Restore presentation parameters and sub-shapes

1 # Restore presentation parameters and sub-shapes
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 import SALOMEDS
9 
10 # create a box and a cylinder
11 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
12 cyl = geompy.MakeCylinderRH(100, 300)
13 
14 # create translated box
15 vec = geompy.MakeVectorDXDYDZ(100, 50, 0)
16 tra = geompy.MakeTranslationVector(box, vec)
17 
18 # create partition objects
19 partition1 = geompy.MakePartition([box, cyl])
20 partition2 = geompy.MakePartition([box], [cyl])
21 partition3 = geompy.MakePartition([box], [tra])
22 
23 # set colours
24 box.SetColor(SALOMEDS.Color(1,0,0))
25 cyl.SetColor(SALOMEDS.Color(0,1,0))
26 
27 # add objects in the study
28 geompy.addToStudy(box, "Box")
29 geompy.addToStudy(cyl, "Cylinder")
30 geompy.addToStudy(vec, "Vector")
31 geompy.addToStudy(tra, "Translation")
32 geompy.addToStudy(partition1, "Partition_1")
33 geompy.addToStudy(partition2, "Partition_2")
34 geompy.addToStudy(partition3, "Partition_3")
35 
36 # Restore presentation parameters and sub-shapes
37 # different methods can be used to find the sub-shapes in the result:
38 # GetInPlace, GetSame, GetInPlaceByHistory, GetShapesOnShape.
39 # By default, GetInPlace method is used (GEOM.FSM_GetInPlace)
40 geompy.RestoreSubShapes(partition1)
41 
42 geompy.RestoreSubShapes(partition2, [], GEOM.FSM_GetInPlace)
43 
44 # The list of arguments can be used to avoid restoring all arguments,
45 # but restore only the passed.
46 geompy.RestoreSubShapes(partition3, [tra], GEOM.FSM_GetInPlaceByHistory)
47 
48 # To find sub-shapes in a transformed shape only one method could be
49 # used: pass GEOM.FSM_Transformed for that.
50 # True passed for the last argument, means that the transformed shape
51 # will inherit colour and sub-shapes from its first argument (see above
52 # MakeTranslation).
53 geompy.RestoreSubShapes(tra, [], GEOM.FSM_Transformed, True)
54 
55 # Also we could do this directly with method addToStudy:
56 partition4 = geompy.MakePartition([box, tra])
57 geompy.addToStudy(partition4, "Partition_4", True, [],
58  GEOM.FSM_GetInPlaceByHistory, False)

Download this script


Get shared shapes

1 # Get shared sub-shapes
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 import SALOMEDS
9 
10 # create a box and partigion it by two planes
11 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
12 p = geompy.MakeVertex(100, 100, 100)
13 v1 = geompy.MakeVectorDXDYDZ(1, 1, 0)
14 v2 = geompy.MakeVectorDXDYDZ(1, -1, 0)
15 pln1 = geompy.MakePlane(p, v1, 2000)
16 pln2 = geompy.MakePlane(p, v2, 2000)
17 partition = geompy.MakePartition([box], [pln1, pln2])
18 
19 # extract solids from result of partition
20 solids = geompy.SubShapeAllSorted(partition, geompy.ShapeType['SOLID'])
21 
22 # get shared shapes from the partition (compound of 4 solids)
23 # a) faces that are shared by all 4 solids (0 found)
24 pF_T = geompy.GetSharedShapesMulti(partition, geompy.ShapeType['FACE'])
25 # b) faces that are shared by any couple of solids (4 found)
26 pF_F = geompy.GetSharedShapesMulti(partition, geompy.ShapeType['FACE'], False)
27 # c) edges that are shared by all 4 solids (1 found)
28 pE_T = geompy.GetSharedShapesMulti(partition, geompy.ShapeType['EDGE'])
29 # d) edges that are shared by any couple of solids (13 found)
30 pE_F = geompy.GetSharedShapesMulti(partition, geompy.ShapeType['EDGE'], False)
31 
32 # get shared shapes from the list of solids
33 # a) faces that are shared by all 4 solids (0 found)
34 sF_T = geompy.GetSharedShapesMulti(solids, geompy.ShapeType['FACE'])
35 # b) faces that are shared by 1st/2nd, 1st/3rd and 1st/4th solids (2 found)
36 sF_F = geompy.GetSharedShapesMulti(solids, geompy.ShapeType['FACE'], False)
37 # c) edges that are shared by all 4 solids (1 found)
38 sE_T = geompy.GetSharedShapesMulti(solids, geompy.ShapeType['EDGE'])
39 # d) edges that are shared by 1st/2nd, 1st/3rd and 1st/4th solids (7 found)
40 sE_F = geompy.GetSharedShapesMulti(solids, geompy.ShapeType['EDGE'], False)

Download this script