From 739b0e37ee6ce461cdfa550f3a5d410470f18f6c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 25 May 2016 23:31:20 +0200 Subject: o Working FreeCAD module for creating boxes useful for laser cutting. --- Boxer.py | 78 +++++++--------------------------------------------------------- 1 file changed, 8 insertions(+), 70 deletions(-) (limited to 'Boxer.py') diff --git a/Boxer.py b/Boxer.py index 58d9218..cfcbbc0 100644 --- a/Boxer.py +++ b/Boxer.py @@ -1,6 +1,6 @@ -# import Boxer; reload(Boxer); Gui.runCommand("BoxerRemoveBox"); Gui.runCommand("BoxerMakeBox"); +# import Boxer; reload(Boxer); import BoxerGui as bg; reload(bg); -import FreeCAD +#import FreeCAD from FreeCAD import Base, Vector, Matrix import Part from enum import Enum @@ -113,7 +113,7 @@ class BoxCfg(object): @property def notchSize(self): - return self._notchUnitWidth + return self._notchSize @notchSize.setter def notchSize(self, notchSize): @@ -151,12 +151,13 @@ class BoxCfg(object): def prt(self): print("Box configuration") + print("Thickness : " + str(self._thickness)) print("Outer w/h/d: " + str(self.outerWidth) + "/" + str(self.outerHeight) + "/" + str(self.outerDepth)) print("Inner w/h/d: " + str(self.innerWidth) + "/" + str(self.innerHeight) + "/" + str(self.innerDepth)) - print("Notch size: " + str(self._notchSize)) - print(" Width: " + str(self.notchConfig(MeasurementDirection.width))) - print(" Height: " + str(self.notchConfig(MeasurementDirection.height))) - print(" Depth: " + str(self.notchConfig(MeasurementDirection.depth))) + print("Notch size : " + str(self._notchSize)) + print(" Width: " + str(self.notchConfig(MeasurementDirection.width))) + print(" Height: " + str(self.notchConfig(MeasurementDirection.height))) + print(" Depth: " + str(self.notchConfig(MeasurementDirection.depth))) class VGen(object): def __init__(self, current, dir): @@ -253,66 +254,3 @@ def makeBox(doc, cfg): l = Part.makePolygon(makeBoxSide(cfg, BoxSide.bottom)) l.transformShape(m) doc.addObject("Part::Feature", "Bottom").Shape = l - -class MakeBoxCommandClass(): - def GetResources(self): - return {#'Pixmap' : os.path.join( iconPath , 'AddWall.svg') , # the name of a svg file available in the resources - 'MenuText': "Make Box" , - 'ToolTip' : "Extends a wall from a side face of metal sheet"} - - def Activated(self): - # TODO: put all objects in a group: - # group = doc.addObject("App::DocumentObjectGroup","Group") - - cfg = BoxCfg().outerDimmensions(300, 100, 50) - # cfg.notches = 2 - cfg.notchUnitWidth = 10 - cfg.thickness = 10 - cfg.prt() - - doc = FreeCAD.ActiveDocument - makeBox(doc, cfg) - - doc.recompute() - Gui.SendMsgToActiveView("ViewFit") - - return - - def IsActive(self): -# if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: -# return False -# selobj = Gui.Selection.getSelection()[0] -# for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: -# if type(selFace) != Part.Face: -# return False -# return True - return FreeCAD.ActiveDocument is not None - -class RemoveBoxCommandClass(): - def GetResources(self): - return { - 'MenuText': "Remove Box", - 'ToolTip' : "Remove the box"} - - def Activated(self): - doc = FreeCAD.ActiveDocument - - def rm(name): - o = getattr(doc, name, None); - if hasattr(doc, name): - doc.removeObject(name) - - rm("Top") - rm("Back") - rm("Left") - rm("Front") - rm("Right") - rm("Bottom") - return - - def IsActive(self): - return FreeCAD.ActiveDocument is not None - -from FreeCAD import Gui -Gui.addCommand('BoxerMakeBox', MakeBoxCommandClass()) -Gui.addCommand('BoxerRemoveBox', RemoveBoxCommandClass()) -- cgit v1.2.3