discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

Changing grid reference on screen?

TP
tony.pemberton.cowroast@gmail.com
Sun, Jul 24, 2022 12:00 PM

A first post so I’m probably not aware of protocol here!

I have used Openscad for the last 2.5 years and I find it great for doing my models and otherthings. I use version 2021.1. both on W7 and Debian11.

So far, I have not needed to determine absolute sizes during Openscad design stages as, by default, designs are 3D printed with metric dimensions. I am aware that Openscad is actually dimensionless but I would like to be able to determine sizes of designed objects, on screen, before committing to print.

I have searched the settings of Openscad to change the dimension scale of the X,Y and Z lines and or introduce screen grid so that I can zoom in or out to see how big an object is on screen (relatively). At present the screen scale normally shows intervals of 1(cm). I would like to be able to have an optional  grid of 0.1(mm) (not just marks on the X,Y,Z bars) when I zoom in to a very small part I am designing.

Am I missing something in the Openscad settings? It would be nice to be able to switch screen grid on or off with a function button too.

Thanks, Tony

A first post so I’m probably not aware of protocol here! I have used Openscad for the last 2.5 years and I find it great for doing my models and otherthings. I use version 2021.1. both on W7 and Debian11. So far, I have not needed to determine absolute sizes during Openscad design stages as, by default, designs are 3D printed with metric dimensions. I am aware that Openscad is actually dimensionless but I would like to be able to determine sizes of designed objects, on screen, before committing to print. I have searched the settings of Openscad to change the dimension scale of the X,Y and Z lines and or introduce screen grid so that I can zoom in or out to see how big an object is on screen (relatively). At present the screen scale normally shows intervals of 1(cm). I would like to be able to have an **optional grid** of 0.1(mm) (not just marks on the X,Y,Z bars) when I zoom in to a very small part I am designing. Am I missing something in the Openscad settings? It would be nice to be able to switch screen grid on or off with a function button too. Thanks, Tony
JB
Jordan Brown
Sun, Jul 24, 2022 7:07 PM

On 7/24/2022 5:00 AM, tony.pemberton.cowroast@gmail.com wrote:

 A first post so I’m probably not aware of protocol here!

You're fine.

I have used Openscad for the last 2.5 years and I find it great for
doing my models and otherthings. I use version 2021.1. both on W7 and
Debian11.

So far, I have not needed to determine absolute sizes during Openscad
design stages as, by default, designs are 3D printed with metric
dimensions. I am aware that Openscad is actually dimensionless but I
would like to be able to determine sizes of designed objects, on
screen, before committing to print.

I have searched the settings of Openscad to change the dimension scale
of the X,Y and Z lines and or introduce screen grid so that I can zoom
in or out to see how big an object is on screen (relatively). At
present the screen scale normally shows intervals of 1(cm). I would
like to be able to have an optional grid of 0.1(mm) (not just marks
on the X,Y,Z bars) when I zoom in to a very small part I am designing.

Am I missing something in the Openscad settings? It would be nice to
be able to switch screen grid on or off with a function button too.

First... there are no units in OpenSCAD, except what you make up for
yourself.  The screen scale is not in mm, or cm, or inches, or miles, or
smoots.  It's in OpenSCAD units, and OpenSCAD units are as large as you
want to pretend them to be.  Indeed, people often or even usually treat
them as millimeters, because that's what slicers want, but OpenSCAD
doesn't know nor care.  (When I model my house at one OpenSCAD unit per
real-world inch, and then print it at one OpenSCAD unit per millimeter,
how big is an OpenSCAD unit?)

Second... no, there's no grid mechanism.  (What would a 3D grid look
like?  Or maybe you'd lay a 2D grid on one of the axis planes.)

However, there's nothing stopping you from drawing your own grid.  Use %
so that it isn't included in your model.

Here's a semi-fancy implementation.  Rotate and reposition as desired. 
There's an argument that this should all be done in 2D, but rotating 2D
off of the XY plane bothers me.  Note that the minor ticks are pretty
small and can sometimes disappear on the display unless zoomed in.  You
might want to turn off displaying the axes.

module grid2D(min=[-100,-100], max=[100,100], minor=1, major=10) {
    minor_len = 0.3;
    minor_thick = 0.05;
    major_len = 0.6;
    major_thick = 0.2;
    thick = 0.1;
    labelsize = 2;
    yoffset = 1;
    xoffset = 1;
    close = 0.1;

