Close



Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Technician
    Join Date
    Mar 2021
    Posts
    63
    "Your homework - make the box parametric :-)"


    Code:
    $fn=50;
    // Defining the box
    ExteriorL=100;  // Exterior cube, length
    ExteriorW=40; // Exterior cube, width
    ExteriorH=30; // Exterior cube, height
    
    InteriorL=96; // Interior cube, length
    InteriorW=36; // Interior cube, width
    InteriorH=30; // Interior cube, height
    
    // Hole making
    SphereDiam=5;
    CylDiam=10.4;
    CylHeight=3.25;
    
    difference(){
    union(){
    difference(){
    cube([ExteriorL,ExteriorW,ExteriorH],true);
    translate([0,0,2])cube([InteriorL,InteriorW,InteriorH],true);
    } // end diff
    
    translate([40,18,0]) resize([14,8,14])sphere(d=SphereDiam);
    translate([-40,18,0]) resize([14,8,14])sphere(d=SphereDiam);
    } // end union
    
    translate([40,20,0]) rotate([90,0,0]) cylinder(d=CylDiam, h=CylHeight);
    translate([-40,20,0]) rotate([90,0,0]) cylinder(d=CylDiam, h=CylHeight);
    translate([0,30,0]) cube([100,20,30],true);
    } // end diff
    The only parameters I didn't define were those for what I think of as your 'third cube'. That's your homework! ;-)

    11-CA-MagnetsInBox-Param.jpg

    (This web site has possibly the most buggy formatting/rendering I've ever seen!)
    Last edited by terrypin; 04-07-2021 at 12:47 PM. Reason: To gripe about the site rendering

  2. #12
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    not bad.
    About the only thing I'd have added would be a way to change the number of magnets and automatically move them about depending on number and size.

    Or possib;y even change the number based on the size of the box.
    But that's really overkill and i rarely bother to do stuff like that, when you can just copy and paste an existing line and change a couple numbers.
    ;-)

    Also if you have the same thickness wall on all 4 sides of a box, it's much easier to have: 'wall thickness' as a variable and saves you defining all the interior measurements of the box seperately.
    It also then allows you to use the wall thickness in placing things around the model easily.

    Your method allows for different thickness walls, kind of.

    And yeah the forum software really does not like a lot of browsers/opearting systems. We've never really tracked down exactly what combinations work best and which ones are a really bad idea.

    I think it just doesn't like apple - but that's probably just professional bias, as I hate them lol

    But for someone who hadn't even seen openscad a couple weeks ago - damn impressve :-)
    Last edited by curious aardvark; 04-11-2021 at 01:16 PM.

  3. #13
    Technician
    Join Date
    Mar 2021
    Posts
    63
    Thanks CA.

    I'm learning by the hour about each of the three main areas of my workflow: OpenSCAD, Cura and Ender 3 V2. One particular aspect of the former that I'm grappling with is visualising the effects of Difference(), especially when there's a 'hierarchy' of them. With that and Translate() too, I'm too often resorting to trial/error. I'm sure I'm not making full use of the various views in OpenSCAD and Cura.

    I was about to give you an example I'm working on right now, but I'll do so later in a separate post with a more relevant subject heading.

    But the biggest obstacle is of my own making: impatience to get stuff printed!

  4. #14
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    don't forget to use 'union'

    Basically union glues everything between it's brackets into a single lump that you can then apply any of the other operations to.

    And also it's worth knowing that you can apply operations to an entire bracket set.
    Took me a while to figure that out.

    for example:
    difference(){
    translate([0,0,10]) cube([20,20,20],true);
    translate([0,0,10]) sphere(d=25);
    } // end diff
    makes my favourite torture test model. Screw benchies if you can print the hollow cube - the machine is dialled in !

    So if we want to do something to the whole model we can simply put the operation in front of the difference and it will effecdt everything between the brackets - much like making it aseperate module does. But without the extra hassle.

    rotate([45,0,0]) resize([10,40,30]) difference(){
    translate([0,0,10]) cube([20,20,20],true);
    translate([0,0,10]) sphere(d=25);
    } // end diff
    So if you've got a section in the middle oif a module you want to change all at once - slap a set of 'union' brackets round it and apply the operations to the union operation :-)

    This is particularly useful if you use a 'minkowski' command to round off corners.
    Because minkowski takes the degree of roundness form a sphere or a cylinder. It also adds all measurements together and changes the size of the model.
    So a resize command before a minkowski command will keep the model the right size and apply more or less curvature depending on the diameter of the cylinder or sphere.

    minkowski(){
    cube([20,20,20]);
    cylinder(d=5,h=1);
    } // end mink


    versus:

    resize([20,20,20]) minkowski(){
    cube([20,20,20]);
    cylinder(d=5, h=1);
    } // end mink

    I did read the explanation of how minkowski works. And it involved robots driving around rooms on different vectors and colliding with things - yeah....

    Minkowski is a fun command to play with - but it does reqquire some serious calculation - what with all those little robots driving around.
    I really need to find that 'explanation' again - it was completely surreal.

    It's amazing just how complicated you can get with simple things.

    It's also why I always mark what operation the second curly bracket applies to. Otherwise it gets really confusing, really quickly.

    It's also why i use very short variable names.
    Some calculations for parametric models can contain several sets of bracketed calculations in a single slot. If you use long names for the variables, they become almost impossibly long and damn difficult to read.

    For example, this line from a script that makes hinged moulds for clay sling glandes: translate([(gd+hod)/2+hod/2,gl/2+st,gd/2])
    Is pretty easy to read.
    but if the variables read:
    gd=glandediameter,
    hod=hingeouterdiameter
    gl=glandelength
    st=shellthickness
    It would be so bloody long the whole thing just looks like a 60's stream of consciousness novel.
    And that's just one operation in a line of script that has several, equally convoluted operartions and a shape.

    There is frequently/occasionally (delete as appropriate) method to my madness.
    Last edited by curious aardvark; 04-12-2021 at 02:09 PM.

  5. #15
    Technician
    Join Date
    Mar 2021
    Posts
    63
    Thanks CA, good stuff there that I’m looking forward to trying out.

  6. #16
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    well I may not be much good at maths - but I've got pretty good at working round them :-)

    The minkowski thing was incredibly frustrating until i worked out i could just use a resize to keep it the right size. And then all increasing the diameter of the cylinder or sphere did was make the corners more rounded.

Page 2 of 2 FirstFirst 12

Posting Permissions

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