Sometimes I import an external STL file to make some modifications...
resize a hole, etc. To do so, I need to get the dimensions of the
imported object.
Scale markers are useful for this, but usually takes a couple of tries
to get the correct values.
Is there any way in OpenSCAD to retrieve dimensions of objects? Even
dumping out bounding boxes to the console would be great.
Alternatively, any other programs that can print useful information
about an STL file, such as bounding boxes? I realize that STL files
don't have dimension information; just the values are fine.
On 7/22/2018 11:39 AM, Mark Harrison wrote:
Alternatively, any other programs that can print useful information
about an STL file, such as bounding boxes? I realize that STL files
don't have dimension information; just the values are fine.
Text STL files are in a pretty simple format and can be relatively
easily examined in any language.
Here's an awk program that dumps the bounding box for a text STL file:
BEGIN {
m = 1000000; // Make larger if your model is really large
maxx = -m;
minx = m;
maxy = -m;
miny = m;
maxz = -m;
minz = m;
}
$1 == "vertex" {
maxx = ($2>maxx ? $2 : maxx);
minx = ($2<minx ? $2 : minx);
maxy = ($3>maxy ? $3 : maxy);
miny = ($3<miny ? $3 : miny);
maxz = ($4>maxz ? $4 : maxz);
minz = ($4<minz ? $4 : minz);
}
END {
print minx,miny,minz;
print maxx,maxy,maxz;
}
If what you have is a binary STL file then it's a little harder. How
hard depends on your computer; if you're on a little-endian system (like
Intel-derived systems) then it's not bad, probably a couple of dozen
lines of C.
There's a simple description of the file format at
https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL
I've found it useful to use Meshmixer, a free program, to import STL files.
The Analysis feature has a dimension option which will display a bounding
box for the entire model based on the current orientation. If a model is
irregular, you can use Edit/Transform to rotate it and check the bounding
box again.
Also useful is the Edit/Plane Cut, which allows you to slice the model in
any location, multiple times, to get a different set of bounding boxes,
enabling you to measure accurately, say, a cylinder in the center of the
model, or to better determine a specific dimension.
Obviously, one would not save the sliced model as it would overwrite your
original.
Another great feature is Undo (Control-Z) which lets you perform and measure
a slice, then return to the original model (Control-Z multiple times) and
make other actions.
--
Sent from: http://forum.openscad.org/
Hi.
Alternatively, any other programs that can print useful information
about an STL file, such as bounding boxes? I realize that STL files
don't have dimension information; just the values are fine.
There is a really old (‘96!) command line tool that you may find useful:
https://github.com/admesh/admesh
Regards,
Antonio B.
On 23 July 2018 at 04:39, Mark Harrison marhar@gmail.com wrote:
Alternatively, any other programs that can print useful information
about an STL file, such as bounding boxes? I realize that STL files
don't have dimension information; just the values are fine.
I wrote a Python script which can do this:
https://www.reddit.com/r/3Dprinting/comments/7ehlfc/python_script_to_find_stl_dimensions/
Jamie
… external STL file …
… get the dimensions of the imported object.
I use 3D-Tool. They provide a free STL viewer that is very handy for
measuring between points, vertices, lines, planes, etc.
-- Clint Goss
Goss.com http://www.goss.com/ ... index of all our web sites
Rather than using OpenSCAD's import function, I convert stl files directly to
OpenSCAD polyhedra using my stl2scad.py script:
https://github.com/arpruss/miscellaneous-scad/tree/master/scripts
The latest version of the script puts all the points in an stlObject1_points
list, so you can calculate bounding boxes yourself with:
minima = [for(i=[0:2]) min([for(p=stlObject1_points) p[i]])];
maxima = [for(i=[0:2]) max([for(p=stlObject1_points) p[i]])];
If you just want to see the bounds without converting to a polyhedron, the
bounds.py script will do that.
--
Sent from: http://forum.openscad.org/
I know this is an old thread, but this may help someone.
I grabbed your excellent python script, stldim.py, and added a little bit at
the end to make it more useful to OpenSCAD users. It's fairly simple, and
solves a problem that I have had trouble with many times; moving an imported
STL file to the origin.
Here is the output for a test.stl, a simple cube not near the origin in any
axis.
L:\3D\Test>stldim.py test.stl
File: test.stl
X size: 30.0
Y size: 20.0
Z size: 13.0
X position: -60.0
Y position: 43.0
Z position: -16.0
-16.0 -3.0
Quadrant: translate([ 60.0 , -43.0 , 16.0 ])
Center: translate([ 45.0 , -53.0 , 9.5 ])
After running this, you simply copy one of the two translate statements and
paste it in front of the imported stl.
"xx Quadrant:" puts the object in the xx quadrant (NE, NW, SW, SE)
"Center:" centres the object in all three dimensions.
stldim.py http://forum.openscad.org/file/t2121/stldim.py
--
Sent from: http://forum.openscad.org/
I have done some more work with Jamie Bainbridge's stldim.py script, and
have come up with an easier way to get the translate() info into OpenSCAD,
in order to move an STL file to be adjacent to or centered on the X,Y,Z
origin.
Running the script in a directory containing an STL file will generate an
OpenSCAD file that may be used as a library that you can include to move the
STL file.
I put it on gihub (I think I got it right), and would appreciate comments or
suggestion.
https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin
--
Sent from: http://forum.openscad.org/
On 2019-06-11 06:45, lar3ry wrote:
I have done some more work with Jamie Bainbridge's stldim.py script,
and
have come up with an easier way to get the translate() info into
OpenSCAD,
in order to move an STL file to be adjacent to or centered on the X,Y,Z
origin.
Running the script in a directory containing an STL file will generate
an
OpenSCAD file that may be used as a library that you can include to
move the
STL file.
I put it on gihub (I think I got it right), and would appreciate
comments or
suggestion.
I tried your python script, but got an error:
ModuleNotFoundError: No module named 'stl'
Then I tried: 'pip3 install stl' which seemed to work. However, when I
ran the script again, I got
python stldim.py
Traceback (most recent call last):
File "stldim.py", line 3, in <module>
from stl import mesh
ImportError: cannot import name 'mesh' from 'stl'
(C:\Python\Python37\lib\site-packages\stl_init_.py)
So apparently there are some dependencies that need clarification.
Here is an alternative approach to the same problem (based on your STL)
using bounding boxes in AngelCAD
https://gist.github.com/arnholm/c06966e575173f9eaaafbac1d30e0c76
Carsten Arnholm