Is there a way to get the dimensions of an stl into a variable after it has
been imported?
No.
From: Trevor Orr via Discuss [mailto:discuss@lists.openscad.org]
Sent: Monday, November 11, 2024 10:31 PM
To: discuss@lists.openscad.org
Cc: Trevor Orr
Subject: [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable after it has been imported?
PrusaSlice, though, will give you the dimensions that you can enter into
OpenSCAD manually.
On Mon, Nov 11, 2024 at 7:06 AM Michael Marx (spintel) via Discuss <
discuss@lists.openscad.org> wrote:
No.
From: Trevor Orr via Discuss [mailto:discuss@lists.openscad.org]
Sent: Monday, November 11, 2024 10:31 PM
To: discuss@lists.openscad.org
Cc: Trevor Orr
Subject: [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable after it
has been imported?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
There’s a two step manual process.
With the development release of OpenSCAD there is an option under preferences | advanced to display the bounding box under Render Summary. If you do a full render of just an import of the .stl file, the console will display the bounding box. You can then copy that into the real .scad file.
Here’s a snipped to import and center a .stl item. The second and third lines of the item vector are the min and size info from the bounding box.
item = [
"item.stl",
[-30,-30,0],
[60,60,85]
];
module model(item, size)
{
scale(size/max(item.z))
translate(-0.5 * item.z - item.y)
import(item.x);
}
model(item, 100);
Mark
On Nov 11, 2024, at 9:21 AM, Leonard Martin Struttmann via Discuss discuss@lists.openscad.org wrote:
PrusaSlice, though, will give you the dimensions that you can enter into OpenSCAD manually.
On Mon, Nov 11, 2024 at 7:06 AM Michael Marx (spintel) via Discuss <discuss@lists.openscad.org mailto:discuss@lists.openscad.org> wrote:
No.
From: Trevor Orr via Discuss [mailto:discuss@lists.openscad.org mailto:discuss@lists.openscad.org]
Sent: Monday, November 11, 2024 10:31 PM
To: discuss@lists.openscad.org mailto:discuss@lists.openscad.org
Cc: Trevor Orr
Subject: [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable after it has been imported?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
A long winded method, without needing manually copying from the
console,would be to parse the stl file with an external program, and
write the max/min values of xyz vertices, to a text file, if you only
want the bounding box, e.g. file named dim.txt
xmax=10;
xmin=0;
ymax=22;
ymin=-7;
zmax=17;
zmin=3;
then in openscad
include<C:/Users/ray/Documents/dim.txt>
echo(xmax,xmin,zmax);
When parsing, you could also calculate cog, volume, whatever else you
may need.
On 11/11/2024 15:10, Mark Erbaugh via Discuss wrote:
There’s a two step manual process.
With the development release of OpenSCAD there is an option under
preferences | advanced to display the bounding box under Render
Summary. If you do a full render of just an import of the .stl file,
the console will display the bounding box. You can then copy that into
the real .scad file.
Here’s a snipped to import and center a .stl item. The second and
third lines of the item vector are the min and size info from the
bounding box.
item = [
"item.stl",
[-30,-30,0],
[60,60,85]
];
module model(item, size)
{
scale(size/max(item.z))
translate(-0.5 * item.z - item.y)
import(item.x);
}
model(item, 100);
Mark
On Nov 11, 2024, at 9:21 AM, Leonard Martin Struttmann via Discuss
discuss@lists.openscad.org wrote:
PrusaSlice, though, will give you the dimensions that you can enter
into OpenSCAD manually.
On Mon, Nov 11, 2024 at 7:06 AM Michael Marx (spintel) via Discuss
discuss@lists.openscad.org wrote:
No.
------------------------------------------------------------------------
*From:*Trevor Orr via Discuss [mailto:discuss@lists.openscad.org]
*Sent:* Monday, November 11, 2024 10:31 PM
*To:* discuss@lists.openscad.org
*Cc:* Trevor Orr
*Subject:* [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable
after it has been imported?
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
That is kind of what I am doing now, was hoping to automate it.
On Monday, November 11, 2024 at 07:31:36 AM PST, Raymond West via Discuss discuss@lists.openscad.org wrote:
A long winded method, without needing manually copying from the console,would be to parse the stl file with an external program, and write the max/min values of xyz vertices, to a text file, if you only want the bounding box, e.g. file named dim.txt
xmax=10;
xmin=0;
ymax=22;
ymin=-7;
zmax=17;
zmin=3;
then in openscad
include<C:/Users/ray/Documents/dim.txt>
echo(xmax,xmin,zmax);
When parsing, you could also calculate cog, volume, whatever else you may need.
On 11/11/2024 15:10, Mark Erbaugh via Discuss wrote:
There’s a two step manual process.
With the development release of OpenSCAD there is an option under preferences | advanced to display the bounding box under Render Summary. If you do a full render of just an import of the .stl file, the console will display the bounding box. You can then copy that into the real .scad file.
Here’s a snipped to import and center a .stl item. The second and third lines of the item vector are the min and size info from the bounding box.
item = [ "item.stl", [-30,-30,0], [60,60,85] ];
module model(item, size) { scale(size/max(item.z)) translate(-0.5 * item.z - item.y) import(item.x); }
model(item, 100);
Mark
On Nov 11, 2024, at 9:21 AM, Leonard Martin Struttmann via Discuss discuss@lists.openscad.org wrote:
PrusaSlice, though, will give you the dimensions that you can enter into OpenSCAD manually.
On Mon, Nov 11, 2024 at 7:06 AM Michael Marx (spintel) via Discuss discuss@lists.openscad.org wrote:
No.
From: Trevor Orr via Discuss [mailto:discuss@lists.openscad.org]
Sent: Monday, November 11, 2024 10:31 PM
To: discuss@lists.openscad.org
Cc: Trevor Orr
Subject: [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable after it has been imported?
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Maybe this one ?
from openscad import *
def center_object(obj):
pts=obj.mesh()[0]
shift=[]
for c in range(3):
min=pts[0][c]
max=pts[0][c]
for pt in pts:
if pt[c] < min:
min=pt[c]
if pt[c] > max:
max=pt[c]
shift.append((min+max)/2)
return obj - shift
obj=osimport("center.stl")
centered = center_object(obj)
centered.show()
On Mon, Nov 11, 2024 at 5:00 PM Trevor Orr via Discuss <
discuss@lists.openscad.org> wrote:
That is kind of what I am doing now, was hoping to automate it.
On Monday, November 11, 2024 at 07:31:36 AM PST, Raymond West via Discuss <
discuss@lists.openscad.org> wrote:
A long winded method, without needing manually copying from the
console,would be to parse the stl file with an external program, and write
the max/min values of xyz vertices, to a text file, if you only want the
bounding box, e.g. file named dim.txt
xmax=10;
xmin=0;
ymax=22;
ymin=-7;
zmax=17;
zmin=3;
then in openscad
include<C:/Users/ray/Documents/dim.txt>
echo(xmax,xmin,zmax);
When parsing, you could also calculate cog, volume, whatever else you may
need.
On 11/11/2024 15:10, Mark Erbaugh via Discuss wrote:
There’s a two step manual process.
With the development release of OpenSCAD there is an option under
preferences | advanced to display the bounding box under Render Summary. If
you do a full render of just an import of the .stl file, the console will
display the bounding box. You can then copy that into the real .scad file.
Here’s a snipped to import and center a .stl item. The second and third
lines of the item vector are the min and size info from the bounding box.
item = [
"item.stl",
[-30,-30,0],
[60,60,85]
];
module model(item, size)
{
scale(size/max(item.z))
translate(-0.5 * item.z - item.y)
import(item.x);
}
model(item, 100);
Mark
On Nov 11, 2024, at 9:21 AM, Leonard Martin Struttmann via Discuss
discuss@lists.openscad.org discuss@lists.openscad.org wrote:
PrusaSlice, though, will give you the dimensions that you can enter into
OpenSCAD manually.
On Mon, Nov 11, 2024 at 7:06 AM Michael Marx (spintel) via Discuss <
discuss@lists.openscad.org> wrote:
No.
From: Trevor Orr via Discuss [mailto:discuss@lists.openscad.org]
Sent: Monday, November 11, 2024 10:31 PM
To: discuss@lists.openscad.org
Cc: Trevor Orr
Subject: [OpenSCAD] Dimensions of imported stl
Is there a way to get the dimensions of an stl into a variable after it
has been imported?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org