by spencer 3 years, 11 months ago
2 times 2.95s avg. build time

Layout Demo

Want to print multiple objects at once? Use spencer's layout module!

License: CreativeCommons-ShareAlike Publicly Listed: True Tags: demo,layout,arrangement,plate,build plate,modules,scripts

Log in to download models or make your own copy!

Auto Apply Changes

  1. # This Part shows off the layout module. The current version is 1.0, and is available from
  2. # https://parametricparts.com/user_media/user_modules/layout-v1.0.py
  3. # Check back here for future updates
  4. #
  5. #
  6. # Usage:
  7. # result = result.layout(width,height)
  8. #
  9. # DESCRIPTION
  10. #
  11. # This script arranges parts so that they fit on a build plate of specified size.
  12. # The algorithm used is not particularly smart, and may fail to find a solution
  13. # for some combinations of part sizes. The solution tends to be best for many
  14. # small objects.
  15. #
  16. # For those interested, it implements the algorithm described here
  17. # http://www.blackpawn.com/texts/lightmaps/default.html
  18. #
  19. # KNOWN BUGS & LIMITATIONS
  20. #
  21. # * If an object does not fit in the build area, it will not be modified. This
  22. # will probably result in it overlapping with the properly arranged parts.
  23. # * Parts are not rotated to fit better
  24. # * Uses rectangular, XY-aligned bounding boxes, so could waste a lot of space
  25. # * Objects sometimes overlap (needs to be fixed)
  26. #
  27. # by Spencer Bliven 2013.
  28. #
  29. # This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
  30. UOM = "mm"
  31. #
  32. # PARAMETERS and PRESETS
  33. # These parameters can be manipulated by end users
  34. #
  35. # Parameters for the Layout
  36. buttons = IntegerParam(min=1,max=100,presets={'default':15},group="Layout", desc="Number of buttons to print")
  37. needles = IntegerParam(min=0,max=100,presets={'default':0},group="Layout", desc="Number of needles to print")
  38. buildWidth = FloatParam(min=1,max=1000,presets={'default':100,},group="Layout", desc="Width of your build plate")
  39. buildHeight = FloatParam(min=1,max=1000,presets={'default':100,},group="Layout", desc="Height of your build plate")
  40. padding = FloatParam(min=0,max=20,presets={'default':1,},group="Layout", desc="Minimum padding between items")
  41. # Parameters for the Buttons themselves
  42. radius = FloatParam(min=1.,max=500.0,presets={'default':10.0,},group="Button", desc="Radius of the button")
  43. holeSpacing = FloatParam(min=0.,max=10.0,presets={'default':3.0,},group="Button", desc="Spacing betwee hole centers")
  44. holeRadius = FloatParam(min=0.,max=10.,presets={'default':1.,},group="Button", desc="Radius of the button holes")
  45. thickness = FloatParam(min=0.,max=100.,presets={'default':2.,},group="Button", desc="Thickness of the button")
  46. needleLength = FloatParam(min=1,max=500.0,presets={'default':40},group="Needle", desc="Length of the needle")
  47. needleThickness = FloatParam(min=0.1,max=500.0,presets={'default':2},group="Needle", desc="Thickness of the box")
  48. def button():
  49. """A simple parametric button"""
  50. result = Workplane("XY").circle(radius.value)
  51. result = result.rect(holeSpacing.value,holeSpacing.value,forConstruction=True).vertices().circle(holeRadius.value)
  52. result = result.extrude(thickness.value)
  53. return result
  54. def needle():
  55. """An ugly unprintable needle"""
  56. needle = Workplane("XY",Vector(2.5,0,0)).box(needleLength.value-10,needleThickness.value,needleThickness.value,centered=(False,True,False))
  57. needle = needle.faces("+X").workplane().rect(needleThickness.value,needleThickness.value).workplane(offset=5).rect(.1,.1).loft()
  58. eye = Workplane("XY").circle(2.5).circle(1.5).extrude(needleThickness.value)
  59. result = needle.add(eye)
  60. return result.combine()
  61. #
  62. # Your build method. It must return a solid object
  63. #
  64. def build():
  65. # Load the layout script
  66. tools.loadScript("https://parametricparts.com/user_media/user_modules/layout-v1.0.py")
  67. # Add a bunch of objects to the stack.
  68. # Note that all objects are initially located at the origin
  69. result = button()
  70. for i in xrange(0,needles.value):
  71. result = result.add( needle() )
  72. for i in xrange(1,buttons.value):
  73. result = result.add( button() )
  74. # Layout the buttons on the build plate automatically
  75. result = result.layout(buildWidth.value,buildHeight.value,padding.value)
  76. return result.combine()