Close



Results 1 to 10 of 72

Hybrid View

  1. #1
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    Here's the link: http://www.openscad.org/cheatsheet/index.html

    Yes! Yes! Hasten slowly.

    I did a bit of that tonight, and here's the little bit of code I ended up with. The object is a toddler's Duplo building block. It took about half an hour to do, and that involved going back and forth to the cheat sheet.

    Here's my notes for the object, except that I was going to make a four peg block when I pinched the Duplo from my grandson. The first design decision I made was to make a block with a single peg, then multiply and join the single one.

    Duplo Sketch.jpg

    After some reading; some cut and paste, and some delete and replace work, I came up with this:

    Single Duplo Block.scad

    Critique appreciated.

    How do you get a grid displayed for measurement purposes? Working out where the centres of the spheres and cylinder was what took most of the time with this exercise.

    Old Man Emu
    Last edited by old man emu; 12-05-2014 at 02:15 AM.

  2. #2
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Quote Originally Posted by old man emu View Post
    How do you get a grid displayed for measurement purposes? Working out where the centres of the spheres and cylinder was what took most of the time with this exercise.
    A sphere and cylinder are always generated at (0,0). So when you translate them... what ever amount you translated them... Is where the center's are. I warmed over your code so you can see how to make your code easier to understand:
    Code:
    singleduploblock();
    
    module singleduploblock () {
    $fn=100;
    cube (32,32,20); color("gray", 0.5) translate([16,16,20]) cylinder(36, d=30); difference() {
    color("red" ) translate([16,16,55]) sphere(d=30); color ("lime") translate ([ 8,8,68 ]) cube([16,16,8]);
    }
    }
    First, in OpenScad you should have a 'Top Level' geometry. That is what that first singleduploblock(); is. It references other stuff, but it is at the top level.

    singleduploblock() does not have any paremeters, and certainly does not need its name passed in as a parameter.

    It is typical, and usually better to put modifiers like color() in the front of the line. And it is usually best to combine things that go together like color(), translate() and cube() so it is easy to pick out what everything is doing.

    And of course, indenting really helps too. For example, having things indented makes it easier to see what the difference() is operating on. The code directive isn't working perfectly on this post... But you can see what I mean even though I'm restricted on how to indent 'properly'. You only have one module in this file so this won't be as clear. But a lot of people indent everything within a module so it is clear where a module starts and ends. The module declarations are part of the 'top level' so they are pushed as far to the left as possible. As you get nested deeper and deeper, you indent more and more to show that.

    Even though what I posted is almost exactly what you had... most people would prefer to work with my version.
    Last edited by Roxy; 12-03-2014 at 09:47 AM.

  3. #3
    Staff Engineer printbus's Avatar
    Join Date
    May 2014
    Location
    Highlands Ranch, Colorado USA
    Posts
    1,437
    Add printbus on Thingiverse
    Quote Originally Posted by Roxy View Post
    ...And of course, indenting really helps too...
    Another good habit for anywhere brackets are used is to comment the closing bracket to explain what it closes, exactly like CA did in his fully annotated script.

Posting Permissions

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