1 """Cylinder macro-feature
2 Authors: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
10 class CylinderFeature(modeler.Feature):
16 modeler.Feature.__init__(self)
31 return CylinderFeature.ID()
34 # Creation of the cylinder at default size
36 def initAttributes(self):
38 # Creating the input arguments of the feature
39 self.addRealInput( self.RADIUS_ID() )
40 self.addRealInput( self.LENGTH_ID() )
42 # Creating the base of the cylinder with unit values
43 mypart = modeler.activeDocument()
44 xoy = modeler.defaultPlane("XOY")
46 self.base = modeler.addSketch( mypart, xoy )
47 circle = self.base.addCircle( 0, 0, 1)
49 # Setting the radius of the base with default values
50 self.radius = self.base.setRadius( circle.result(), 10 ) # Keeps the constraint for edition
52 # Creating the extrusion (the cylinder) at default size
53 self.cyl = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
56 # Edition of the cylinder at user size
59 # Retrieving the user inputs
60 radius = self.getRealInput( self.RADIUS_ID() )
61 length = self.getRealInput( self.LENGTH_ID() )
63 # Editing the cylinder
64 self.base.setValue( self.radius, radius )
65 self.cyl.setSize( length )
67 # Publishing the result
68 self.addResult( self.cyl.result() )