    module minor_tick() {
        cube([minor_len, minor_thick, thick], center=true);
        cube([minor_thick, minor_len, thick], center=true);
    }

    module major_tick() {
        cube([major_len, major_thick, thick], center=true);
        cube([major_thick, major_len, thick], center=true);
    }

    module minor_ticks(xrange, yrange) {
        for (x=xrange, y=yrange) {
            if (abs(x%major) > close || abs(y%major) > close) {
                translate([x,y,0]) minor_tick();
            }
        }
    }

    module major_ticks(xrange, yrange) {
        for (x=xrange, y=yrange) {
            translate([x,y,0]) major_tick();
        }
    }

    module xlabel(x) {
        translate([x,yoffset,0])
            linear_extrude(height=thick, center=true)
            text(str(x), size=labelsize, halign="center");
    }

    module ylabel(y) {
        translate([xoffset,y,0])
            linear_extrude(height=thick, center=true)
            text(str(y), size=labelsize, valign="center");
    }

    for (x=[-major:-major:min.x]) xlabel(x);
    for (x=[major:major:max.x]) xlabel(x);
    for (y=[-major:-major:min.y]) ylabel(y);
    for (y=[major:major:max.y]) ylabel(y);

    minor_ticks(xrange=[-minor:-minor:min.x], yrange=[-minor:-minor:min.y]);
    minor_ticks(xrange=[0:minor:max.x], yrange=[-minor:-minor:min.y]);
    minor_ticks(xrange=[-minor:-minor:min.x], yrange=[0:minor:max.y]);
    minor_ticks(xrange=[0:minor:max.x], yrange=[0:minor:max.y]);

    major_ticks(xrange=[-major:-major:min.x], yrange=[-major:-major:min.y]);
    major_ticks(xrange=[0:major:max.x], yrange=[-major:-major:min.y]);
    major_ticks(xrange=[-major:-major:min.x], yrange=[0:major:max.y]);
    major_ticks(xrange=[0:major:max.x], yrange=[0:major:max.y]);
}

