3D part design with OpenSCAD #60: a module for making 3d printable Halbach arrays.

A module for OpenScad to 3d print a frame to hold magnets for a Halbach array.

1 min read
By Bob
3D part design with OpenSCAD #60: a module for making 3d printable Halbach arrays.

It's always fun to experiment with magnets, here's an openscad module that arranges holes around a circle so the magnets can be glued in or printed into the part. It will be pretty easy to add dxf import so any shape can be  made with Inkscape and used, right now it's pretty customizable the way it is.

Here is the code:

/*[Ring]*/ 
  Ring_height= 5; // [.1:.01:100]
  Ring_Outside_diameter = 50; //[0:.01:100] 
  Ring_Inside_diameter = 5; //[0:.01:100] 
  Ring_Outside_shape = 100; //[3:1:100]
  Ring_Inside_shape = 100; //[3:1:100]
  Ring_rotate = 0; //[0:.01:360]

/*[Magnet Holes]*/  
  Hole_size = 7; //[1:.01:100]
  Hole_depth = -1; //[-10:.01:-1]
  Hole_Ring_diameter = 20; //[0:.01:100]
  Hole_number = 7; //[1:360]
  Hole_shape = 4; //[3:1:100]
  Hole_rotate = 45; //[30:.01:120]
  
/*[Scale]*/  
Scale = 1; //[0:.01:10]

   
module MagnetHoles(){
   translate([0,0,Hole_depth])
   linear_extrude(Ring_height+2,convexity=11)
for(h=[1:Hole_number])           
   rotate([0,0,h*360/Hole_number]) 
   translate([0,-Hole_Ring_diameter,0])  
   rotate([0,0,Hole_rotate])
   circle(Hole_size/2,$fn=Hole_shape);
}   
   
 
 module Ring(){
  rotate([0,0,Ring_rotate])
  linear_extrude(Ring_height,convexity=11)
difference(){
  circle(Ring_Outside_diameter/2,$fn=Ring_Outside_shape);
  circle(Ring_Inside_diameter/2,$fn=Ring_Inside_shape);
 }}


scale([Scale,Scale,Scale]) 
difference(){ 
Ring();
MagnetHoles();
}

Here are some different designs I made by adjusting the variables: