Close



Results 1 to 10 of 32

Threaded View

  1. #5
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    well that is insanely long for a simple box generator. I suppose it does have a lid as well.
    But honestly you are better off starting by making your own. #
    A simple box is a great way to start:

    difference(){
    cube ([50,20,10],center=true);
    translate([0,0,2]) cube ([46,16,10],center=true);
    } // end difference
    viola - a box with 2mm thick walls and base and 50mm long by 20 wide and 10mm tall - good for screws and bits.

    To make this parametric you just need to indulge in a little algebra and throw in some variables

    bl=50; // box length
    bw=20; // box width
    bh=10; //box height
    wt=2; // wall thickness
    bt=1; // base thickness

    difference(){
    cube ([bl,bw,bh],center=true);
    translate([0,0,bt])cube ([bl-2*wt,bw-2*wt,bh],center=true);
    } // end difference
    And that's a 2 line cubic box generator.

    To make a different shape box you use cylinders instead of cubes and change the number of facets to the shape you want.
    so a 4 facet cylinder is a cube and a 3 facet cylinder is a triangle. You use a resize command to change the shape from a fixed diameter 'cylinder' to the length and breadth you specify. :

    bl=50; // box length
    bw=20; // box width
    bh=10; //box height
    wt=2; // wall thickness
    bt=1; // base thickness
    bs=3; // box shape

    difference(){
    resize([bl,bw,bh]) cylinder(d=10,h=10,$fn=bs);
    translate([0,0,bt]) resize([bl-2*wt,bw-2*wt,bh]) cylinder(d=10,h=10,$fn=bs);
    } // end difference
    2 line infinite shape box generator.

    So you start with a simple centred cube and difference a smaller cube - if you center it you don't have to muck about with moving it about to get it centred yourself.
    wall thickness happens on both sides of the shape - so you always have to multiply it by 2.

    In the second example you use algebra to make the sizes variable.
    And in the third example you use different number sided 'cylinders' to change the number of sides of the shape.
    A resize command over rules all subsequent sizes - so it doesn't matter what size you make the original cylinder.

    I don't do programming - so i approach openscad very differently to programmers.
    I like to make it easy to read what I've done - so I use short variables and never indent anything. Most programmers use whole sentences for variables and end up with something almost unguessable - in my opinion ;-)

    The beauty of openscad is that you can write the scripts any way you like.
    The way I approach a design problem is also simple.
    work out what you want to make and then break it down into simple shapes. Then work out what shapes need to be added or removed and where they need to be and go from there.

    It does seem daunting at first.
    But once you've got your own script style that you can read and have worked out what the commands do - it's really a lot better and more precise than moving stuff around with a mouse.

    And so much faster !

    Also - and one of it's best points - everything generated by a script is a solid shape that will print.
    No errors.

    As far as all the different brackets and why they are where there are, goes, don't sweat it.
    Just get into the habit of putting them where the cheatsheet says they should go and don't worry about what they do :-)

    Last edited by curious aardvark; 03-11-2021 at 08:21 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •