Modeling magnets

For reference, here is the work flow I use for building the individual magnet models (on my fedora linux desktop):

  1. Fill any holes (at least big ones) with yellow Play-Doh so annoying shadows from the scanner won't obscure any bits.
  2. Crank up the flatbed scanner on my all-in-one device and make 600 DPI scans of the top and bottom sides of the magnet to jpg files.
  3. Load the image files into gimp and use the layer rotation tools to orient the magnets to fit best in the cube (I generally like the longest dimension to be horizontal for most magnet shapes).
  4. Flip one image over to make it the same orientation as the other, then combine the images into one image with two layers.
  5. Make one layer partially transparent, then shift and rotate it till it exactly matches the other layer. Now any dimensions picked off the top will match the bottom and vice-vesa. One convenient technique is to position one hole directly over the matching hole, then rotate about the center of that hole till the other holes line up as well.
  6. You can now use the gimp lasso tool to select the shapes of the magnet, the other frame, any holes or bumps you want to include in the model, etc. I can't imagine dragging the mouse accurately enough, so I use it in single click mode where a button 1 click makes one new lasso segment and just work my way around the part I'm selecting.
  7. Through trial and error, I found that I should use the grow selection tool to grow the 600 DPI selections by 10 pixels to make a hole that will fit well without any filing down of the edges required (which would be hard if you want to drop the magnet into the hole in the middle of printing :-).
  8. To get the selections from gimp into openscad, I convert the selection to a path, then in the paths tool window I can right click the path and select export to an SVG image file.
  9. After getting the 2D shapes modeled, time to break out the calipers and measure the thicknesses to use. You can import the SVG files into openscad and use linear_extrude to make them the right thickness, union together the magnet and frame shapes, then subtract them from a cube, leaving a hole the size of the magnet's overall shape.
  10. Another thing I found by trial and error: I print these in 0.3mm resolution, and I have problems with collisions or filament curling up off the cold magnet unless I add at least two layers to the thickness I measured to give plenty of room for the nozzle to avoid collisions and the filament to extrude.
  11. To do the print, I'm using Repetier-Server, and Repetier-Host to do the slicing. I can use the print preview in one layer at a time mode to find out exactly which layer will first print across the top of the hole and edit the gcode file to add a @pause line just before that layer starts printing (special command processed by Repetier-Server). This is slightly tricky since the gcode only has Z movement commands and all I know is the layer number, but finding the first Z move tells you the level of layer one, and a little arithmetic from there will find the Z move value for the layer you want to stop at.

That all works for magnets with two mostly smooth flat sides. A bunch of my salvaged magnets are mostly flat, but have odd bumps and shapes stamped into the top. For these I use the same modeling techniques, but I make one additional model: A cover piece for the top of the magnet so that the cover is flat. I then add that to the thickness of the magnet, and when I pop the magnet in the hole, I pop in the cover along with it, and they both get embedded in the print.

Page last modified Thu Jun 3 12:00:04 2021