Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Geometrical Fields
1 # Geom Field
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 # a box
11 shape = geompy.MakeBoxDXDYDZ( 1, 1, 1, theName="box")
12 
13 # Create fields holding sub-shape IDs as strings,
14 # which can be useful to see sub-shape IDs in the Viewer
15 
16 componentNames = ['ID']
17 fieldDataType = GEOM.FDT_String
18 stepID = 0
19 stamp = 0
20 
21 dim = 0 # == vertices
22 values = [str(i) for i in geompy.SubShapeAllIDs( shape, geompy.ShapeType["VERTEX"] )]
23 f0 = geompy.CreateField( shape, "vertices", fieldDataType, dim, componentNames )
24 s0 = f0.addStep( stepID, stamp, values )
25 geompy.addToStudyInFather( shape, f0, f0.GetName() )
26 s0id = geompy.addToStudyInFather( f0, s0, s0.GetName() )
27 
28 dim = 1 # == edges
29 values = [str(i) for i in geompy.SubShapeAllIDs( shape, geompy.ShapeType["EDGE"] )]
30 f1 = geompy.CreateField( shape, "edges", fieldDataType, dim, componentNames )
31 s1 = f1.addStep( stepID, stamp, values )
32 geompy.addToStudyInFather( shape, f1, f1.GetName() )
33 geompy.addToStudyInFather( f1, s1, s1.GetName() )
34 
35 dim = 2 # == faces
36 values = [str(i) for i in geompy.SubShapeAllIDs( shape, geompy.ShapeType["FACE"] )]
37 f2 = geompy.CreateField( shape, "faces", fieldDataType, dim, componentNames )
38 s2 = f2.addStep( stepID, stamp, values )
39 geompy.addToStudyInFather( shape, f2, f2.GetName() )
40 geompy.addToStudyInFather( f2, s2, s2.GetName() )
41 
42 dim = 3 # == solids
43 values = [str(i) for i in geompy.SubShapeAllIDs( shape, geompy.ShapeType["SOLID"] )]
44 f3 = geompy.CreateField( shape, "solids", fieldDataType, dim, componentNames )
45 s3 = f3.addStep( stepID, stamp, values )
46 geompy.addToStudyInFather( shape, f3, f3.GetName() )
47 geompy.addToStudyInFather( f3, s3, s3.GetName() )
48 
49 dim = -1 # == whole shape
50 f_1 = geompy.CreateField( shape, "whole shape", fieldDataType, dim, componentNames )
51 s_1 = f_1.addStep(stepID, stamp, ["1"])
52 geompy.addToStudyInFather( shape, f_1, f_1.GetName() )
53 geompy.addToStudyInFather( f_1, s_1, s_1.GetName() )
54 
55 # display
56 gg.createAndDisplayGO( s0id )

Download this script