2 Authors: Renaud Nedelec - Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
10 class BoxFeature(modeler.Feature):
16 modeler.Feature.__init__(self)
35 return BoxFeature.ID()
38 # Creation of the box at default size
40 def initAttributes(self):
42 # Creating the input arguments of the feature
43 self.addRealInput( self.WIDTH_ID() )
44 self.addRealInput( self.LENGTH_ID() )
45 self.addRealInput( self.HEIGHT_ID() )
47 # Creating the base of the box with unit values
48 mypart = modeler.activeDocument()
49 xoy = modeler.defaultPlane("XOY")
51 self.base = modeler.addSketch( mypart, xoy )
53 p1 = geom.Pnt2d( 0, 0 )
54 p2 = geom.Pnt2d( 0, 1 )
55 p3 = geom.Pnt2d( 1, 1 )
56 p4 = geom.Pnt2d( 1, 0 )
58 line = self.base.addPolygon(p1, p2, p3, p4)
60 self.base.setParallel( line[0].result(), line[2].result() )
61 self.base.setParallel( line[1].result(), line[3].result() )
62 self.base.setPerpendicular( line[0].result(), line[3].result() )
64 # Setting the size of the base with default values
65 self.width = self.base.setLength( line[0].result(), 50 ) # Keeps the constraint for edition
66 self.length = self.base.setLength( line[3].result(), 50 ) # Keeps the constraint for edition
68 # Creating the extrusion (the box) at default size
69 self.box = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
72 # Edition of the box at user size
75 # Retrieving the user inputs
76 width = self.getRealInput( self.WIDTH_ID() )
77 length = self.getRealInput( self.LENGTH_ID() )
78 height = self.getRealInput( self.HEIGHT_ID() )
81 self.base.setValue( self.width, width )
82 self.base.setValue( self.length, length )
83 self.box.setSize( height )
85 # Publishing the result: not needed for Macro feature
86 #self.addResult( self.box.result() )
89 # Box feature is macro: removes itself on the creation transaction finish