ScriptSpot

Forum topic · General Scripting

Bounding box of selected verts in Edit Mesh

By WillyWonka · 2008-02-08

Description

Is there any easy way to read the .max and .min points of a selection made in Edit Mesh?  I haven't been able to find any and my attempts at looping through the verts and recording the smallest and largest have been buggy.

 

Comments (2)

Maybe a different approach...

recubo · 2011-10-18

Maybe there is another way to do it...

You could create a spline object to connect those vertex and then get the bounding box of that spline.

denisT · 2008-02-23

there is no easy way to get bbox for selected verts. you have to go through all selected verts and look for min/max
Like this:

fn vertsBBox thenode verts: =
(
local themesh = thenode.mesh
if verts == unsupplied do verts = themesh.selectedVerts as bitarray

local minx = miny = minz = 1e9
local maxx = maxy = maxz = -1e9
for v in verts do
(
-- vert position in local coords
p = getVert themesh v
-- to get position in world coords
-- p *= thenode.transform
minx = amin minx p.x
miny = amin miny p.y
minz = amin minz p.z
maxx = amax maxx p.x
maxy = amax maxy p.y
maxz = amax maxz p.z
)
#([minx,miny,minz],[maxx,maxy,maxz])
)

if you want to make it faster don't use amin/amax
use if ... then ... else ...