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