Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - raymw

Pages: 1 2 [3]
31
General Discussion / Re: a first stab at something useful
« on: 2020-08-11, 18:43:22 »
Thanks, I never actually saw the warning messages. I test printed the boxes as I wrote the code,  I have about 18 pla boxes, not many any use (trying to sort the printer out at the same time). I've now added rounded edges, and tried to do rounded corners, too, but not much success there. Easier to use a bit of sandpaper! I don't think I'll 'counterbore' the screwholes.

32
General Discussion / a first stab at something useful
« on: 2020-08-07, 20:49:26 »
I've only been playing around with angelcad for a few weeks, but I like the structure so far, and the ood aspects of it. Not having a background in c++, I find the syntax somewhat confusing, but I know that will change as I had a load of help from Carsten. I thought I'd show a component box, which can be 3d printed. It is designed such that sizes, ventilation, standoffs can be readily changed. Depending on the quality of the 3d print, you may need to adjust the 'shave' value, so that the lid fits nicely. I recently added rounded corners to the lid, (thinlid, in code) because often internal corners of 3d prints are not sharp. There are other alterations I may or may not make, and if anyone wants to modify or otherwise use it, feel free to do so.

 
Code: [Select]
// AngelCAD code.

//inside dimensions of box
   double y= 45;
   double x= 51;
   double z= 15;
//wall thickness   
   double wall=2.5;
// x1,y1,x3,y3 defines corners of ventilation hole area
   double x1= 15;
   double y1=15;
   double x3=36;
   double y3=30;
//hole is width of inividual ventilation hole   
   double hole =3;
//space is hole spacing   
   double space= 5;
//select if you want want ventialtion holes in box or lid  or both 
   bool lidhole = true;
   bool boxhole = false;
//soh is standoff height, sod is standoff diameter   
   double soh = 5 ;
   double sod = 6 ;
//shole is diameter of hole in centre of standoff   
   double shole = 2;
// son is number of standoffs
   int son =4;
// if you add more standoffs, adjust number 'son', above.
// if you don' twant standoffs, set son to 0, but leave values in stands
// (x,y) position of standoffs 'stands'
   array<pos2d@ > stands  = {
     {6,6},
     {45,6},
     {6,39},
     {45,39}
     };
//shave is to give clearance for lid lip
//value of shave may depend on manufacturing method.   
  double shave=0.5;
 
 
 // fixed values below........
 // no need to edit values below here
 //*******************************************
 
 // w2 is half the wall thickness
   double w2= wall/2;
   
solid@ box()   //create box
{
   //smaller cuboid for inside
   solid@ boxis = cuboid(x,y,z+wall, false);
   // add walls to create outside of box
   solid@ boxos = cuboid(x+wall+wall,y+wall+wall,z+wall,false);
   //subtract inner from outer
   solid@ crate= translate(-wall,-wall,-wall)*boxos -boxis;
   //add lip to top size (0.5*wall) on outer edge
   solid@ lip= cuboid(x+wall+wall,y+wall+wall,wall) -translate(w2,w2,0)*cuboid(x+wall,y+wall,wall);
  solid@ all= translate (-wall,-wall,z-w2)*lip +crate;
return all;
}

solid@ thinlid(){
   
  //puts a 1mm radius on lip of inserted top
shape2d@ top= offset2d (rectangle (x+wall-shave-2,y+wall-shave-2),r:1);
return transform_extrude (top,translate(0,0,w2)*top);
   }

solid@ lid()  //similar to box, but only half wall high rim
{
  solid@ topbig = cuboid(x+wall+wall,y+wall+wall,w2, false);
   //add insertedhalf wall (make it shave smaller to fit inside lip of box)
   
   solid@ topall =topbig + translate(w2+1+(shave/2),w2+1+(shave/2),w2)*thinlid();
   // add lid holes (diam 1.3 * shole) in corners for fixing screws
   double r = (1.3*shole)/2;
   double hr =shole/2;
   solid@ h1 = translate (hr+wall,hr+wall,-wall)*cylinder(20,r);
   solid@ h2 = translate (hr+wall,y+wall-hr,-wall)*cylinder(20,r);
   solid@ h3 = translate (x+wall-hr,hr+wall,-wall)*cylinder(20,r);
   solid@ h4 = translate (x-hr+wall,y-hr+wall,-wall)*cylinder(20,r);
return translate (-wall,-wall,-wall)*(topall - h1 - h2 - h3 - h4);
 
 
    }
   
solid@ sup()    //support for pcb and screw holes for lid (standoff)
{
   solid@ block= cylinder(soh,sod/2,true)-cylinder(soh,shole/2,true);
   return translate(0,0,soh/2)*block;
}
 
solid@ standoffs()    // add standoffs
{
   array<solid@> p;
   for (int j=0;j<son;j++)
      {
      p.push_back( translate(stands[j].x(),stands[j].y(),0)*sup());
      }
return union3d(p);
}
 
solid@ holes()    // number of ventilation holes in each direction
{
   int nx= int((x3-x1)/space) ;
   int ny= int((y3-y1)/space) ;
   double dx=space;
   double dy=space;
   // create an array of cuboids a grid pattern in 1st quadrant
   array<solid@> h;
   for (int ix=0;ix<=nx;ix++)
   {
      for (int iy=0;iy<=ny;iy++)
      {
         double xh = x1 + ix*space;
         double yh = y1 + iy*space;
       h.push_back(translate(xh,yh,0)*cuboid(hole,hole,100,true));
      }
   }
   // return the cylinders as a single solid
return union3d(h);   
}

solid@ fix()     // fix standoffs at top corners for screws for lid
{
   double hr =shole/2;
   solid@ h1 = translate (hr,hr,z-soh)*sup();
   solid@ h2 = translate (hr,y-hr,z-soh)*sup();
   solid@ h3 = translate (x-hr,hr,z-soh)*sup();
   solid@ h4 = translate (x-hr,y-hr,z-soh)* sup();
return h1 + h2 + h3 + h4;
}
 
solid@ boxholed()  //add ventilation holes to box if required
{
   if (boxhole == true)
      {     
      return box() - holes();
      }
return box();
}
           
solid@ lidholed()  //add ventilation holes to lid if required
{
   if (lidhole == true)
     {
      return lid() -holes();
      }
return lid();     
}
     
void main()    //put all the parts together
{
   solid@ both=boxholed()+translate(0,y+3+wall+wall,0)*lidholed() +fix()+standoffs();
   both.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

edited the above code to correctly offset resized rounded corner lid part - hopefully fits now!

Pages: 1 2 [3]