2 Authors: Renaud Nedelec - Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
10 class BoxFeature(model.Feature):
16 model.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 = model.activeDocument()
49 xoy = model.defaultPlane("XOY")
51 self.base = model.addSketch(mypart, xoy)
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 = model.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