Export File

 1from salome.shaper import model
 2
 3model.begin()
 4partSet = model.moduleDocument()
 5Part_1 = model.addPart(partSet)
 6Part_1_doc = Part_1.document()
 7Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
 8Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
 9Export_1 = model.exportPart(Part_1_doc, "~/box.shaperpart", [model.selection("SOLID", "Box_1_1")])
10model.end()

Download this script

Save Session

 1# Copyright (C) 2021-2026  CEA, EDF
 2#
 3# This library is free software; you can redistribute it and/or
 4# modify it under the terms of the GNU Lesser General Public
 5# License as published by the Free Software Foundation; either
 6# version 2.1 of the License, or (at your option) any later version.
 7#
 8# This library is distributed in the hope that it will be useful,
 9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11# Lesser General Public License for more details.
12#
13# You should have received a copy of the GNU Lesser General Public
14# License along with this library; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16#
17# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18#
19
20import os
21from salome.shaper import model
22
23from tempfile import TemporaryDirectory
24from ModelAPI import *
25from GeomAPI import GeomAPI_Shape
26import PrimitivesAPI
27
28model.begin()
29partSet = model.moduleDocument()
30
31### Create Part 1
32Part_1 = model.addPart(partSet)
33Part_1_doc = Part_1.document()
34Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
35
36### Create Part 2
37Part_2 = model.addPart(partSet)
38Part_2_doc = Part_2.document()
39Cyl_1 = model.addCylinder(Part_2_doc, 10, 13)
40
41model.end()
42
43model.checkResult(Box_1, model, 1, [0], [1], [6], [24], [48])
44model.testResultsVolumes(Box_1, [1000])
45model.checkResult(Cyl_1, model, 1, [0], [1], [3],  [6], [12])
46model.testResultsVolumes(Cyl_1, [4084.07045])
47
48# Save/load document
49with TemporaryDirectory() as tmp_dir:
50  aSession = ModelAPI_Session.get()
51
52  # Save
53  aFiles = StringList()
54  aSession.save(tmp_dir, aFiles)
55
56  # Close and Load again
57  aSession.closeAll()
58  assert(aSession.load(tmp_dir))
59
60  # Check data
61  partSet = aSession.moduleDocument()
62  assert(partSet.size("Parts") == 2)
63
64  # Access data of Part 1
65  aPart1 = modelAPI_ResultPart(objectToResult(partSet.object("Parts", 0)))
66  aSession.startOperation()
67  aPart1.activate()
68  aSession.finishOperation()
69  aPart1Doc = aPart1.partDoc()
70  aBoxF = objectToFeature(aPart1Doc.objectByName("Features", "Box_1"))
71  aBox = PrimitivesAPI.PrimitivesAPI_Box(aBoxF)
72  model.checkResult(aBox, model, 1, [0], [1], [6], [24], [48])
73  model.testResultsVolumes(aBox, [1000])
74
75  aSession.startOperation()
76  aSession.setActiveDocument(partSet)
77  aSession.finishOperation()
78
79  # Access data of Part 2
80  aPart2 = modelAPI_ResultPart(objectToResult(partSet.object("Parts", 1)))
81  aSession.startOperation()
82  aPart2.activate()
83  aSession.finishOperation()
84  aPart2Doc = aPart2.partDoc()
85  aCylF = objectToFeature(aPart2Doc.objectByName("Features", "Cylinder_1"))
86  aCyl = PrimitivesAPI.PrimitivesAPI_Cylinder(aCylF)
87  model.checkResult(aCyl, model, 1, [0], [1], [3], [6], [12])
88  model.testResultsVolumes(aCyl, [4084.07045])

Download this script