Salome HOME
3b5f7df60a753f1ae4c6bec0749b41bdc3cce37a
[modules/geom.git] / doc / salome / examples / import_export.py
1 # Import/Export
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 # Example of import from IGES using various formats
10
11 # get a path to SAMPLES_SRC
12 import os
13 thePath = os.getenv("DATA_DIR")
14 # create filenames
15 theFileName1 = thePath + "/Shapes/Iges/boite-3Dipsos_m.igs"
16 theFileName2 = thePath + "/Shapes/Iges/boite-3Dipsos_mm.igs"
17 #print "thePath = ", thePath
18
19 # get units from files
20 UnitName1 = geompy.GetIGESUnit(theFileName1)
21 UnitName2 = geompy.GetIGESUnit(theFileName2)
22 print "UnitName1 = ", UnitName1
23 print "UnitName2 = ", UnitName2
24
25 # import shapes
26 Shape1 = geompy.ImportIGES(theFileName1)
27 Shape2 = geompy.ImportIGES(theFileName2)
28 Shape3 = geompy.ImportIGES(theFileName2, True)
29 [Xmin1,Xmax1, Ymin1,Ymax1, Zmin1,Zmax1] = geompy.BoundingBox(Shape1)
30 [Xmin2,Xmax2, Ymin2,Ymax2, Zmin2,Zmax2] = geompy.BoundingBox(Shape2)
31 [Xmin3,Xmax3, Ymin3,Ymax3, Zmin3,Zmax3] = geompy.BoundingBox(Shape3)
32 geompy.addToStudy(Shape1, "3Dipsos_m")
33 geompy.addToStudy(Shape2, "3Dipsos_mm")
34 geompy.addToStudy(Shape3, "3Dipsos_mm_scaled")
35 d1 = (Xmax1-Xmin1)*(Xmax1-Xmin1) + (Ymax1-Ymin1)*(Ymax1-Ymin1) + (Zmax1-Zmin1)*(Zmax1-Zmin1)
36 d2 = (Xmax2-Xmin2)*(Xmax2-Xmin2) + (Ymax2-Ymin2)*(Ymax2-Ymin2) + (Zmax2-Zmin2)*(Zmax2-Zmin2)
37 d3 = (Xmax3-Xmin3)*(Xmax3-Xmin3) + (Ymax3-Ymin3)*(Ymax3-Ymin3) + (Zmax3-Zmin3)*(Zmax3-Zmin3)
38 import math
39 dd32 = math.sqrt(d3/d2)
40 dd12 = math.sqrt(d1/d2)
41 dd31 = math.sqrt(d3/d1)
42 # values dd31, dd12 and dd31 can be using for checking
43 print "dd32 = ",dd32,"  dd12 = ",dd12,"  dd31 = ",dd31