Close



Results 1 to 10 of 72

Threaded View

  1. #10
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912

    Modules - OpenScad's answer to toolbar icons?

    I was reading this, http://blog.cubehero.com/2013/12/18/...d-code-part-i/ and came across this example of a module,

    module ring(height, radius, radial_width) {
    difference() {
    cylinder(h = height, r = radius + radial_width / 2);
    translate([0, 0, -1])
    cylinder(h = height + 2, r = radius - radial_width / 2);
    }}

    After studying it for a while, it dawned on me that the module was like an icon on the object creation toolbar of a GUI based progam like Rhino. With Rhino, if I want to create a 3D object, or perform some action on one, I click on an icon on a toolbar, or in a drop-down menu. Then the program prompts me to input the parameters necessary to achieve the particular result at the time. In OpenScad, there is no icon, but a block of text called a "module". These modules are user created and result in the creation of a specific object.

    Having created a general set of steps that OpenScad must take to create an object, it only requires the user to provide the parameters specific to the object being made at the time. This is done by writing this:

    ring (height, radius, radial width) in the body of the code. To keep with convention, this would actually be coded as ring(h,r,rw)

    This would be how it would appear in practice:

    // ring implemented with rotational extrusion
    module ring(height, radius, radial_width) {
    rotate_extrude()
    translate([radius, 0, 0])
    square([radial_width, height]);
    }
    // There might be lines and lines of code before the need to enter specific values //to create the ring
    ring(4,10,5);

    QUESTIONS:

    1. Say I've just created a module to make a whatsit, and I'm going to be making whatsits of various sizes in the future. If I click on <Save As> in Openscad do I save my .scad file here
    C:\Program Files\OpenSCAD\Libraries?
    2. If I've saved my module as whatsit.scad, can i create a whatsit using this bit of code:

    use <whatsit.scad>
    whatsit (parameters);

    3. Which is better practice, putting this in the code:
    module ring(height, radius, radial_width)
    {
    difference()
    {
    cylinder(h = height, r = radius + radial_width / 2);
    translate([0, 0, -1])
    cylinder(h = height + 2, r = radius - radial_width / 2);
    }}

    or this:
    use <ring.scad>
    ring(h,r,rw);

    OME
    Last edited by old man emu; 12-10-2014 at 06:18 AM.

Posting Permissions

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