%grid2D(min=[-20,-20], max=[20,20]);
On 7/24/2022 5:00 AM, tony.pemberton.cowroast@gmail.com wrote: > > A first post so I’m probably not aware of protocol here! > You're fine. > I have used Openscad for the last 2.5 years and I find it great for > doing my models and otherthings. I use version 2021.1. both on W7 and > Debian11. > > So far, I have not needed to determine absolute sizes during Openscad > design stages as, by default, designs are 3D printed with metric > dimensions. I am aware that Openscad is actually dimensionless but I > would like to be able to determine sizes of designed objects, on > screen, before committing to print. > > I have searched the settings of Openscad to change the dimension scale > of the X,Y and Z lines and or introduce screen grid so that I can zoom > in or out to see how big an object is on screen (relatively). At > present the screen scale normally shows intervals of 1(cm). I would > like to be able to have an *optional grid* of 0.1(mm) (not just marks > on the X,Y,Z bars) when I zoom in to a very small part I am designing. > > Am I missing something in the Openscad settings? It would be nice to > be able to switch screen grid on or off with a function button too. > First... there are no units in OpenSCAD, except what you make up for yourself.  The screen scale is not in mm, or cm, or inches, or miles, or smoots.  It's in OpenSCAD units, and OpenSCAD units are as large as you want to pretend them to be.  Indeed, people often or even usually treat them as millimeters, because that's what slicers want, but OpenSCAD doesn't know nor care.  (When I model my house at one OpenSCAD unit per real-world inch, and then print it at one OpenSCAD unit per millimeter, how big is an OpenSCAD unit?) Second... no, there's no grid mechanism.  (What would a 3D grid look like?  Or maybe you'd lay a 2D grid on one of the axis planes.) However, there's nothing stopping you from drawing your own grid.  Use % so that it isn't included in your model. Here's a semi-fancy implementation.  Rotate and reposition as desired.  There's an argument that this should all be done in 2D, but rotating 2D off of the XY plane bothers me.  Note that the minor ticks are pretty small and can sometimes disappear on the display unless zoomed in.  You might want to turn off displaying the axes. module grid2D(min=[-100,-100], max=[100,100], minor=1, major=10) { minor_len = 0.3; minor_thick = 0.05; major_len = 0.6; major_thick = 0.2; thick = 0.1; labelsize = 2; yoffset = 1; xoffset = 1; close = 0.1; module minor_tick() { cube([minor_len, minor_thick, thick], center=true); cube([minor_thick, minor_len, thick], center=true); } module major_tick() { cube([major_len, major_thick, thick], center=true); cube([major_thick, major_len, thick], center=true); } module minor_ticks(xrange, yrange) { for (x=xrange, y=yrange) { if (abs(x%major) > close || abs(y%major) > close) { translate([x,y,0]) minor_tick(); } } } module major_ticks(xrange, yrange) { for (x=xrange, y=yrange) { translate([x,y,0]) major_tick(); } } module xlabel(x) { translate([x,yoffset,0]) linear_extrude(height=thick, center=true) text(str(x), size=labelsize, halign="center"); } module ylabel(y) { translate([xoffset,y,0]) linear_extrude(height=thick, center=true) text(str(y), size=labelsize, valign="center"); } for (x=[-major:-major:min.x]) xlabel(x); for (x=[major:major:max.x]) xlabel(x); for (y=[-major:-major:min.y]) ylabel(y); for (y=[major:major:max.y]) ylabel(y); minor_ticks(xrange=[-minor:-minor:min.x], yrange=[-minor:-minor:min.y]); minor_ticks(xrange=[0:minor:max.x], yrange=[-minor:-minor:min.y]); minor_ticks(xrange=[-minor:-minor:min.x], yrange=[0:minor:max.y]); minor_ticks(xrange=[0:minor:max.x], yrange=[0:minor:max.y]); major_ticks(xrange=[-major:-major:min.x], yrange=[-major:-major:min.y]); major_ticks(xrange=[0:major:max.x], yrange=[-major:-major:min.y]); major_ticks(xrange=[-major:-major:min.x], yrange=[0:major:max.y]); major_ticks(xrange=[0:major:max.x], yrange=[0:major:max.y]); } %grid2D(min=[-20,-20], max=[20,20]);
K
Ken
Mon, Jul 25, 2022 3:21 AM

Thanks for the grid module Jordan- that is going to come in very useful
for me at least.

On 2022-07-25 05:07, Jordan Brown wrote:

However, there's nothing stopping you from drawing your own grid. Use
% so that it isn't included in your model.

Here's a semi-fancy implementation.  Rotate and reposition as
desired.  There's an argument that this should all be done in 2D, but
rotating 2D off of the XY plane bothers me.  Note that the minor ticks
are pretty small and can sometimes disappear on the display unless
zoomed in.  You might want to turn off displaying the axes.

 module grid2D(min=[-100,-100], max=[100,100], minor=1, major=10) {
      minor_len = 0.3;
      minor_thick = 0.05;
      major_len = 0.6;
      major_thick = 0.2;
      thick = 0.1;
      labelsize = 2;
      yoffset = 1;
      xoffset = 1;
      close = 0.1;

      module minor_tick() {
          cube([minor_len, minor_thick, thick], center=true);
          cube([minor_thick, minor_len, thick], center=true);
      }

      module major_tick() {
          cube([major_len, major_thick, thick], center=true);
          cube([major_thick, major_len, thick], center=true);
      }

      module minor_ticks(xrange, yrange) {
          for (x=xrange, y=yrange) {
              if (abs(x%major) > close || abs(y%major) > close) {
                  translate([x,y,0]) minor_tick();
              }
          }
      }

      module major_ticks(xrange, yrange) {
          for (x=xrange, y=yrange) {
              translate([x,y,0]) major_tick();
          }
      }

      module xlabel(x) {
          translate([x,yoffset,0])
              linear_extrude(height=thick, center=true)
              text(str(x), size=labelsize, halign="center");
      }

      module ylabel(y) {
          translate([xoffset,y,0])
              linear_extrude(height=thick, center=true)
              text(str(y), size=labelsize, valign="center");
      }

      for (x=[-major:-major:min.x]) xlabel(x);
      for (x=[major:major:max.x]) xlabel(x);
      for (y=[-major:-major:min.y]) ylabel(y);
      for (y=[major:major:max.y]) ylabel(y);

      minor_ticks(xrange=[-minor:-minor:min.x], yrange=[-minor:-minor:min.y]);
      minor_ticks(xrange=[0:minor:max.x], yrange=[-minor:-minor:min.y]);
      minor_ticks(xrange=[-minor:-minor:min.x], yrange=[0:minor:max.y]);
      minor_ticks(xrange=[0:minor:max.x], yrange=[0:minor:max.y]);

      major_ticks(xrange=[-major:-major:min.x], yrange=[-major:-major:min.y]);
      major_ticks(xrange=[0:major:max.x], yrange=[-major:-major:min.y]);
      major_ticks(xrange=[-major:-major:min.x], yrange=[0:major:max.y]);
      major_ticks(xrange=[0:major:max.x], yrange=[0:major:max.y]);
 }

 %grid2D(min=[-20,-20], max=[20,20]);

OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

--
Cheers, Ken
bats059@gmail.com
https://vk7krj.com/running.html
https://sstv.vk7krj.com/all_bands.html

A baby is just an ego with a noise at one end and a smell at the other. Your job as a parent is to teach it to control all three.

Thanks for the grid module Jordan- that is going to come in very useful for me at least. On 2022-07-25 05:07, Jordan Brown wrote: > However, there's nothing stopping you from drawing your own grid. Use > % so that it isn't included in your model. > > Here's a semi-fancy implementation.  Rotate and reposition as > desired.  There's an argument that this should all be done in 2D, but > rotating 2D off of the XY plane bothers me.  Note that the minor ticks > are pretty small and can sometimes disappear on the display unless > zoomed in.  You might want to turn off displaying the axes. > > module grid2D(min=[-100,-100], max=[100,100], minor=1, major=10) { > minor_len = 0.3; > minor_thick = 0.05; > major_len = 0.6; > major_thick = 0.2; > thick = 0.1; > labelsize = 2; > yoffset = 1; > xoffset = 1; > close = 0.1; > > module minor_tick() { > cube([minor_len, minor_thick, thick], center=true); > cube([minor_thick, minor_len, thick], center=true); > } > > module major_tick() { > cube([major_len, major_thick, thick], center=true); > cube([major_thick, major_len, thick], center=true); > } > > module minor_ticks(xrange, yrange) { > for (x=xrange, y=yrange) { > if (abs(x%major) > close || abs(y%major) > close) { > translate([x,y,0]) minor_tick(); > } > } > } > > module major_ticks(xrange, yrange) { > for (x=xrange, y=yrange) { > translate([x,y,0]) major_tick(); > } > } > > module xlabel(x) { > translate([x,yoffset,0]) > linear_extrude(height=thick, center=true) > text(str(x), size=labelsize, halign="center"); > } > > module ylabel(y) { > translate([xoffset,y,0]) > linear_extrude(height=thick, center=true) > text(str(y), size=labelsize, valign="center"); > } > > for (x=[-major:-major:min.x]) xlabel(x); > for (x=[major:major:max.x]) xlabel(x); > for (y=[-major:-major:min.y]) ylabel(y); > for (y=[major:major:max.y]) ylabel(y); > > minor_ticks(xrange=[-minor:-minor:min.x], yrange=[-minor:-minor:min.y]); > minor_ticks(xrange=[0:minor:max.x], yrange=[-minor:-minor:min.y]); > minor_ticks(xrange=[-minor:-minor:min.x], yrange=[0:minor:max.y]); > minor_ticks(xrange=[0:minor:max.x], yrange=[0:minor:max.y]); > > major_ticks(xrange=[-major:-major:min.x], yrange=[-major:-major:min.y]); > major_ticks(xrange=[0:major:max.x], yrange=[-major:-major:min.y]); > major_ticks(xrange=[-major:-major:min.x], yrange=[0:major:max.y]); > major_ticks(xrange=[0:major:max.x], yrange=[0:major:max.y]); > } > > %grid2D(min=[-20,-20], max=[20,20]); > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org -- Cheers, Ken bats059@gmail.com https://vk7krj.com/running.html https://sstv.vk7krj.com/all_bands.html ---------------------------------------- A baby is just an ego with a noise at one end and a smell at the other. Your job as a parent is to teach it to control all three.