by fabberking 2 years, 7 months ago
2 times 2.35s avg. build time

Configurable hole gauge

License: CreativeCommons-ShareAlike Publicly Listed: True Tags: None

Log in to download models or make your own copy!

Auto Apply Changes

  1. # Hole gauge
  2. #
  3. # (c) 2014 fabberking.com
  4. # Important MetaData
  5. #
  6. UOM = "mm"
  7. # PARAMETERS and PRESETS
  8. # These parameters can be manipulated by end users
  9. #
  10. DEFAULT_PRESET = '0.2mm step'
  11. x_num_of_holes = IntegerParam(min=1,max=10,presets={'0.2mm step':5, '0.1mm step':10},group="Basics", desc="number of holes from left to right")
  12. diameter_increment = FloatParam(min=0.1,max=1.0,presets={'0.2mm step':0.2, '0.1mm step':0.1},group="Basics", desc="diameter increment from hole to hole")
  13. diameter_of_first_hole = FloatParam(min=0.1,max=99.0,presets={'0.2mm step':3.0, '0.1mm step':3.0},group="Basics", desc="diameter of smallest hole (bottom left hole)")
  14. y_num_of_holes = IntegerParam(min=1,max=10,presets={'0.2mm step':1, '0.1mm step':1},group="Basics", desc="number of holes from bottom to top")
  15. thickness = FloatParam(min=2.0,max=30.0,presets={'0.2mm step':8, '0.1mm step':8},group="Basics", desc="thickness of the gauge")
  16. wall_min = FloatParam(min=1.0,max=5.0,presets={'0.2mm step':2, '0.1mm step':2},group="Basics", desc="min wall width between holes")
  17. # Your build method. It must return a solid object
  18. #
  19. def build():
  20. d_list = []
  21. d_now = diameter_of_first_hole.value - diameter_increment.value
  22. for y in xrange(0, y_num_of_holes.value):
  23. for x in xrange(0, x_num_of_holes.value):
  24. d_now = d_now + diameter_increment.value
  25. d_list.append(d_now)
  26. d_list_x = d_list[ ((y_num_of_holes.value - 1) * x_num_of_holes.value): ]
  27. box_x = sum(d_list_x) + (x_num_of_holes.value + 1) * wall_min.value
  28. d_list_y = d_list[(x_num_of_holes.value - 1)::x_num_of_holes.value]
  29. box_y = sum(d_list_y) + (y_num_of_holes.value + 1) * wall_min.value
  30. part = Workplane("XY").rect(box_x, box_y, centered=False).extrude(thickness.value)
  31. part = part.edges().fillet(1.0)
  32. y_now = 0.0
  33. for y in xrange(0, y_num_of_holes.value):
  34. y_now = y_now + wall_min.value + d_list_y[y] / 2
  35. x_now = 0.0
  36. for x in xrange(0, x_num_of_holes.value):
  37. x_now = x_now + wall_min.value + d_list_x[x] / 2
  38. hole = Workplane("XY").center(x_now, y_now) \
  39. .circle(d_list[x + y * x_num_of_holes.value] / 2) \
  40. .extrude(thickness.value)
  41. part = part.cut(hole)
  42. # prepare for next iteration: add missing x radius
  43. x_now = x_now + d_list_x[x] / 2
  44. # prepare for next iteration: add missing y radius
  45. y_now = y_now + d_list_y[y] / 2
  46. return part