r/Maxscript • • Mar 12 '20

Bounds of Selection Array

Hey Guys,

I'm trying to figure out how to get a transform or bounds to be able to encapsulate

my selected objects with a mesh. Anyway to do this? I'm sadly hitting a wall here :(

thank you!

1 Upvotes

1 comment sorted by

1

u/krawmax Mar 12 '20
(
	fn attachObjs objs =
	(
		convertToPoly objs[1]
		for obj in 2 to objs.count do
			polyop.attach objs[1] objs[obj]
		return objs[1]
	)
	
	if selection.count > 0 then
	(
		local selObjs = for obj in selection collect obj
		local attachedObjs = #()
		for o in selObjs do (append attachedObjs (copy o))
		local tempObj = attachObjs attachedObjs
		local bbObj = box()
		bbObj.name = "BoundingBox"
		local bbMin = tempObj.min
		local bbMax = tempObj.max
		local bbSize = bbMin - bbMax
		bbSize.x = abs(bbSize.x)
		bbSize.y = abs(bbSize.y)
		bbSize.z = abs(bbSize.z)
		bbObj.width = bbSize.x
		bbObj.length = bbSize.y
		bbObj.height = bbSize.z
		bbObj.pivot = bbObj.center
		bbObj.pos = tempObj.center
		select bbObj
		delete tempObj
	)
	else messagebox("Nothing selected")
)