# A small script to make a ruler Classic List Threaded 5 messages Open this post in threaded view
|

## A small script to make a ruler

 I occasionally find it useful to make measurements in a model (in complex models, it's not always easy to get the distance from A to B by calculations, and you just need a ballpark figure), or simply have a size reference (for example, when designing my porch, I need something to relate to, to see how it'll work in reality). So, I made this simple little script, which draws a ruler of arbitrary length, with only the scales needed for the actual length drawn (so, for a half meter ruler, I don't draw meter steps). Just include with use , and call it to draw the ruler. You can, of course, use rotate and translate to move it around as needed (or, if you like, scal and resize, but that wouldn't make much sense...). It's also a simple example of parametric design. Hope you'll find it useful! Here goes: // Draws a ruler of specified length. // Origin of the ruler is at 0, and it is laid out along the X axis. // Call with: ruler(length); module ruler(length){     difference(){         //draw ruler         union(){             offset=0;             for(n=[1:4]){                 offset=pow(2,n+1)-2;                 translate([0,-offset,0])                 drawscale(length,pow(10,n-1),pow(2,n));             }         }         //cut of protruding end bits         color([0,0,0])         translate([length,-38,-1])         cube([1000,38,3]);     } } //Draws the different scales, as needed. Don't call directly. module drawscale(length,step,width){     if(length>step){             for(n=[0:step:length-1]){             if(n%(2*step)==0){                  color([0,0,0])                  translate([n,0,0])                  cube([step,width,1]);               }else{                  color([1,1,1])                  translate([n,0,0])                  cube([step,width,1]);               }         }     } } //Test ruler(1201); -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: A small script to make a ruler

 Elegant! License?On Thu, Oct 5, 2017 at 7:52 AM, Troberg wrote:I occasionally find it useful to make measurements in a model (in complex models, it's not always easy to get the distance from A to B by calculations, and you just need a ballpark figure), or simply have a size reference (for example, when designing my porch, I need something to relate to, to see how it'll work in reality). So, I made this simple little script, which draws a ruler of arbitrary length, with only the scales needed for the actual length drawn (so, for a half meter ruler, I don't draw meter steps). Just include with use , and call it to draw the ruler. You can, of course, use rotate and translate to move it around as needed (or, if you like, scal and resize, but that wouldn't make much sense...). It's also a simple example of parametric design. Hope you'll find it useful! Here goes: // Draws a ruler of specified length. // Origin of the ruler is at 0, and it is laid out along the X axis. // Call with: ruler(length); module ruler(length){     difference(){         //draw ruler         union(){             offset=0;             for(n=[1:4]){                 offset=pow(2,n+1)-2;                 translate([0,-offset,0])                 drawscale(length,pow(10,n-1),pow(2,n));             }         }         //cut of protruding end bits         color([0,0,0])         translate([length,-38,-1])         cube([1000,38,3]);     } } //Draws the different scales, as needed. Don't call directly. module drawscale(length,step,width){     if(length>step){         for(n=[0:step:length-1]){             if(n%(2*step)==0){                  color([0,0,0])                  translate([n,0,0])                  cube([step,width,1]);             }else{                  color([1,1,1])                  translate([n,0,0])                  cube([step,width,1]);             }         }     } } //Test ruler(1201); -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|