Getting dimensions of imported shape?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting dimensions of imported shape?

marhar
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.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

JordanBrown
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



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

fred_dot_u
In reply to this post by marhar
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

atnbueno
In reply to this post by marhar
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:


Regards,
Antonio B.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

Jamie Bainbridge
In reply to this post by marhar
On 23 July 2018 at 04:39, Mark Harrison <[hidden email]> 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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

ClintGoss
>  … 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  ... index of all our web sites



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Clint Goss <clint@goss.com>
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

Alexander Pruss
In reply to this post by marhar
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

lar3ry
This post was updated on .
In reply to this post by Jamie Bainbridge
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
NE Quadrant: translate([ 60.0 , -43.0 , 16.0 ])
NW Quadrant: rotate([0,0,90]) translate([ 60.0 , -43.0 , 16.0 ])
SW Quadrant: rotate([0,0,180]) translate([ 60.0 , -43.0 , 16.0 ])
NE Quadrant: rotate([0,0,-90]) translate([ 60.0 , -43.0 , 16.0 ])
Center: translate([ 45.0 , -53.0 , 9.5 ])

After running this, you simply copy one of the 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

Small correction. Change the second "NE Quadrant:" line to "SE Quadrant:" in the python file.





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

lar3ry
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

cacb
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.
>
> https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin

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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

lar3ry
If you don't have numpy, could you try installing that. I have it in my
Python library, but don't remember if it was already there when I started.

Could it be that there are more than one stl modules?

I took a look at the link you posted, and what I find most interesting about
it is the number of problems polyfix pointed out. It surprised me, because I
could slice the model (in Slic3r) just fine.

I haven't looked at AngelCAD at all. Do you have pre-built binaries
available anywhere?

Larry


cacb wrote

> 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
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

cacb
On 2019-06-11 15:58, lar3ry wrote:
> If you don't have numpy, could you try installing that. I have it in my
> Python library, but don't remember if it was already there when I
> started.

I will try again on a different computer and report back later.

> I took a look at the link you posted, and what I find most interesting
> about
> it is the number of problems polyfix pointed out. It surprised me,
> because I
> could slice the model (in Slic3r) just fine.

Slicers are generally much more forgiving than cad programs, so many STL
files with issues can be printed without problems. Also important is the
fact that reading an STL file into a CAD program is a matter of
interpretation, so different software will report different issues.

> I haven't looked at AngelCAD at all. Do you have pre-built binaries
> available anywhere?

Yes, you can get it at https://github.com/arnholm/angelcad/releases 
(Windows/Ubuntu)

Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

cacb
On 11.06.2019 17:31, [hidden email] wrote:
> On 2019-06-11 15:58, lar3ry wrote:
>> If you don't have numpy, could you try installing that. I have it in my
>> Python library, but don't remember if it was already there when I
>> started.
>
> I will try again on a different computer and report back later.

I had another try, this time on a Kubuntu 18.04 computer with Python3.7

First I got the same error as before and installed (using pip3) the
'stl' package, same problem. Then I tried to install a 'mesh' package,
still no success. Next I tried your suggestion numpy, but this was no
success either. After searching with DuckDuckGo for "python package stl
mesh", I noticed there is something called 'numpy-stl'. So I did

pip3 install numpy-stl

Then it worked fine, I was able to run your .scad code successfully. So
I think you might want to add the requirement to install the python
package numpy-stl in your github README.md

Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dimensions of imported shape?

lar3ry
Done. Thanks Carsten!




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org