36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import FreeCAD as App
|
|
import FreeCADGui
|
|
import FreeCAD
|
|
import Part
|
|
import math
|
|
|
|
class Contenitore:
|
|
def __init__(self,obj, unitsX=20, unitsY=30,unitsZ=3):
|
|
obj.addProperty("App::PropertyFloat","unitsX","Box","Size in X direction.").unitsX = unitsX
|
|
obj.addProperty("App::PropertyFloat","unitsY","Box","Size in Y direction.").unitsY = unitsY
|
|
obj.addProperty("App::PropertyFloat","unitsZ","Box","Size in Z direction.").unitsZ = unitsZ
|
|
obj.Proxy = self
|
|
|
|
def execute(self, fp):
|
|
'''Print a short message when doing a recomputation, this method is mandatory'''
|
|
fp.Shape = Contenitore.buildshape(fp.unitsX, fp.unitsY, fp.unitsZ)
|
|
|
|
@staticmethod
|
|
def buildshape( unitsX, unitsY, unitsZ):
|
|
wall=1.5
|
|
|
|
# box
|
|
l=unitsX
|
|
w=unitsY
|
|
height=unitsZ
|
|
c1=Part.makeBox(l, w, height,FreeCAD.Vector(-l/2.0,-w/2.0,0))
|
|
c2=Part.makeBox(l+2*wall, w+2*wall, height+wall,FreeCAD.Vector(-(l+2*wall)/2.0,-(w+2*wall)/2.0,-wall))
|
|
d1=c2.cut(c1)
|
|
return d1
|
|
|
|
|
|
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Box")
|
|
Contenitore(a)
|
|
a.ViewObject.Proxy=0 # just set it to something different from None (this assignment is needed to run an internal notification)
|
|
FreeCAD.ActiveDocument.recompute()
|