Difference between revisions of "Macro Cabinets32"

From FreeCAD Documentation
Jump to: navigation, search
Line 29: Line 29:
 
#!/usr/bin/env python
 
#!/usr/bin/env python
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8 -*-
#***************************************************************************
+
# ***************************************************************************
#*                                                                        *
+
# *                                                                        *
#*  Copyright (c) 2015 Bruno Bueckmann reset12 at gmx.de                  *
+
# *  Copyright (c) 2015 Bruno Bueckmann reset12 at gmx.de                  *
#*                      http://home.bb-24.net                              *
+
# *                      http://home.bb-24.net                              *
#*  This program is free software; you can redistribute it and/or modify  *
+
# *  This program is free software; you can redistribute it and/or modify  *
#*  it under the terms of the GNU Lesser General Public License (LGPL)    *
+
# *  it under the terms of the GNU Lesser General Public License (LGPL)    *
#*  as published by the Free Software Foundation; either version 2 of    *
+
# *  as published by the Free Software Foundation; either version 2 of    *
#*  the License, or (at your option) any later version.                  *
+
# *  the License, or (at your option) any later version.                  *
#*  for detail see the LICENCE text file.                                *
+
# *  for detail see the LICENCE text file.                                *
#*                                                                        *
+
# *                                                                        *
#*  This program is distributed in the hope that it will be useful,      *
+
# *  This program is distributed in the hope that it will be useful,      *
#*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of        *
#*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
#*  GNU Library General Public License for more details.                  *
+
# *  GNU Library General Public License for more details.                  *
#*                                                                        *
+
# *                                                                        *
#*  You should have received a copy of the GNU Library General Public    *
+
# *  You should have received a copy of the GNU Library General Public    *
#*  License along with this program; if not, write to the Free Software  *
+
# *  License along with this program; if not, write to the Free Software  *
#*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+
# *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
#*  USA                                                                  *
+
# *  USA                                                                  *
#*                                                                        *
+
# *                                                                        *
#***************************************************************************
+
# ***************************************************************************
  
  
# Macro Begin: cabinets32.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
+
# Macro Begin: cabinets32.FCMacro ++++++++++++++++++++++++++++++++++++++++++++++
 
# This Macro generates holes and a groove for the side Base cabinet
 
# This Macro generates holes and a groove for the side Base cabinet
 
# Top and Bottom Wall are OUTSIDE the side base
 
# Top and Bottom Wall are OUTSIDE the side base
Line 61: Line 61:
 
# -------
 
# -------
  
import FreeCAD
+
from __future__ import division
import Part
+
 
 +
import FreeCAD as App
 +
from PySide import QtGui
 +
 
 
# GUI
 
# GUI
debug="n" #debugging on
+
debug = False # debugging on
guiok="y" # flag for abort input
+
guiok = True # flag for abort input
from PySide import QtGui
+
 
(width, ok) = QtGui.QInputDialog.getDouble(  
+
width, ok = QtGui.QInputDialog.getDouble(
      QtGui.QWidget(), 'Thickness', 'Thickness of cabinet-side', 19, 0, 50, 2)
+
    QtGui.QWidget(), 'Thickness', 'Thickness of cabinet-side', 19, 0, 50, 2)
 
if ok:
 
