]> SALOME platform Git repositories - modules/geom.git/blob - doc/salome/examples/import_export.py
Salome HOME
[bos #42424] [CEA][FORUM] bug with MinDistance in Geom Module. Old workarounds causin...
[modules/geom.git] / doc / salome / examples / import_export.py
1 # Import/Export
2
3 import salome
4 salome.salome_init_without_session()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8
9 import tempfile, os
10
11 # create a sphere
12 sphere = geompy.MakeSphereR(100)
13
14 tmpdir = tempfile.mkdtemp()
15
16 # export sphere to the BREP file
17 f_brep = os.path.join(tmpdir, "sphere.brep")
18 geompy.ExportBREP(sphere, f_brep)
19
20 # export sphere to the IGES v5.3 file
21 f_iges = os.path.join(tmpdir, "sphere.iges")
22 geompy.ExportIGES(sphere, f_iges, "5.3")
23
24 # export sphere to the STEP file, using millimeters as length units
25 f_step = os.path.join(tmpdir, "sphere.step")
26 geompy.ExportSTEP(sphere, f_step, GEOM.LU_MILLIMETER)
27
28 # export sphere to the binary STL file, with default deflection coefficient
29 f_stl1 = os.path.join(tmpdir, "sphere1.stl")
30 geompy.ExportSTL(sphere, f_stl1, False)
31
32 # export sphere to the ASCII STL file, with custom deflection coefficient
33 f_stl2 = os.path.join(tmpdir, "sphere2.stl")
34 geompy.ExportSTL(sphere, f_stl2, True, 0.1)
35
36 # export sphere to the VTK file, with default deflection coefficient
37 f_vtk1 = os.path.join(tmpdir, "sphere1.vtk")
38 geompy.ExportVTK(sphere, f_vtk1)
39
40 # export sphere to the VTK file, with custom deflection coefficient
41 f_vtk2 = os.path.join(tmpdir, "sphere2.vtk")
42 geompy.ExportVTK(sphere, f_vtk2, 0.1)
43
44 # export sphere to the XAO file
45 f_xao = os.path.join(tmpdir, "sphere.xao")
46 geompy.ExportXAO(sphere, [], [], "author", f_xao)
47
48 # export sphere to XAO format memory buffer (bytes array)
49 buff_xao = geompy.ExportXAOMem(sphere, [], [], "author")
50
51 # import BREP file
52 sphere_brep = geompy.ImportBREP(f_brep)
53
54 # import IGES file
55 sphere_iges = geompy.ImportIGES(f_iges)
56
57 # import STEP file, taking units into account
58 sphere_step1 = geompy.ImportSTEP(f_step)
59
60 # import STEP file, ignoring units (result is scaled)
61 sphere_step2 = geompy.ImportSTEP(f_step, True)
62
63 # import STL files
64 sphere_stl1 = geompy.ImportSTL(f_stl1)
65 sphere_stl2 = geompy.ImportSTL(f_stl2)
66
67 # import XAO file
68 ok, sphere_xao, sub_shapes, groups, fields = geompy.ImportXAO(f_xao)
69
70 # import XAO data from memory buffer (bytes array)
71 ok_mem, sphere_xao_mem, sub_shapes_mem, groups_mem, fields_mem = geompy.ImportXAOMem(buff_xao)
72
73 # clean up
74 for f in f_brep, f_iges, f_step, f_stl1, f_stl2, f_vtk1, f_vtk2, f_xao:
75   os.remove(f)
76 os.rmdir(tmpdir)