Close



Results 1 to 10 of 72

Threaded View

  1. #10
    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
    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.
    Here is a piece of OpenScad code I wrote to make ridged beams. I was making a Pump Jack for my brother that just graduated from University of Texas as a Petroleum Engineer. I wanted things as big as they could be because this was going to sit on his desk. But I ran into problems with the beams warping when they were long.

    This is a good example of how to use modules to insulate yourself from a problem. I already had a module that made a ridged_beam() and let me set numbers to build it. But then I defined a module to make a stress_relieved_ridged_beam() that took some input numbers and generated an 'appropriate' beam from them.

    And at a higher level, it only takes a few lines of code to make the base() with all these fancy holes. If I need to do further work to reduce stress on the model, I just have to do it in the one routine stress_relieved_ridged_beam() and it will automatically get replicated everywhere that function is used. If the topic is of interest to you, you can zoom in and see the miniature cuts between each big hole to eliminate stress build up on the early layers.

    PumpJack_Base.jpg

    Proper and judicious use of 'module' can help make your code more maintainable and easier to reuse. (Not to mention... Easier for other people to understand!!!!)
    Attached Files Attached Files

Posting Permissions

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