Salome HOME
bos #29468: Advanced geometry features: distance Edge-Edge & Face-Face
[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 # import BREP file
49 sphere_brep = geompy.ImportBREP(f_brep)
50
51 # import IGES file
52 sphere_iges = geompy.ImportIGES(f_iges)
53
54 # import STEP file, taking units into account
55 sphere_step1 = geompy.ImportSTEP(f_step)
56
57 # import STEP file, ignoring units (result is scaled)
58 sphere_step2 = geompy.ImportSTEP(f_step, True)
59
60 # import STL files
61 sphere_stl1 = geompy.ImportSTL(f_stl1)
62 sphere_stl2 = geompy.ImportSTL(f_stl2)
63
64 # import XAO file
65 ok, sphere_xao, sub_shapes, groups, fields = geompy.ImportXAO(f_xao)
66
67 # clean up
68 for f in f_brep, f_iges, f_step, f_stl1, f_stl2, f_vtk1, f_vtk2, f_xao:
69   os.remove(f)
70 os.rmdir(tmpdir)