2 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
4 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
7 from model.roots import Interface
10 def addExtrusion(part, *args):
11 """Add an Extrusion feature to the Part and return Extrusion.
13 Pass all args to Extrusion __init__ function.
15 assert(len(args) > 0 and args[0] is not None)
16 feature = part.addFeature("Extrusion")
17 return Extrusion(feature, *args)
20 class Extrusion(Interface):
21 """Interface on an Extrusion feature."""
23 def __init__(self, feature, base=None, *args):
24 """Initialize an Extrusion feature with given parameters.
26 Expected arguments for all modes:
27 feature -- an Extrusion feature
29 Expected arguments for initializing the feature:
30 base -- name, sketch or list of names and sketches.
31 If base is None then don't change the feature.
33 For BySize mode (expect 2 arguments):
35 from_size -- lower size
37 For ByPlanesAndOffsets mode (expect 4 arguments):
38 to_object -- upper object (plane)
39 to_offset -- offset from upper object
40 from_object -- lower object (plane)
41 from_offset -- offset from lower object
43 Interface.__init__(self, feature)
44 assert(self._feature.getKind() == "Extrusion")
46 self._base = self._feature.data().selectionList("base")
47 self._CreationMethod = self._feature.string("CreationMethod")
48 self._to_size = self._feature.data().real("to_size")
49 self._from_size = self._feature.data().real("from_size")
50 self._to_object = self._feature.data().selection("to_object")
51 self._to_offset = self._feature.data().real("to_offset")
52 self._from_object = self._feature.data().selection("from_object")
53 self._from_offset = self._feature.data().real("from_offset")
61 self.__createByPlanesAndOffsets(*args)
63 self.__createBySizes(*args)
66 "Extrusion takes 4 or 6 arguments (%s given)." % (len(args) + 2)
72 def __setBase(self, base):
73 self._fill_attribute(self._base, base)
77 self._CreationMethod.setValue("BySizes")
78 self._fill_attribute(self._to_size, 0)
79 self._fill_attribute(self._from_size, 0)
80 self._fill_attribute(self._to_object, None)
81 self._fill_attribute(self._to_offset, 0)
82 self._fill_attribute(self._from_object, None)
83 self._fill_attribute(self._from_offset, 0)
86 def __createBySizes(self, to_size, from_size):
88 self._CreationMethod.setValue("BySizes")
89 self._fill_attribute(self._to_size, to_size)
90 self._fill_attribute(self._from_size, from_size)
93 def __createByPlanesAndOffsets(self, to_object, to_offset,
94 from_object, from_offset):
96 self._CreationMethod.setValue("ByPlanesAndOffsets")
97 self._fill_attribute(self._to_object, to_object)
98 self._fill_attribute(self._to_offset, to_offset)
99 self._fill_attribute(self._from_object, from_object)
100 self._fill_attribute(self._from_offset, from_offset)
104 if self.areInputValid():
107 raise Exception("Cannot execute Extrusion: %s" %
108 self._feature.error())
110 def setBase(self, base):
111 """Modify base attribute of the feature.
119 def setSizes(self, *args):
120 """Modify the to_size, from_size attributes of the feature.
124 self.__createBySizes(*args)
128 def setPlanesAndOffsets(self, *args):
129 """Modify planes and offsets attributes of the feature.
133 self.__createByPlanesAndOffsets(*args)