if ok:
  (length, ok) = QtGui.QInputDialog.getDouble(
+
    length, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Depth', 'Depth of cabinet-side', 600, 0, 2000, 2)
+
        QtGui.QWidget(), 'Depth', 'Depth of cabinet-side', 600, 0, 2000, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
if (ok) and (guiok == "y"):
+
 
  (height, ok) = QtGui.QInputDialog.getDouble(
+
if ok and guiok:
QtGui.QWidget(), 'Height', 'Height of cabinet-side', 2000, 0, 3000, 2)
+
    height, ok = QtGui.QInputDialog.getDouble(
 +
        QtGui.QWidget(), 'Height', 'Height of cabinet-side', 2000, 0, 3000, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
if (ok) and (guiok == "y"):
+
 
  (bradius, ok) = QtGui.QInputDialog.getDouble(
+
if ok and guiok:
QtGui.QWidget(), 'Bradius', 'Radius of drill holes in cabinet-side', 2.5, 0, 50, 2)
+
    bradius, ok = QtGui.QInputDialog.getDouble(
 +
        QtGui.QWidget(), 'Bradius', 'Radius of drill holes in cabinet-side',
 +
        2.5, 0, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (bdeep, ok) = QtGui.QInputDialog.getDouble(
+
    bdeep, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Bdeep', 'Deepness of drill holes in cabinet-side', 12, 0, 50, 2)
+
        QtGui.QWidget(), 'Bdeep', 'Depth of drill holes in cabinet-side',
 +
        12, 0, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (fdist, ok) = QtGui.QInputDialog.getDouble(
+
    fdist, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Fdist', 'Distance to Front of cabinet-side', 37, 0, 50, 2)
+
        QtGui.QWidget(), 'Fdist', 'Distance to Front of cabinet-side',
 +
        37, 0, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (hole1, ok) = QtGui.QInputDialog.getDouble(
+
    hole1, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Hole1', 'Distance first hole from top or bottom of cabinet-side', 10, 0, 50, 2)
+
        QtGui.QWidget(), 'Hole1',
 +
        'Distance first hole from top or bottom of cabinet-side', 10, 0, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (holedistance, ok) = QtGui.QInputDialog.getDouble(
+
    holedistance, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Holedistance', 'Distance from hole to hole (System 32)', 32, 1, 50, 2)
+
        QtGui.QWidget(), 'Holedistance',
 +
        'Distance from hole to hole (System 32)', 32, 1, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (groovethickness, ok) = QtGui.QInputDialog.getDouble(
+
    groovethickness, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Groovethickness', 'Thickness of backpanel', 3, 1, 50, 2)
+
        QtGui.QWidget(), 'Groovethickness', 'Thickness of backpanel',
 +
        3, 1, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
if ok:
 
if ok:
  (groovedeep, ok) = QtGui.QInputDialog.getDouble(
+
    groovedeep, ok = QtGui.QInputDialog.getDouble(
QtGui.QWidget(), 'Groovedeep', 'Overlapping of backpanel in cabinet-side', 12, 1, 50, 2)
+
        QtGui.QWidget(), 'Groovedeep',
 +
        'Overlapping of backpanel in cabinet-side', 12, 1, 50, 2)
 
else:
 
else:
guiok="n"
+
    guiok = False
if guiok=="y":
+
 
# VB 35 / 18 or VB 36 M /19 from Hettich
+
if guiok:
(connector, ok= QtGui.QInputDialog.getInt(
+
    # VB 35 / 18 or VB 36 M /19 from Hettich
QtGui.QWidget(), 'Connectortype', 'Zerohole(0) Singlehole(1) or Doublehole(2) Connector', 2, 0, 2, 1)  
+
    connector, ok = QtGui.QInputDialog.getInt(
 +
        QtGui.QWidget(), 'Connectortype',
 +
        'Zerohole(0) Singlehole(1) or Doublehole(2) Connector', 2, 0, 2, 1)
 +
 
 
if ok:
 
if ok:
fillwithholes = QtGui.QInputDialog.getText(None, "Fillwithholes", "Fill Board with holes y/n")[0]
+
    fillwithholes = QtGui.QInputDialog.getText(None,
 +
                                              "Fillwithholes",
 +
                                              "Fill Board with holes y/n")[0]
 
else:
 
else:
guiok="n"
+
    guiok = False
 +
 
 
endhole = 9.5
 
endhole = 9.5
if guiok=="y":
 
endholes = QtGui.QInputDialog.getText(None, "Endholes", "Drill Holes on Top/Bottom vertikal for Connectors y/n")[0]
 
if guiok=="y" and endholes == 'y':
 
  (endhole, ok) = QtGui.QInputDialog.getDouble(
 
QtGui.QWidget(), 'Endhole', 'Endhole distance from inner cabinet-side', 9.5, 1, 50, 2)
 
if debug == 'y':
 
  FreeCAD.Console.PrintMessage("width="+str(width) + " " + str(ok) + "\n" )
 
  FreeCAD.Console.PrintMessage("length="+str(length) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("bradius="+str(bradius) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("bdeep="+str(bdeep) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("fdist="+str(fdist) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("hole1="+str(hole1) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("holedistance="+str(holedistance) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("groovethickness="+str(groovethickness) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("groovedeep="+str(groovedeep) + " " + str(ok) + "\n")
 
  FreeCAD.Console.PrintMessage("connector="+str(connector) + " " + "\n")
 
  FreeCAD.Console.PrintMessage("fillwithholes="+str(fillwithholes) + " " + "\n")
 
  FreeCAD.Console.PrintMessage("endholes="+str(endholes) + " " + "\n")
 
  FreeCAD.Console.PrintMessage("endhole="+str(endhole) + " " + "\n")
 
  FreeCAD.Console.PrintMessage("guiok="+str(guiok) + " " + "\n")
 
#End GUI
 
if guiok == "y":
 
#width= 19 # thickness of korpus
 
#length= 600 # width of korpus
 
#height= 2000 # height of korpus
 
#
 
#bradius = 2.5  # Radius drill hole
 
#bdeep = 12    # deepness of drill hole
 
#fdist = 37    # Distance to Front
 
#hole1 = 9.5 # Distance first hole from top or bottom of korpus
 
#holedistance = 32  # System 32
 
#groovethickness = 3 # 3 mm backpanel
 
#groovedeep = width-8 # deep of groovedeep
 
if int(width) > 16:
 
  # first hole depend on specs for VB36 M / 19  for 19 mm boards von Hettich
 
  holetop = 9.5  # holedistance for screw of vb36
 
  hole1 = 9.5 + 0.5 # distance hole 1 from end of board
 
  hole1r = 10 # radius first hole
 
  hole1d = 14 # deepness first hole
 
  hole2r = 5 # radius 2. hole
 
  hole2d = 10.5 # deepness 2. hole
 
else:
 
# first hole depend on specs for VB36 M / 16  for 16 mm boards von Hettich
 
  holetop = 9.5  # holedistance for screw of vb36
 
  hole1 = 9.5 + 0.5 # distance hole 1 from end of board
 
  hole1r = 10 # radius first hole
 
  hole1d = 12.5 # deepness first hole
 
  hole2r = 5 # radius 2. hole
 
  hole2d = 10.5 # deepness 2. hole
 
if debug == 'y':
 
  FreeCAD.Console.PrintMessage("hole1d="+str(hole1d) + " " + str(ok) + "\n" )
 
# functions
 
def cut( tool ):
 
  global cutsnr,cuts
 
  # cuts objects defined in string cuts
 
  if debug == 'y':
 
  FreeCAD.Console.PrintMessage("cuts=" + str(cuts) + " cutsnr=" + str(cutsnr) + "\n")
 
  data='App.activeDocument().addObject("Part::Cut","' + str(cuts.split(" ")[cutsnr + 1]) + '")'
 
  if debug == 'y':
 
  FreeCAD.Console.PrintMessage(str(data)  + "\n")
 
  exec(data)
 
  data="App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
 
  data=data + ".Base = App.activeDocument()."+ str(cuts.split(" ")[cutsnr])
 
  if debug == 'y':
 
  FreeCAD.Console.PrintMessage(str(data)  + "\n")
 
  exec(data)
 
  data="App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
 
  data=data + ".Tool = App.activeDocument()." + str(tool)
 
  if debug == 'y':
 
  FreeCAD.Console.PrintMessage(str(data)  + "\n")
 
  exec(data)
 
  cutsnr=cutsnr + 1
 
  cuts=cuts + " Cut%03d" % cutsnr
 
  return 0;
 
# end functions
 
# Korpus
 
App.ActiveDocument.addObject("Part::Box","Box")
 
App.ActiveDocument.ActiveObject.Label = "Cube"
 
App.ActiveDocument.ActiveObject.Length = length
 
App.ActiveDocument.ActiveObject.Width = width
 
App.ActiveDocument.ActiveObject.Height = height
 
Gui.ActiveDocument.Box.DiffuseColor= (0.67,0.67,0.00) #Change Color of Object
 
App.ActiveDocument.recompute()
 
# Groove
 
App.ActiveDocument.addObject("Part::Box","Groove")
 
App.ActiveDocument.ActiveObject.Label = "Groove"
 
App.ActiveDocument.ActiveObject.Length = groovethickness
 
App.ActiveDocument.ActiveObject.Width = groovedeep
 
App.ActiveDocument.ActiveObject.Height = height - (2 * groovedeep)
 
Gui.ActiveDocument.Box.DiffuseColor= (0.67,0.67,0.00) #Change Color of Object
 
App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(
 
                                              length-groovethickness,0,groovedeep),
 
                                              App.Rotation(App.Vector(0,0,0),0), App.Vector(0,0,0))
 
App.ActiveDocument.recompute()
 
  
# make endholes
+
if guiok:
cylinders="" # labels of cylinders to cut
+
    endholes = QtGui.QInputDialog.getText(
if endholes == 'y':
+
        None, "Endholes",
  # Bottom holes
+
        "Drill Holes on Top/Bottom vertikal for Connectors y/n")[0]
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderendl")
+
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderendl001"
+
if guiok and endholes == 'y':
  App.ActiveDocument.ActiveObject.Radius = bradius
+
    endhole, ok = QtGui.QInputDialog.getDouble(
  App.ActiveDocument.ActiveObject.Height = bdeep
+
        QtGui.QWidget(), 'Endhole',
  App.ActiveDocument.ActiveObject.Angle = 360
+
        'Endhole distance from inner cabinet-side', 9.5, 1, 50, 2)
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
if debug:
  Gui.ActiveDocument.Cylinderendl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
    App.Console.PrintMessage("ok?: {}\n".format(ok))
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,bdeep,holetop),
+
    App.Console.PrintMessage("width = {}\n".format(width))
                                                          App.Rotation(App.Vector(1,0,0),90),
+
    App.Console.PrintMessage("length = {}\n".format(length))
                                                          App.Vector(0,0,0))
+
    App.Console.PrintMessage("bradius = {}\n".format(bradius))
  App.ActiveDocument.recompute()
+
    App.Console.PrintMessage("bdeep = {}\n".format(bdeep))
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderendr")
+
    App.Console.PrintMessage("fdist = {}\n".format(fdist))
  App.ActiveDocument.ActiveObject.Label = "Cylinderendr001"
+
    App.Console.PrintMessage("hole1 = {}\n".format(hole1))
  App.ActiveDocument.ActiveObject.Radius = bradius
+
    App.Console.PrintMessage("holedistance = {}\n".format(holedistance))
  App.ActiveDocument.ActiveObject.Height = bdeep
+
    App.Console.PrintMessage("groovethickness = {}\n".format(groovethickness))
  App.ActiveDocument.ActiveObject.Angle = 360
+
    App.Console.PrintMessage("groovedeep = {}\n".format(groovedeep))
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
    App.Console.PrintMessage("connector = {}\n".format(connector))
  Gui.ActiveDocument.Cylinderendr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
    App.Console.PrintMessage("fillwithholes = {}\n".format(fillwithholes))
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,bdeep,holetop),
+
    App.Console.PrintMessage("endholes = {}\n".format(endholes))
                                            App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
+
    App.Console.PrintMessage("endhole = {}\n".format(endhole))
  App.ActiveDocument.recompute()
+
    App.Console.PrintMessage("guiok = {}\n".format(guiok))
# Top holes
+
# End GUI
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderendl")
+
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderendl002"
+
if guiok:
  App.ActiveDocument.ActiveObject.Radius = bradius
+
    # width= 19 # thickness of korpus
  App.ActiveDocument.ActiveObject.Height = bdeep
+
    # length= 600 # width of korpus
  App.ActiveDocument.ActiveObject.Angle = 360
+
    # height= 2000 # height of korpus
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
    #
  Gui.ActiveDocument.Cylinderendl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
    # bradius = 2.5  # Radius drill hole
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,bdeep,(height-holetop)),
+
    # bdeep = 12    # deepness of drill hole
                                            App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
+
    # fdist = 37    # Distance to Front
  App.ActiveDocument.recompute()
+
    # hole1 = 9.5 # Distance first hole from top or bottom of korpus
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderendr")
+
    # holedistance = 32  # System 32
  App.ActiveDocument.ActiveObject.Label = "Cylinderendr002"
+
    # groovethickness = 3 # 3 mm backpanel
  App.ActiveDocument.ActiveObject.Radius = bradius
+
    # groovedeep = width-8 # deep of groovedeep
  App.ActiveDocument.ActiveObject.Height = bdeep
+
    if int(width) > 16:
  App.ActiveDocument.ActiveObject.Angle = 360
+
        # First hole depends on specs for VB36 M / 19 for 19 mm boards from
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        # Hettich.
  Gui.ActiveDocument.Cylinderendr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        holetop = 9.5  # holedistance for screw of vb36
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,bdeep,(height-holetop)),
+
        hole1 = 9.5 + 0.5  # distance hole 1 from end of board
                                            App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
+
        hole1r = 10  # radius first hole
  App.ActiveDocument.recompute()
+
        hole1d = 14  # deepness first hole
#
+
        hole2r = 5  # radius 2. hole
if fillwithholes == 'n':
+
        hole2d = 10.5  # deepness 2. hole
  n=0
+
    else:
else:
+
        # First hole depends on specs for VB36 M / 16 for 16 mm boards from
  n=int(height/2/holedistance)
+
        # Hettich.
# drill holes from bottom to half height
+
        holetop = 9.5  # holedistance for screw of vb36
# reduce holes for test to 2 alternative use n
+
        hole1 = 9.5 + 0.# distance hole 1 from end of board
# Holes for Hettich VB36
+
        hole1r = 10  # radius first hole
# Bohrloecher
+
        hole1d = 12.5  # deepness first hole
x = -1 # init value
+
        hole2r = 5  # radius 2. hole
if connector >= 1:
+
        hole2d = 10.5  # deepness 2. hole
  x=0
+
 
  FreeCAD.Console.PrintMessage("x="+str(x) + " " + "\n")
+
    if debug:
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
+
        App.Console.PrintMessage("hole1d = {}\n".format(hole1d))
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
+
 
  App.ActiveDocument.ActiveObject.Radius = hole1r
+
    # functions
  App.ActiveDocument.ActiveObject.Height = hole1d
+
    def cut(tool):
  App.ActiveDocument.ActiveObject.Angle = 360
+
        global cutsnr
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        global cuts
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        # cuts objects defined in string cuts
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,hole1d,hole1+x*holedistance),
+
        if debug:
                                            App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
+
            App.Console.PrintMessage("cuts = {}, cutsnr = {}\n".format(
  App.ActiveDocument.recompute()  
+
                cuts, cutsnr))
 +
        data = 'App.activeDocument().addObject("Part::Cut","' + str(cuts.split(" ")[cutsnr + 1]) + '")'
 +
        if debug:
 +
            App.Console.PrintMessage(str(data) + "\n")
 +
        exec(data)
 +
        data = "App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
 +
        data = data + ".Base = App.activeDocument()." + str(cuts.split(" ")[cutsnr])
 +
        if debug:
 +
            App.Console.PrintMessage(str(data) + "\n")
 +
        exec(data)
 +
        data = "App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
 +
        data = data + ".Tool = App.activeDocument()." + str(tool)
 +
        if debug:
 +
            App.Console.PrintMessage(str(data) + "\n")
 +
        exec(data)
 +
        cutsnr = cutsnr + 1
 +
        cuts = cuts + " Cut%03d" % cutsnr
 +
        return 0
 +
 
 +
    # end functions
 +
 
 +
    doc = App.activeDocument()
 +
 
 +
    # Korpus
 +
    box = doc.addObject("Part::Box", "Box")
 +
    box.Label = "Cube"
 +
    box.Length = length
 +
    box.Width = width
 +
    box.Height = height
 +
    # Change Color of Object.
 +
    box.ViewObject.DiffuseColor = (0.67, 0.67, 0.0)
 +
    if debug:
 +
        doc.recompute()
 +
    # Groove
 +
    groove = doc.addObject("Part::Box", "Groove")
 +
    groove.Label = "Groove"
 +
    groove.Length = groovethickness
 +
    groove.Width = groovedeep
 +
    groove.Height = height - (2 * groovedeep)
 +
    groove.ViewObject.DiffuseColor = (0.67, 0.67, 0.0)
 +
    groove.Placement = App.Placement(
 +
        App.Vector(length - groovethickness, 0, groovedeep),
 +
        App.Rotation())
 +
    if debug:
 +
        doc.recompute()
 +
 
 +
    # make endholes
 +
    cylinders = ""  # labels of cylinders to cut
 +
    if endholes == 'y':
 +
        # Bottom holes
 +
        cylendl = doc.addObject("Part::Cylinder", "Cylinderendl")
 +
        cylendl.Label = "Cylinderendl001"
 +
        cylendl.Radius = bradius
 +
        cylendl.Height = bdeep
 +
        cylendl.Angle = 360
 +
        cylinders = cylinders + " " + cylendl.Name
 +
        cylendl.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        doc.ActiveObject.Placement = App.Placement(
 +
            App.Vector(fdist, bdeep, holetop),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
        cylendr = doc.addObject("Part::Cylinder", "Cylinderendr")
 +
        cylendr.Label = "Cylinderendr001"
 +
        cylendr.Radius = bradius
 +
        cylendr.Height = bdeep
 +
        cylendr.Angle = 360
 +
        cylinders = cylinders + " " + cylendr.Name
 +
        cylendr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylendr.Placement = App.Placement(
 +
            App.Vector(length - fdist, bdeep, holetop),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
        # Top holes
 +
        cylendl = doc.addObject("Part::Cylinder", "Cylinderendl")
 +
        cylendl.Label = "Cylinderendl002"
 +
        cylendl.Radius = bradius
 +
        cylendl.Height = bdeep
 +
        cylendl.Angle = 360
 +
        cylinders = cylinders + " " + cylendl.Name
 +
        cylendl.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylendl.Placement = App.Placement(
 +
            App.Vector(fdist, bdeep, height - holetop),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
        cylendr = doc.addObject("Part::Cylinder", "Cylinderendr")
 +
        cylendr.Label = "Cylinderendr002"
 +
        cylendr.Radius = bradius
 +
        cylendr.Height = bdeep
 +
        cylendr.Angle = 360
 +
        cylinders = cylinders + " " + cylendr.Name
 +
        cylendr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylendr.Placement = App.Placement(
 +
            App.Vector(length - fdist, bdeep, height-holetop),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
    if fillwithholes == 'n':
 +
        n = 0
 +
    else:
 +
        n = int(height / 2 / holedistance)
 +
 
 +
    # drill holes from bottom to half height
 +
    # reduce holes for test to 2 alternative use n
 +
    # Holes for Hettich VB36
 +
    # Bohrloecher
 +
    x = -1  # init value
 +
    if connector >= 1:
 +
        x = 0
 +
        App.Console.PrintMessage("x="+str(x) + " " + "\n")
 +
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
 +
        cyll.Label = "Cylinderl%03d" % x
 +
        cyll.Radius = hole1r
 +
        cyll.Height = hole1d
 +
        cyll.Angle = 360
 +
        cylinders = cylinders + " " + cyll.Name
 +
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cyll.Placement = App.Placement(
 +
            App.Vector(fdist, hole1d, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
 +
        cylr.Label = "Cylinderr%03d" % x
 +
        cylr.Radius = hole1r
 +
        cylr.Height = hole1d
 +
        cylr.Angle = 360
 +
        cylinders = cylinders + " " + cylr.Name
 +
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylr.Placement = App.Placement(
 +
            App.Vector(length - fdist, hole1d, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
 
 +
    if connector == 2:
 +
        x = 1
 +
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
 +
        cyll.Label = "Cylinderl%03d" % x
 +
        cyll.Radius = hole2r
 +
        cyll.Height = hole2d
 +
        cyll.Angle = 360
 +
        cylinders = cylinders + " " + cyll.Name
 +
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cyll.Placement = App.Placement(
 +
            App.Vector(fdist, hole2d, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
 +
        cylr.Label = "Cylinderr%03d" % x
 +
        cylr.Radius = hole2r
 +
        cylr.Height = hole2d
 +
        cylr.Angle = 360
 +
        cylinders = cylinders + " " + cylr.Name
 +
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylr.Placement = App.Placement(
 +
            App.Vector(length - fdist, hole2d, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
    xs = x + 1
 +
    for x in range(xs, n):
 +
        # Bohrloecher
 +
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
 +
        cyll.Label = "Cylinderl%03d" % x
 +
        cyll.Radius = bradius
 +
        cyll.Height = bdeep
 +
        cyll.Angle = 360
 +
        cylinders = cylinders + " " + cyll.Name
 +
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cyll.Placement = App.Placement(
 +
            App.Vector(fdist, bdeep, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
 +
        cylr.Label = "Cylinderr%03d" % x
 +
        cylr.Radius = bradius
 +
        cylr.Height = bdeep
 +
        cylr.Angle = 360
 +
        cylinders = cylinders + " " + cylr.Name
 +
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cylr.Placement = App.Placement(
 +
            App.Vector(length - fdist, bdeep, hole1 + x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
 +
 
 +
    # drill holes from Top to half height
 +
    # # Holes for Hettich VB36
 +
    x = -1  # init value
 +
    if connector >= 1:
 +
        x = 0
 +
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
 +
        cyll.Label = "Cylinderl%03d" % x
 +
        cyll.Radius = hole1r
 +
        cyll.Height = hole1d
 +
        cyll.Angle = 360
 +
        cylinders = cylinders + " " + cyll.Name
 +
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
 +
        cyll.Placement = App.Placement(
 +
            App.Vector(fdist, hole1d, height - hole1 - x * holedistance),
 +
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
        cylr.Label = "Cylinderr%03d" % x
  App.ActiveDocument.ActiveObject.Radius = hole1r
+
        cylr.Radius = hole1r
  App.ActiveDocument.ActiveObject.Height = hole1d
+
        cylr.Height = hole1d
  App.ActiveDocument.ActiveObject.Angle = 360
+
        cylr.Angle = 360
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        cylinders = cylinders + " " + cylr.Name
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,hole1d,hole1+
+
        cylr.Placement = App.Placement(
                                              x*holedistance), App.Rotation(App.Vector(1,0,0),90),
+
            App.Vector(length - fdist, hole1d, height-hole1 - x * holedistance),
                                              App.Vector(0,0,0))
+
            App.Rotation(App.Vector(1, 0, 0), 90))
if connector == 2:
+
        if debug:
  x=1
+
            doc.recompute()
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
 
  App.ActiveDocument.ActiveObject.Radius = hole2r
 
  App.ActiveDocument.ActiveObject.Height = hole2d
 
  App.ActiveDocument.ActiveObject.Angle = 360
 
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
 
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
 
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,hole2d,hole1+
 
                                            x*holedistance), App.Rotation(App.Vector(1,0,0),90),
 
                                              App.Vector(0,0,0))
 
  App.ActiveDocument.recompute()
 
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
    if connector == 2:
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
        x = 1
  App.ActiveDocument.ActiveObject.Radius = hole2r
+
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
  App.ActiveDocument.ActiveObject.Height = hole2d
+
        cyll.Label = "Cylinderl%03d" % x
  App.ActiveDocument.ActiveObject.Angle = 360
+
        cyll.Radius = hole2r
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        cyll.Height = hole2d
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        cyll.Angle = 360
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,hole2d,hole1+
+
        cylinders = cylinders + " " + cyll.Name
                                            x*holedistance), App.Rotation(App.Vector(1,0,0),90),
+
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
                                              App.Vector(0,0,0))
+
        cyll.Placement = App.Placement(
  App.ActiveDocument.recompute()
+
            App.Vector(fdist, hole2d, height - hole1 - x * holedistance),
xs = x + 1
+
            App.Rotation(App.Vector(1, 0, 0), 90))
for x in range(xs, n):
+
        if debug:
  # Bohrloecher
+
            doc.recompute()
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
 
  App.ActiveDocument.ActiveObject.Radius = bradius
 
  App.ActiveDocument.ActiveObject.Height = bdeep
 
  App.ActiveDocument.ActiveObject.Angle = 360
 
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
 
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
 
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,bdeep,hole1+x*holedistance),
 
                                            App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
 
  App.ActiveDocument.recompute()
 
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
        cylr.Label = "Cylinderr%03d" % x
  App.ActiveDocument.ActiveObject.Radius = bradius
+
        cylr.Radius = hole2r
  App.ActiveDocument.ActiveObject.Height = bdeep
+
        cylr.Height = hole2d
  App.ActiveDocument.ActiveObject.Angle = 360
+
        cylr.Angle = 360
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        cylinders = cylinders + " " + cylr.Name
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,bdeep,hole1+
+
        cylr.Placement = App.Placement(
                                            x*holedistance), App.Rotation(App.Vector(1,0,0),90),
+
            App.Vector(
                                              App.Vector(0,0,0))
+
                length - fdist, hole2d, height - hole1 - x * holedistance),
  App.ActiveDocument.recompute()  
+
            App.Rotation(App.Vector(1, 0, 0), 90))
 +
        if debug:
 +
            doc.recompute()
  
# drill holes from Top to half height
+
    xs = x + 1
# # Holes for Hettich VB36
+
    for x in range(xs, n):
x = -1 # init value
+
        # Drillholes
if connector >= 1:
+
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
  x=0
+
        cyll.Label = "Cylinderl%03d" % x
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
+
        cyll.Radius = bradius
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
+
        cyll.Height = bdeep
  App.ActiveDocument.ActiveObject.Radius = hole1r
+
        cyll.Angle = 360
  App.ActiveDocument.ActiveObject.Height = hole1d
+
        cylinders = cylinders + " " + cyll.Name
  App.ActiveDocument.ActiveObject.Angle = 360
+
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        cyll.Placement = App.Placement(
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
            App.Vector(fdist, bdeep, height - hole1 - x * holedistance),
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,hole1d,(height-hole1)-
+
            App.Rotation(App.Vector(1, 0, 0), 90))
                                            (x*holedistance)), App.Rotation(App.Vector(1,0,0),90),
+
        if debug:
                                              App.Vector(0,0,0))
+
            doc.recompute()
  App.ActiveDocument.recompute()
 
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
        cylr.Label = "Cylinderr%03d" % x
  App.ActiveDocument.ActiveObject.Radius = hole1r
+
        cylr.Radius = bradius
  App.ActiveDocument.ActiveObject.Height = hole1d
+
        cylr.Height = bdeep
  App.ActiveDocument.ActiveObject.Angle = 360
+
        cylr.Angle = 360
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
        cylinders = cylinders + " " + cylr.Name
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,hole1d,
+
        cylr.Placement = App.Placement(
                                            (height-hole1)-(x*holedistance)),  
+
            App.Vector(
                                              App.Rotation(App.Vector(1,0,0),90), App.Vector(0,0,0))
+
                length - fdist, bdeep, height - hole1 - x * holedistance),
  App.ActiveDocument.recompute()  
+
            App.Rotation(App.Vector(1, 0, 0), 90))
if connector == 2:
+
        if debug:
  x=1
+
            doc.recompute()
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
 
  App.ActiveDocument.ActiveObject.Radius = hole2r
 
  App.ActiveDocument.ActiveObject.Height = hole2d
 
  App.ActiveDocument.ActiveObject.Angle = 360
 
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
 
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
 
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,hole2d,(height-hole1)-
 
                                            (x*holedistance)), App.Rotation(App.Vector(1,0,0),90),
 
                                              App.Vector(0,0,0))
 
  App.ActiveDocument.recompute()
 
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
    if debug:
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
        App.Console.PrintMessage("cylinders = ")
  App.ActiveDocument.ActiveObject.Radius = hole2r
+
        App.Console.PrintMessage(cylinders + "\n")
  App.ActiveDocument.ActiveObject.Height = hole2d
 
  App.ActiveDocument.ActiveObject.Angle = 360
 
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
 
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
 
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,hole2d,(height-hole1)-
 
                                            (x*holedistance)), App.Rotation(App.Vector(1,0,0),90),
 
                                              App.Vector(0,0,0))
 
  App.ActiveDocument.recompute()
 
xs = x + 1
 
for x in range(xs, n):
 
  # Drillholes
 
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderl")
 
  App.ActiveDocument.ActiveObject.Label = "Cylinderl%03d" % x
 
  App.ActiveDocument.ActiveObject.Radius = bradius
 
  App.ActiveDocument.ActiveObject.Height = bdeep
 
  App.ActiveDocument.ActiveObject.Angle = 360
 
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
 
  Gui.ActiveDocument.Cylinderl.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
 
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(fdist,bdeep,(height-hole1)-
 
                                            (x*holedistance)), App.Rotation(App.Vector(1,0,0),90),
 
                                              App.Vector(0,0,0))
 
  App.ActiveDocument.recompute()
 
  
  App.ActiveDocument.addObject("Part::Cylinder","Cylinderr")
+
    # cut all holes
  App.ActiveDocument.ActiveObject.Label = "Cylinderr%03d" % x
+
    cuts = "Box Cut"  # cut labels
  App.ActiveDocument.ActiveObject.Radius = bradius
+
    cutsnr = 0    # index number in cuts
  App.ActiveDocument.ActiveObject.Height = bdeep
+
    # cut groove
  App.ActiveDocument.ActiveObject.Angle = 360
+
    cut("Groove")
  cylinders=cylinders + " " + App.ActiveDocument.ActiveObject.Name
+
    cyls = cylinders.split()  # number of words
  Gui.ActiveDocument.Cylinderr.DiffuseColor= (0.00,0.00,0.00) #Change Color of Object
+
    if debug:
  App.ActiveDocument.ActiveObject.Placement=App.Placement(App.Vector(length-fdist,bdeep,(height-hole1)-
+
        App.Console.PrintMessage("n=" + str(cyls) + "\n")
                                            (x*holedistance)), App.Rotation(App.Vector(1,0,0),90),
+
    for x in cyls:
                                              App.Vector(0,0,0))
+
        if debug:
  App.ActiveDocument.recompute()
+
            App.Console.PrintMessage("cylinder(" + x + ")=" + str(x) + "\n")
if debug == 'y':
+
        cut(str(x))
  FreeCAD.Console.PrintMessage("cylinders=")
+
    doc.recompute()
  FreeCAD.Console.PrintMessage(cylinders  + "\n")
 
# cut all holes
 
cuts="Box Cut"  # cut labels
 
cutsnr=0    # index number in cuts
 
# cut groove
 
cut("Groove");
 
cyls = cylinders.split()  # number of words
 
if debug == 'y':
 
  FreeCAD.Console.PrintMessage("n=" + str(cyls) + "\n")
 
for x in cyls:
 
  if debug == "y":
 
    FreeCAD.Console.PrintMessage("cylinder(" + x + ")=" + str(x) + "\n")
 
  cut(str(x));
 
App.ActiveDocument.recompute()
 
  
 
# OS: Ubuntu 14.04.1 LTS
 
# OS: Ubuntu 14.04.1 LTS

Revision as of 20:55, 22 January 2015

32px Cabinets32

Description
drill holes for System32 cabinets.

Author
Berner
Download
None
Links
Macro Version
1.0
Date last modification
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

cabinetside

cabinettop


Description

This macro creates Top/Bottom and sidewalls for a cabinet with System32 specification. The defaults in the Macro are for parts of manufacturer Hettich.

Use

  • Launch the macro and change length, height and width of your cabinet-board.
  • The Gui ask to drill one or two-hole connectors.
  • You can drill the hole board with holes in 32 mm distance.
  • You can drill holes for top/bottom boards of your cabinet.


Script

Cabinets32.FCMacro

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ***************************************************************************
# *                                                                         *
# *   Copyright (c) 2015 Bruno Bueckmann reset12 at gmx.de                  *
# *                      http://home.bb-24.net                              *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
# *   as published by the Free Software Foundation; either version 2 of     *
# *   the License, or (at your option) any later version.                   *
# *   for detail see the LICENCE text file.                                 *
# *                                                                         *
# *   This program is distributed in the hope that it will be useful,       *
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
# *   GNU Library General Public License for more details.                  *
# *                                                                         *
# *   You should have received a copy of the GNU Library General Public     *
# *   License along with this program; if not, write to the Free Software   *
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
# *   USA                                                                   *
# *                                                                         *
# ***************************************************************************


# Macro Begin: cabinets32.FCMacro ++++++++++++++++++++++++++++++++++++++++++++++
# This Macro generates holes and a groove for the side Base cabinet
# Top and Bottom Wall are OUTSIDE the side base
# like :
# -------
# |     |
# |     |
# -------

from __future__ import division

import FreeCAD as App
from PySide import QtGui

# GUI
debug = False  # debugging on
guiok = True  # flag for abort input

width, ok = QtGui.QInputDialog.getDouble(
    QtGui.QWidget(), 'Thickness', 'Thickness of cabinet-side', 19, 0, 50, 2)
if ok:
    length, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Depth', 'Depth of cabinet-side', 600, 0, 2000, 2)
else:
    guiok = False

if ok and guiok:
    height, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Height', 'Height of cabinet-side', 2000, 0, 3000, 2)
else:
    guiok = False

if ok and guiok:
    bradius, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Bradius', 'Radius of drill holes in cabinet-side',
        2.5, 0, 50, 2)
else:
    guiok = False

if ok:
    bdeep, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Bdeep', 'Depth of drill holes in cabinet-side',
        12, 0, 50, 2)
else:
    guiok = False

if ok:
    fdist, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Fdist', 'Distance to Front of cabinet-side',
        37, 0, 50, 2)
else:
    guiok = False

if ok:
    hole1, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Hole1',
        'Distance first hole from top or bottom of cabinet-side', 10, 0, 50, 2)
else:
    guiok = False

if ok:
    holedistance, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Holedistance',
        'Distance from hole to hole (System 32)', 32, 1, 50, 2)
else:
    guiok = False

if ok:
    groovethickness, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Groovethickness', 'Thickness of backpanel',
        3, 1, 50, 2)
else:
    guiok = False

if ok:
    groovedeep, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Groovedeep',
        'Overlapping of backpanel in cabinet-side', 12, 1, 50, 2)
else:
    guiok = False

if guiok:
    # VB 35 / 18 or VB 36 M /19 from Hettich
    connector, ok = QtGui.QInputDialog.getInt(
        QtGui.QWidget(), 'Connectortype',
        'Zerohole(0) Singlehole(1) or Doublehole(2) Connector', 2, 0, 2, 1)

if ok:
    fillwithholes = QtGui.QInputDialog.getText(None,
                                               "Fillwithholes",
                                               "Fill Board with holes y/n")[0]
else:
    guiok = False

endhole = 9.5

if guiok:
    endholes = QtGui.QInputDialog.getText(
        None, "Endholes",
        "Drill Holes on Top/Bottom vertikal for Connectors y/n")[0]

if guiok and endholes == 'y':
    endhole, ok = QtGui.QInputDialog.getDouble(
        QtGui.QWidget(), 'Endhole',
        'Endhole distance from inner cabinet-side', 9.5, 1, 50, 2)
if debug:
    App.Console.PrintMessage("ok?: {}\n".format(ok))
    App.Console.PrintMessage("width = {}\n".format(width))
    App.Console.PrintMessage("length = {}\n".format(length))
    App.Console.PrintMessage("bradius = {}\n".format(bradius))
    App.Console.PrintMessage("bdeep = {}\n".format(bdeep))
    App.Console.PrintMessage("fdist = {}\n".format(fdist))
    App.Console.PrintMessage("hole1 = {}\n".format(hole1))
    App.Console.PrintMessage("holedistance = {}\n".format(holedistance))
    App.Console.PrintMessage("groovethickness = {}\n".format(groovethickness))
    App.Console.PrintMessage("groovedeep = {}\n".format(groovedeep))
    App.Console.PrintMessage("connector = {}\n".format(connector))
    App.Console.PrintMessage("fillwithholes = {}\n".format(fillwithholes))
    App.Console.PrintMessage("endholes = {}\n".format(endholes))
    App.Console.PrintMessage("endhole = {}\n".format(endhole))
    App.Console.PrintMessage("guiok = {}\n".format(guiok))
# End GUI

if guiok:
    # width= 19	# thickness of korpus
    # length= 600	# width of korpus
    # height= 2000	# height of korpus
    #
    # bradius = 2.5  	# Radius drill hole
    # bdeep = 12     	# deepness of drill hole
    # fdist = 37    	# Distance to Front
    # hole1 = 9.5	# Distance first hole from top or bottom of korpus
    # holedistance = 32  # System 32
    # groovethickness = 3 # 3 mm backpanel
    # groovedeep = width-8 # deep of groovedeep
    if int(width) > 16:
        # First hole depends on specs for VB36 M / 19 for 19 mm boards from
        # Hettich.
        holetop = 9.5  # holedistance for screw of vb36
        hole1 = 9.5 + 0.5  # distance hole 1 from end of board
        hole1r = 10  # radius first hole
        hole1d = 14  # deepness first hole
        hole2r = 5  # radius 2. hole
        hole2d = 10.5  # deepness 2. hole
    else:
        # First hole depends on specs for VB36 M / 16 for 16 mm boards from
        # Hettich.
        holetop = 9.5  # holedistance for screw of vb36
        hole1 = 9.5 + 0.5  # distance hole 1 from end of board
        hole1r = 10  # radius first hole
        hole1d = 12.5  # deepness first hole
        hole2r = 5  # radius 2. hole
        hole2d = 10.5  # deepness 2. hole

    if debug:
        App.Console.PrintMessage("hole1d = {}\n".format(hole1d))

    # functions
    def cut(tool):
        global cutsnr
        global cuts
        # cuts objects defined in string cuts
        if debug:
            App.Console.PrintMessage("cuts = {}, cutsnr = {}\n".format(
                cuts, cutsnr))
        data = 'App.activeDocument().addObject("Part::Cut","' + str(cuts.split(" ")[cutsnr + 1]) + '")'
        if debug:
            App.Console.PrintMessage(str(data) + "\n")
        exec(data)
        data = "App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
        data = data + ".Base = App.activeDocument()." + str(cuts.split(" ")[cutsnr])
        if debug:
            App.Console.PrintMessage(str(data) + "\n")
        exec(data)
        data = "App.activeDocument()." + str(cuts.split(" ")[cutsnr + 1])
        data = data + ".Tool = App.activeDocument()." + str(tool)
        if debug:
            App.Console.PrintMessage(str(data) + "\n")
        exec(data)
        cutsnr = cutsnr + 1
        cuts = cuts + " Cut%03d" % cutsnr
        return 0

    # end functions

    doc = App.activeDocument()

    # Korpus
    box = doc.addObject("Part::Box", "Box")
    box.Label = "Cube"
    box.Length = length
    box.Width = width
    box.Height = height
    # Change Color of Object.
    box.ViewObject.DiffuseColor = (0.67, 0.67, 0.0)
    if debug:
        doc.recompute()
    # Groove
    groove = doc.addObject("Part::Box", "Groove")
    groove.Label = "Groove"
    groove.Length = groovethickness
    groove.Width = groovedeep
    groove.Height = height - (2 * groovedeep)
    groove.ViewObject.DiffuseColor = (0.67, 0.67, 0.0)
    groove.Placement = App.Placement(
        App.Vector(length - groovethickness, 0, groovedeep),
        App.Rotation())
    if debug:
        doc.recompute()

    # make endholes
    cylinders = ""  # labels of cylinders to cut
    if endholes == 'y':
        # Bottom holes
        cylendl = doc.addObject("Part::Cylinder", "Cylinderendl")
        cylendl.Label = "Cylinderendl001"
        cylendl.Radius = bradius
        cylendl.Height = bdeep
        cylendl.Angle = 360
        cylinders = cylinders + " " + cylendl.Name
        cylendl.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        doc.ActiveObject.Placement = App.Placement(
            App.Vector(fdist, bdeep, holetop),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()
        cylendr = doc.addObject("Part::Cylinder", "Cylinderendr")
        cylendr.Label = "Cylinderendr001"
        cylendr.Radius = bradius
        cylendr.Height = bdeep
        cylendr.Angle = 360
        cylinders = cylinders + " " + cylendr.Name
        cylendr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylendr.Placement = App.Placement(
            App.Vector(length - fdist, bdeep, holetop),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        # Top holes
        cylendl = doc.addObject("Part::Cylinder", "Cylinderendl")
        cylendl.Label = "Cylinderendl002"
        cylendl.Radius = bradius
        cylendl.Height = bdeep
        cylendl.Angle = 360
        cylinders = cylinders + " " + cylendl.Name
        cylendl.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylendl.Placement = App.Placement(
            App.Vector(fdist, bdeep, height - holetop),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()
        cylendr = doc.addObject("Part::Cylinder", "Cylinderendr")
        cylendr.Label = "Cylinderendr002"
        cylendr.Radius = bradius
        cylendr.Height = bdeep
        cylendr.Angle = 360
        cylinders = cylinders + " " + cylendr.Name
        cylendr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylendr.Placement = App.Placement(
            App.Vector(length - fdist, bdeep, height-holetop),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    if fillwithholes == 'n':
        n = 0
    else:
        n = int(height / 2 / holedistance)

    # drill holes from bottom to half height
    # reduce holes for test to 2 alternative use n
    # Holes for Hettich VB36
    # Bohrloecher
    x = -1  # init value
    if connector >= 1:
        x = 0
        App.Console.PrintMessage("x="+str(x) + " " + "\n")
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = hole1r
        cyll.Height = hole1d
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, hole1d, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = hole1r
        cylr.Height = hole1d
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(length - fdist, hole1d, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))

    if connector == 2:
        x = 1
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = hole2r
        cyll.Height = hole2d
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, hole2d, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = hole2r
        cylr.Height = hole2d
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(length - fdist, hole2d, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    xs = x + 1
    for x in range(xs, n):
        # Bohrloecher
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = bradius
        cyll.Height = bdeep
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, bdeep, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = bradius
        cylr.Height = bdeep
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(length - fdist, bdeep, hole1 + x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    # drill holes from Top to half height
    # # Holes for Hettich VB36
    x = -1  # init value
    if connector >= 1:
        x = 0
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = hole1r
        cyll.Height = hole1d
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, hole1d, height - hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = hole1r
        cylr.Height = hole1d
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(length - fdist, hole1d, height-hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    if connector == 2:
        x = 1
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = hole2r
        cyll.Height = hole2d
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, hole2d, height - hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = hole2r
        cylr.Height = hole2d
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(
                length - fdist, hole2d, height - hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    xs = x + 1
    for x in range(xs, n):
        # Drillholes
        cyll = doc.addObject("Part::Cylinder", "Cylinderl")
        cyll.Label = "Cylinderl%03d" % x
        cyll.Radius = bradius
        cyll.Height = bdeep
        cyll.Angle = 360
        cylinders = cylinders + " " + cyll.Name
        cyll.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cyll.Placement = App.Placement(
            App.Vector(fdist, bdeep, height - hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

        cylr = doc.addObject("Part::Cylinder", "Cylinderr")
        cylr.Label = "Cylinderr%03d" % x
        cylr.Radius = bradius
        cylr.Height = bdeep
        cylr.Angle = 360
        cylinders = cylinders + " " + cylr.Name
        cylr.ViewObject.DiffuseColor = (0.0, 0.0, 0.0)
        cylr.Placement = App.Placement(
            App.Vector(
                length - fdist, bdeep, height - hole1 - x * holedistance),
            App.Rotation(App.Vector(1, 0, 0), 90))
        if debug:
            doc.recompute()

    if debug:
        App.Console.PrintMessage("cylinders = ")
        App.Console.PrintMessage(cylinders + "\n")

    # cut all holes
    cuts = "Box Cut"  # cut labels
    cutsnr = 0     	# index number in cuts
    # cut groove
    cut("Groove")
    cyls = cylinders.split()  # number of words
    if debug:
        App.Console.PrintMessage("n=" + str(cyls) + "\n")
    for x in cyls:
        if debug:
            App.Console.PrintMessage("cylinder(" + x + ")=" + str(x) + "\n")
        cut(str(x))
    doc.recompute()

# OS: Ubuntu 14.04.1 LTS
# Word size of OS: 32-bit
# Word size of FreeCAD: 32-bit
# Version: 0.15.4410 (Git)
# Branch: master
# Hash: 9ee08a97ea81304e2690694f76ee2dc013556a5d
# Python version: 2.7.6
# Qt version: 4.8.6
# Coin version: 4.0.0a

Links

Other languages:
English • ‎français • ‎italiano