"""
from model.roots import Interface
-
+from model import Selection
def addExtrusion(part, *args):
"""Add an Extrusion feature to the Part and return Extrusion.
Pass all args to Extrusion __init__ function.
"""
- assert(len(args) > 0 and args[0] is not None)
+ assert(args)
feature = part.addFeature("Extrusion")
return Extrusion(feature, *args)
class Extrusion(Interface):
"""Interface on an Extrusion feature."""
- def __init__(self, feature, base=None, *args):
+ def __init__(self, feature, *args):
"""Initialize an Extrusion feature with given parameters.
Expected arguments for all modes:
self._from_object = self._feature.data().selection("from_object")
self._from_offset = self._feature.data().real("from_offset")
- if base is None:
+ assert(self._base)
+ assert(self._CreationMethod)
+ assert(self._to_size)
+ assert(self._from_size)
+ assert(self._to_object)
+ assert(self._to_offset)
+ assert(self._from_object)
+ assert(self._from_offset)
+
+ if not args:
return
- self.__setBase(base)
+ self.setBase(args[0])
+
+ args = args[1:]
+ assert(len(args) in (1, 2, 4))
if len(args) == 4:
- self.__createByPlanesAndOffsets(*args)
+ self.setPlanesAndOffsets(*args)
elif len(args) == 2:
- self.__createBySizes(*args)
- else:
- raise AssertionError(
- "Extrusion takes 4 or 6 arguments (%s given)." % (len(args) + 2)
- )
-
- self.__execute()
- pass
-
- def __setBase(self, base):
- self._fill_attribute(self._base, base)
+ self.setSizes(*args)
+ elif len(args) == 1:
+ self.setSize(args[0])
pass
def __clear(self):
self._fill_attribute(self._from_offset, 0)
pass
- def __createBySizes(self, to_size, from_size):
- self.__clear()
- self._CreationMethod.setValue("BySizes")
- self._fill_attribute(self._to_size, to_size)
- self._fill_attribute(self._from_size, from_size)
- pass
-
- def __createByPlanesAndOffsets(self, to_object, to_offset,
- from_object, from_offset):
- self.__clear()
- self._CreationMethod.setValue("ByPlanesAndOffsets")
- self._fill_attribute(self._to_object, to_object)
- self._fill_attribute(self._to_offset, to_offset)
- self._fill_attribute(self._from_object, from_object)
- self._fill_attribute(self._from_offset, from_offset)
- pass
-
- def __execute(self):
- if self.areInputValid():
- self.execute()
- else:
- raise Exception("Cannot execute Extrusion: %s" %
- self._feature.error())
-
def setBase(self, base):
"""Modify base attribute of the feature.
See __init__.
"""
- self.__setBase(base)
- self.__execute()
+ self._fill_attribute(self._base, base)
pass
- def setSizes(self, *args):
+ def setSizes(self, to_size, from_size):
"""Modify the to_size, from_size attributes of the feature.
See __init__.
"""
- self.__createBySizes(*args)
- self.__execute()
+ self.__clear()
+ self._CreationMethod.setValue("BySizes")
+ self._fill_attribute(self._to_size, to_size)
+ self._fill_attribute(self._from_size, from_size)
pass
- def setPlanesAndOffsets(self, *args):
+ def setSize(self, size):
+ """Modify the size of the feature.
+
+ If size is positive then initialize to_size with size.
+ If size is negative then initialize from_size with -size.
+ """
+ to_size, from_size = 0, 0
+ if size >= 0:
+ to_size = size
+ else:
+ from_size = -size
+
+ self.setSizes(to_size, from_size)
+ pass
+
+ def setPlanesAndOffsets(self, to_object, to_offset,
+ from_object, from_offset):
"""Modify planes and offsets attributes of the feature.
See __init__.
"""
- self.__createByPlanesAndOffsets(*args)
- self.__execute()
+ self.__clear()
+ self._CreationMethod.setValue("ByPlanesAndOffsets")
+ self._fill_attribute(self._to_object, to_object)
+ self._fill_attribute(self._to_offset, to_offset)
+ self._fill_attribute(self._from_object, from_object)
+ self._fill_attribute(self._from_offset, from_offset)
pass
+
+ def result(self):
+ return [Selection(result, result.shape()) for result in (self.firstResult(),)]