2 Authors: Renaud Nedelec - Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
10 class BoxFeature(modeler.Feature):
11 """An example of Box feature implementation"""
17 modeler.Feature.__init__(self)
21 """Return Id of the feature"""
26 """Returns ID of Width parameter"""
31 """Returns ID of Length parameter"""
36 """Returns ID of Height parameter"""
40 """Returns ID of еру ауфегку"""
41 return BoxFeature.ID()
44 # Creation of the box at default size
46 def initAttributes(self):
47 """Initialise attributes of the feature"""
48 # Creating the input arguments of the feature
49 self.addRealInput( self.WIDTH_ID() )
50 self.addRealInput( self.LENGTH_ID() )
51 self.addRealInput( self.HEIGHT_ID() )
53 # Creating the base of the box with unit values
54 mypart = modeler.activeDocument()
55 xoy = modeler.defaultPlane("XOY")
57 ### A base of the geometry
58 self.base = modeler.addSketch( mypart, xoy )
60 p1 = geom.Pnt2d( 0, 0 )
61 p2 = geom.Pnt2d( 0, 1 )
62 p3 = geom.Pnt2d( 1, 1 )
63 p4 = geom.Pnt2d( 1, 0 )
65 line = self.base.addPolygon(p1, p2, p3, p4)
67 self.base.setParallel( line[0].result(), line[2].result() )
68 self.base.setParallel( line[1].result(), line[3].result() )
69 self.base.setPerpendicular( line[0].result(), line[3].result() )
71 # Setting the size of the base with default values
73 self.width = self.base.setLength( line[0].result(), 50 ) # Keeps the constraint for edition
75 self.length = self.base.setLength( line[3].result(), 50 ) # Keeps the constraint for edition
77 # Creating the extrusion (the box) at default size
79 self.box = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
82 # Edition of the box at user size
85 """Compute the feature result"""
86 # Retrieving the user inputs
87 width = self.getRealInput( self.WIDTH_ID() )
88 length = self.getRealInput( self.LENGTH_ID() )
89 height = self.getRealInput( self.HEIGHT_ID() )
92 self.base.setValue( self.width, width )
93 self.base.setValue( self.length, length )
94 self.box.setSize( height )
96 # Publishing the result: not needed for Macro feature
97 #self.addResult( self.box.result() )
101 # Box feature is macro: removes itself on the creation transaction finish