MXS Select Objects by volume

Hi,
Is there anyways that I can select the objects covered by any object’s bounds? In this case from the image, i want to select the spheres which comes with in the object bounds. I know we can get the bounds from obj.max-obj.min, but dint know how to apply it to select the objects. Please help.

If you only need to select based on bounding box, you can do it simply:


fn objects_in_BB target objarr =
(
	result_arr = #()
	for obj in objarr do 
		if obj.pos.x > target.min.x AND obj.pos.y > target.min.y AND obj.pos.z > target.min.z AND obj.pos.x < target.max.x and obj.pos.y < target.max.y AND obj.pos.z < target.max.z then
			append result_arr obj
	result_arr
)

inBB_arr = (objects_in_BB $Box001 (selection as array))
clearSelection()
select inBB_arr


But this is quick and dirty, it won’t work the way you expect if you rotate the “volume” box in anything other than 90 degree increments.

Thanks Zhalktis for the swift reply but unfortunately this is not working. Tried collecting objects in to objarr also. No luck even then. :frowning:

This may not be a ton of help, so forgive me. I only had a few spare minutes to put together a quick sample since I’m leaving to catch a flight back home from the holidays. :wink: The example is also for Maya in Python… :rolleyes: But the concept should be the same! Hopefully you can follow it. I tried to comment is well.

http://technicallyitsart.wordpress.com/2013/12/28/maya-python-select-by-volume/

The main idea is that you’re going to check the position (or volume) of all the other shapes in the scene against the bounding box of your volume object. The math checks to do this are detailed in my BoundingBox class and can be found well-documented all over the internet in various forms. You’re basically just checking each component of position (x,y,z) to see if they are within each component of the volume (x,z,y). Good luck! If I have more time and you are still stuck, I can look into a maxscript version.

Hey Thanks Mouthlessbobcat. I was like a lil problem with calling an array but the code of Zhalktis was working fine with that modification. Thanks a bunch for your concern shown :slight_smile:

And if you want this in MaxPlus… there you go! http://www.youcandoitvfx.com/?p=653

Thanks to Eric for his Maya code, just had to do some minor changes :slight_smile: Will improve it a bit afterwards to use Box3 values by default instead of flattening everything into ints.