from macros.box.feature import BoxFeature as MY
-def addBox(container, *args):
- feature = container.addFeature(MY.ID())
+def addBox(part, *args):
+ """Add Box feature to the part and return Box.
+
+ Pass all args to Box __init__ function.
+ """
+ feature = part.addFeature(MY.ID())
return Box(feature, *args)
class Box(Interface):
- """Executes the macro-feature Box."""
+ """Executes the macro-feature Box.
+
+ Box(feature) -> feature interface without initialization
+ Extrusion(feature, dx, dy, dz) ->
+ feature interface initialized from arguments:
+ - dx, dy, dz -- box dimensions
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == MY.ID())
pass
def setWidth(self, width):
+ """B.setWidth(float) -- modify width attribute"""
self._fill_attribute(self._width, width)
pass
def setLength(self, length):
+ """B.setLength(float) -- modify length attribute"""
self._fill_attribute(self._length, length)
pass
def setHeight(self, height):
+ """B.setHeight(float) -- modify height attribute"""
self._fill_attribute(self._height, height)
pass
# Built-in features
from sketcher.sketch import addSketch
+from connection import *
from construction import *
from exchange import *
from features import *
class Axis(Interface):
- """Interface on an Axis feature."""
+ """Interface class for Axis feature.
+
+ Axis(feature) -> feature interface without initialization
+ Axis(feature, p1, p2) ->
+ feature interface initialized from arguments:
+ - p1 -- FirstPoint
+ - p2 -- SecondPoint
+ Axis(feature, face) ->
+ feature interface initialized from arguments:
+ - face -- CylindricalFace
+ """
def __init__(self, feature, *args):
- """Initialize an Axis feature with given parameters.
-
- Expected arguments for all modes:
- feature -- a Axis feature
-
- For AxisByPointsCase mode (expect 2 arguments):
- p1 -- FirstPoint
- p2 -- SecondPoint
-
- For AxisByCylindricalFaceCase mode (expect 1 argument):
- face -- CylindricalFace
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Axis")
class Plane(Interface):
- """Interface on a Plane feature."""
+ """Interface class for Plane feature.
+
+ Plane(feature) -> feature interface without initialization
+ Plane(feature, face, distance) ->
+ feature interface initialized from arguments:
+ - face -- planeFace
+ - distance -- distance
+ Plane(feature, a, b, c, d) ->
+ feature interface initialized from arguments:
+ - A, B, C, D -- GeneralEquation parameters
+ """
def __init__(self, feature, *args):
- """Initialize a Plane feature with given parameters.
-
- Expected arguments for all modes:
- feature -- a Plane feature
-
- For PlaneByFaceAndDistance mode (expect 2 arguments):
- face -- planeFace
- distance -- distance
-
- For PlaneByGeneralEquation mode (expect 4 arguments):
- A, B, C, D -- GeneralEquation parameters
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Plane")
class Point(Interface):
- """Interface on an Point feature."""
+ """Interface class for Point feature.
- def __init__(self, feature, *args):
- """Initialize an Point feature with given parameters.
-
- Expected arguments for all modes:
- feature -- a Point feature
+ Point(feature) -> feature interface without initialization
+ Point(feature, x, y, z) ->
+ feature interface initialized from arguments:
+ - x, y, z -- coordinates for the point
+ """
- Expected arguments for initializing the feature:
- x, y, z -- x, y, z coordinates for the point.
- """
+ def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Point")
class Import(Interface):
- """Interface on an Import feature."""
+ """Interface class for Import feature.
- def __init__(self, feature, *args):
- """Initialize an Import feature with given parameters.
-
- Expected arguments for all modes:
- feature -- an Import feature
+ Import(feature) -> feature interface without initialization
+ Import(feature, file_path) ->
+ feature interface initialized from arguments:
+ - file_path -- path to the imported file
+ """
- For initialization (expect 1 argument):
- file_path -- path to the imported file
- """
+ def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Import")
class Export(Interface):
- """Interface on an Export feature."""
+ """Interface class for Export feature.
+
+ Export(feature) -> feature interface without initialization
+ Export(feature, file_path, file_format, selection_list) ->
+ feature interface initialized from arguments:
+ - file_path -- path to the exported file
+ - file_format -- format of to the exported file
+ - selection_list -- objects to export
+ """
def __init__(self, feature, *args):
- """Initialize an Export feature with given parameters.
-
- Expected arguments for all modes:
- feature -- an Export feature
-
- For initialization (expect 3 argument):
- file_path -- path to the exported file
- file_format -- format of to the exported file
- objects -- objects to export
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Export")
class Boolean(Interface):
- """Abstract root class of Boolean Features."""
+ """Interface class for Boolean features.
+
+ Boolean(feature) -> feature interface without initialization
+ Boolean(feature, main_objects, tool_objects, bool_type) ->
+ feature interface initialized from arguments
+ """
+
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Boolean")
pass
def setMainObjects(self, main_objects):
+ """F.setMainObjects(iterable) -- modify main_objects attribute"""
self._fill_attribute(self._main_objects, main_objects)
pass
def setToolObjects(self, tool_objects):
+ """F.setToolObjects(iterable) -- modify tool_objects attribute"""
self._fill_attribute(self._tool_objects, tool_objects)
pass
def setBoolType(self, bool_type):
+ """F.setBoolType(integer) -- modify bool_type attribute.
+
+ Available types:
+ - GeomAlgoAPI_Boolean.BOOL_FUSE
+ - GeomAlgoAPI_Boolean.BOOL_CUT
+ - GeomAlgoAPI_Boolean.BOOL_COMMON
+ """
self._fill_attribute(self._bool_type, bool_type)
pass
class Extrusion(Interface):
- """Interface on an Extrusion feature."""
+ """Interface class for Extrusion feature.
+
+ Extrusion(feature) -> feature interface without initialization
+ Extrusion(feature, base, size) ->
+ feature interface initialized from arguments:
+ - base -- name, sketch or list of names and sketches
+ - size -- if positive -> to_size, if negative -> from_size
+ Extrusion(feature, base, to_size, from_size) ->
+ feature interface initialized from arguments:
+ - base -- name, sketch or list of names and sketches
+ - to_size -- upper size
+ - from_size -- lower size
+ Extrusion(feature, base, to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - base -- name, sketch or list of names and sketches
+ - to_object -- upper object (plane)
+ - to_offset -- offset from upper object
+ - from_object -- lower object (plane)
+ - from_offset -- offset from lower object
+ """
def __init__(self, feature, *args):
- """Initialize an Extrusion feature with given parameters.
-
- Expected arguments for all modes:
- feature -- an Extrusion feature
-
- Expected arguments for initializing the feature:
- base -- name, sketch or list of names and sketches.
- If base is None then don't change the feature.
-
- For BySize mode (expect 2 arguments):
- to_size -- upper size
- from_size -- lower size
-
- For ByPlanesAndOffsets mode (expect 4 arguments):
- to_object -- upper object (plane)
- to_offset -- offset from upper object
- from_object -- lower object (plane)
- from_offset -- offset from lower object
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Extrusion")
See __init__.
"""
self.__clear()
- self._CreationMethod.setValue("BySizes")
+ self._fill_attribute(self._CreationMethod, "BySizes")
self._fill_attribute(self._to_size, to_size)
self._fill_attribute(self._from_size, from_size)
pass
pass
def result(self):
+ """F.result() -> list of Selection objects"""
return [Selection(result, result.shape()) for result in (self.firstResult(),)]
class ExtrusionBoolean(CompositeBoolean):
+ """Interface class for ExtrusionBoolean features.
+
+ Supported features:
+ - ExtrusionCut
+ - ExtrusionFuse
+
+ ExtrusionBoolean(feature) -> feature interface without initialization
+ ExtrusionBoolean(feature,
+ sketch, sketch_selection, boolean_objects,
+ to_size, from_size) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - boolean_objects
+ - to_size
+ - from_size
+ ExtrusionBoolean(feature,
+ sketch, sketch_selection, boolean_objects,
+ to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - boolean_objects
+ - to_object
+ - to_offset
+ - from_object
+ - from_offset
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
CompositeBoolean.__init__(self, feature, *args[:3])
args = args[3:]
class ExtrusionSketch(CompositeSketch):
-
+ """Interface class for ExtrusionSketch feature.
+
+ ExtrusionSketch(feature) -> feature interface without initialization
+ ExtrusionSketch(feature,
+ sketch, sketch_selection,
+ to_size, from_size) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - to_size
+ - from_size
+ ExtrusionSketch(feature,
+ sketch, sketch_selection,
+ to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - to_object
+ - to_offset
+ - from_object
+ - from_offset
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
CompositeSketch.__init__(self, feature, *args[:2])
args = args[2:]
class Group(Interface):
+ """Interface class for Group feature.
+
+ Group(feature) -> feature interface without initialization
+ Group(feature, group_list) ->
+ feature interface initialized from arguments:
+ - group_list
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Group")
class Partition(Interface):
- """Interface on an Partition feature."""
+ """Interface class for Partition feature.
+
+ Partition(feature) -> feature interface without initialization
+ Partition(feature, main_objects, tool_objects, partition_combine) ->
+ feature interface initialized from arguments:
+ - main_objects -- list of solids
+ - tool_objects -- list of solids
+ - partition_combine -- boolean value
+ """
def __init__(self, feature, *args):
- """Initialize an Partition feature with given parameters.
-
- Expected arguments:
- feature -- an Partition feature
-
- Expected arguments for initializing the feature:
- main_objects -- list of solids.
- tool_objects -- list of solids.
- partition_combine -- boolean value.
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Partition")
class Placement(Interface):
+ """Interface class for Placement feature.
+
+ Placement(feature) -> feature interface without initialization
+ Placement(feature, objects_list, start_shape, end_shape,
+ reverse_direction, centering) ->
+ feature interface initialized from arguments:
+ - objects_list
+ - start_shape
+ - end_shape
+ - reverse_direction
+ - centering
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Placement")
class Revolution(Interface):
- """Interface on an Revolution feature."""
+ """Interface class for Revolution features.
+
+ Revolution(feature) -> feature interface without initialization
+ Revolution(feature, base, axis_object, to_angle, from_angle) ->
+ feature interface initialized from arguments:
+ - base -- name, sketch or list of names and sketches
+ - axis_object -- name, edge for axis
+ - to_angle -- upper angle
+ - from_angle -- lower angle
+ Revolution(feature, base, axis_object,
+ to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - base -- name, sketch or list of names and sketches
+ - axis_object -- name, edge for axis
+ - to_object -- upper object (plane)
+ - to_offset -- offset from upper object
+ - from_object -- lower object (plane)
+ - from_offset -- offset from lower object
+ """
def __init__(self, feature, *args):
- """Initialize an Revolution feature with given parameters.
-
- Expected arguments for all modes:
- feature -- an Revolution feature
-
- Expected arguments for initializing the feature:
- base -- name, sketch or list of names and sketches.
- If base is None then don't change the feature.
- axis_object -- name, edge for axis
-
- For ByAngles mode (expect 2 arguments):
- to_angle -- upper angle
- from_angle -- lower angle
-
- For ByPlanesAndOffsets mode (expect 4 arguments):
- to_object -- upper object (plane)
- to_offset -- offset from upper object
- from_object -- lower object (plane)
- from_offset -- offset from lower object
- """
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Revolution")
class RevolutionBoolean(CompositeBoolean):
+ """Interface class for RevolutionBoolean features.
+
+ Supported features:
+ - RevolutionCut
+ - RevolutionFuse
+
+ RevolutionBoolean(feature) -> feature interface without initialization
+ RevolutionBoolean(feature,
+ sketch, sketch_selection, boolean_objects,
+ to_angle, from_angle) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - boolean_objects
+ - to_angle
+ - from_angle
+ RevolutionBoolean(feature,
+ sketch, sketch_selection, boolean_objects,
+ to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - boolean_objects
+ - to_object
+ - to_offset
+ - from_object
+ - from_offset
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
CompositeBoolean.__init__(self, feature, *args[:3])
args = args[3:]
class RevolutionSketch(CompositeSketch):
+ """Interface class for RevolutionSketch features.
+
+ RevolutionSketch(feature) -> feature interface without initialization
+ RevolutionSketch(feature,
+ sketch, sketch_selection,
+ to_angle, from_angle) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - to_angle
+ - from_angle
+ RevolutionSketch(feature,
+ sketch, sketch_selection,
+ to_object, to_offset, from_object, from_offset) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - to_object
+ - to_offset
+ - from_object
+ - from_offset
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
CompositeSketch.__init__(self, feature, *args[:2])
args = args[2:]
class CompositeBoolean(Interface):
+ """Interface class for CompositeBoolean features.
+
+ CompositeBoolean(feature) -> feature interface without initialization
+ CompositeBoolean(feature, sketch, sketch_selection, boolean_objects) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ - boolean_objects
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
self._sketch = self._feature.reference("sketch")
pass
def setSketch(self, sketch):
+ """Modify sketch attribute"""
self._fill_attribute(self._sketch, sketch)
pass
def setSketchSelection(self, sketch_selection):
+ """Modify sketch_selection attribute"""
self._fill_attribute(self._sketch_selection, sketch_selection)
pass
def setBooleanObjects(self, boolean_objects):
+ """Modify boolean_objects attribute"""
self._fill_attribute(self._boolean_objects, boolean_objects)
pass
class CompositeSketch(Interface):
+ """Interface class for CompositeSketch features.
+
+ CompositeSketch(feature) -> feature interface without initialization
+ CompositeSketch(feature, sketch, sketch_selection) ->
+ feature interface initialized from arguments:
+ - sketch
+ - sketch_selection
+ """
+
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
self._sketch = self._feature.reference("sketch")
pass
def setSketch(self, sketch):
+ """Modify sketch attribute"""
self._fill_attribute(self._sketch, sketch)
pass
def setSketchSelection(self, sketch_selection):
+ """Modify sketch_selection attribute"""
self._fill_attribute(self._sketch_selection, sketch_selection)
pass
class Rotation(Interface):
+ """Interface class for Rotation features.
+
+ Rotation(feature) -> feature interface without initialization
+ Rotation(feature, main_objects, axis_object, angle) ->
+ feature interface initialized from arguments:
+ - main_objects
+ - axis_object
+ - angle
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Rotation")
class Translation(Interface):
+ """Interface class for Translation features.
+
+ Translation(feature) -> feature interface without initialization
+ Translation(feature, main_objects, axis_object, distance) ->
+ feature interface initialized from arguments:
+ - main_objects
+ - axis_object
+ - distance
+ """
def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Translation")
class Parameter(Interface):
- """Interface on a Parameter feature."""
+ """Interface class for Parameter feature.
- def __init__(self, feature, *args):
- """Initialize a Parameter feature with given parameters.
-
- Expected arguments for all modes:
- feature -- a Parameter feature
+ Parameter(feature) -> feature interface without initialization
+ Parameter(feature, variable, expression) ->
+ feature interface initialized from arguments:
+ - variable -- variable name
+ - expression -- Python expression
+ """
- For initialization (expect 2 arguments):
- name -- variable name
- expression -- Python expression
- """
+ def __init__(self, feature, *args):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Parameter")
class Part(Interface):
+ """Interface class for Part feature.
+
+ Part(feature) -> feature interface without initialization
+ """
def __init__(self, feature):
- """Adds a new Part to the given Partset and activates the Part."""
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
Interface.__init__(self, feature)
assert(self._feature.getKind() == "Part")
"""Base class of user-defined Python features."""
def __init__(self):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
ModelAPI.ModelAPI_Feature.__init__(self)
- def addRealInput (self, inputid):
+ def addRealInput(self, inputid):
+ """F.addRealInput(str) -- add real attribute"""
self.data().addAttribute(inputid,
ModelAPI.ModelAPI_AttributeDouble_typeId())
- def getRealInput (self, inputid):
+ def getRealInput(self, inputid):
+ """F.getRealInput(str) -- get real value of the attribute"""
return self.data().real(inputid).value()
- def addResult (self, result):
+ def addResult(self, result):
+ """F.addResult(ModelAPI_Result) -- add ModelAPI_Result shape as a result"""
shape = result.shape()
body = self.document().createBody(self.data())
body.store(shape)
"""Base class of high level Python interfaces to features."""
def __init__(self, feature):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
self._feature = feature
self._attribute_white_list = [
"execute",
tools.fill_attribute(attribute, value)
def setRealInput(self, inputid, value):
+ """I.setRealInput(str, float) -- set real value to the attribute"""
self._feature.data().real(inputid).setValue(value)
def areInputValid(self):
+ """I.areInputValid() -> True or False validation result"""
validators = ModelAPI.ModelAPI_Session.get().validators()
return validators.validate(self._feature)
def _execute(self):
+ """I._execute() -- validate and execute the feature.
+
+ Raises RuntimeError if validation fails.
+ """
if self.areInputValid():
self._feature.execute()
else:
return Sketch(feature, plane)
class Sketch(Interface):
- """Interface on a Sketch feature."""
+ """Interface class for Sketch feature."""
def __init__(self, feature, *args):
"""Initialize a 2D Sketch on the given plane.
class Selection:
- """Class for storing selection."""
+ """Class for selection.
+
+ Selection() -> empty selection
+ Selection(name, type) -> selection initialized with arguments:
+ - name -- topological name
+ - type -- type of the object
+ Selection(context, shape) -> selection initialized with arguments:
+ - context -- ModelAPI_Result object
+ - shape -- GeomAPI_Shape shape
+ """
def __init__(self, *args):
- """Initialize selection."""
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
+
if not args:
self.args = (None, None)
return
class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
+ """Class for Python features plugin.
+
+ PythonFeaturesPlugin() -> plugin object
+ """
def __init__(self):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
ModelAPI.ModelAPI_Plugin.__init__(self)
aSession = ModelAPI.ModelAPI_Session.get()
aSession.registerPlugin(self)
pass
def createFeature(self, theFeatureID):
+ """Override ModelAPI_Plugin.createFeature()"""
aFeature = None
if theFeatureID == BoxFeature.ID():
class BoxFeature(model.Feature):
+ """Box feature.
+ BoxFeature() -> Box
+ """
# Initializations
def __init__(self):
+ """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
model.Feature.__init__(self)
@staticmethod
def ID():
+ """String constant."""
return "Box"
@staticmethod
def WIDTH_ID():
+ """String constant."""
return "width"
@staticmethod
def LENGTH_ID():
+ """String constant."""
return "length"
@staticmethod
def HEIGHT_ID():
+ """String constant."""
return "height"
def getKind(self):
+ """Override Feature.getKind()"""
return BoxFeature.ID()
# Creation of the box at default size
def initAttributes(self):
-
+ """Override Feature.initAttributes()"""
# Creating the input arguments of the feature
self.addRealInput(self.WIDTH_ID())
self.addRealInput(self.LENGTH_ID())
# Edition of the box at user size
def execute(self):
+ """F.execute() -- execute the feature"""
# Retrieving the user inputs
width = self.getRealInput(self.WIDTH_ID())
- length = self.getRealInput(self.LENGTH_ID())
+ length = self.getRealInpuut(self.WIDTH_ID())
+ length = self.getRealInt(self.LENGTH_ID())
height = self.getRealInput(self.HEIGHT_ID())
# Editing the box
# self.addResult( self.box.result() )
def isMacro(self):
- # Box feature is macro: removes itself on the creation transaction finish
+ """Override Feature.initAttributes().
+ F.isMacro() -> True
+
+ Box feature is macro: removes itself on the creation transaction
+ finish.
+ """
return True