Close



Results 1 to 6 of 6
  1. #1
    Student
    Join Date
    May 2021
    Location
    Pacific NorthWet
    Posts
    13

    OpenSCAD: Sneaky handy tricks.

    Offering one - Asking for 2 more LOL

    Partial one as a bonus - I use function i2mm(I) = I * 25.4; in must of my scripts, handles inches to mm conversions for me.

    For hexagons like a hexagonal button, use cylinder() with $fn set to 6, you could use $fn set to 8 for octagons etc., devious but works

    The two I need help on, are,

    a) How would I place hexagonal buttons in regular, offset rows/columns efficiently?

    b) For making a floor have alternating color tiles (or the like) I know I could add x and y together, mod 2 if needed, then if even (or 0) pick one tile color, otherwise the other; is there a better way?

    Thanks, all
    Last edited by Mr_Sheesh; 05-13-2021 at 07:30 AM. Reason: Fixing it back into separate sentences, was all concatenated

  2. #2
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,463
    ss=4.8; // shaft sixe
    sh=10; //socket height
    ns=6; //number of sockets
    wt=0.8; //wall thickness
    shs=6; //number of sides of shaft
    eg=1.3; // extra gap between sockets

    difference() {
    for (i = [0:ns-1]) translate([0,(eg*i*ss),0]) cylinder(d=ss+2*wt,h=sh,$fn=40);
    for (i = [0:ns-1]) translate([0,eg*i*ss,wt]) cylinder(d=ss,h=sh,$fn=shs);
    } // end diff
    play with that.
    It's actually a script to generate strips of bit holders I print them from tpu.

    Now if you lose the difference.
    You get a single line of script that can generate any size hexagons with any size gap between them.
    And another 'for' loop and you can then generate vertical columns of the horizontal rows.
    A little algebra will offset the different rows. There is a way to tell if a number is odd oir even and then do something with it.
    I'd do the below work around :-)

    Or - what i';d do because I'm lazy.
    Create two unioned already offset rows inbetween a 'for' operation. so you just duplicate the two already offset rows - however many times you like.

    If you use a dual diameter cylinder, you also create the top wide hexagon he has in the drawing.

  3. #3
    Student
    Join Date
    May 2021
    Location
    Pacific NorthWet
    Posts
    13
    Been doing tapered cylinders, for loops, rotates, translates, unions, diffs, minkowskis, all kinds of goodies, but the fact that I can brute force something doesn't always make it feel elegant or efficient.

    Been coding since 70 or so, back when your home PC had 32kB of RAM if you could afford to max it out, still sometimes weirds me out that nowadays 8GB of RAM is a "minimal" amount... I try to be efficient despite that, LOL

    Don't see much need for mark sense reader repair, keypunch fixing, etc., any more either LOL

  4. #4
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,463
    see I'm not a programmer.

    So I use openscad like an amazing wood working tool :-)
    Totally different approach.

    My scripts can be truly awful - but at the end of the day they all work. And that's all I'm after.

    There are dozens of openscad commands and procedures I have never used.
    Some because I simply do not understand what the 'manual' says.
    Some because i just don't understand the maths behindg them.
    Some because I don't think in 2d - so most 2d stuff doesn't fit in my brain.

    And some simply because I have absolutely no idea 'why', let alone 'what' they are for.

    take the 'children' command.
    just ???????????????????????????????????
    I'm sure it would be really useful - I just can't work out what or why or how it does whatever the hell it does.

    But I do understand loops and basic algebra. And that's pretty much all you actuially need :-)

    Some of the other stuff would probably be really useful - I just need someone who can explain it in human and not cyborg/programmer terms :-)

  5. #5
    Student
    Join Date
    May 2021
    Location
    Pacific NorthWet
    Posts
    13
    That person would NOT be me, sadly, I am, however, good at causing folks' eyes to glaze over and their brains to explode LOL

    Just a guess but I don't think that would help you much.

    Haven't used children() yet, maybe some day.

  6. #6
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,463
    so how does the function thing work ?
    Must be good for stuff other than converting inches to mm (why bother ? just use mm)

    And how would you use the function you posted in an actual script ?

    That's right - no clue what the function command does :-)

    or to be fair - even that there was one :-)
    Last edited by curious aardvark; 05-24-2021 at 02:18 PM.

Posting Permissions

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