[Closed] Finding out if an object is inside another
Yep, me again…
Is there a script out there that allows you to select all the objects that are outside another object?
for example…i have a cube with a bunch of planes inside and surrounding it. I would like to select all the planes outside the cube, but keep the ones inside. There are other objects in the scene, but i would only like to select the planes.
I can get just the planes by using the “matchpattern” call, but the only way i can think of seeing if they are inside the box is comparing the verts, but this just seems tedious. Any thoughts?
Thanks.
targ_obj = $sphere01
obj_outside = (for i in selection where (intersects targ_obj i) == false collect i.name)
Thank you…saved me a bunch of time. Is there a place in the maxscript reference that talks more about the “collect” call, i can’t seem to find it, and it seems pretty powerful.
Collect is part of the for loop construction,and is used only with arrays. You are right, it is a powerful thing and will save you many commands and lines of code. There is information on it under the following Help topics:
Collections
Collection Types – In particular, “ObjectSet Values”
For Loop
Array Values
The topic “ObjectSet Values” is particularly useful because it tells you all the automatic collections that 3ds max makes, which you can use to look through the items in your scene.
Since the information in the Help is a bit spread out, I will share with you a brief lesson on the collect command that I recently wrote up for my students.
In MAXScript, a collection is a bunch of objects that fit into one category. This is a loose definition that encompasses:
[ul]
[li]Arrays, which are collections you make yourself.[/li][li]Object categories, which 3ds max makes automatically. For example, all the lights in your scene are automatically placed in a collection of lights.[/li][/ul]Some of the automatic collections available to you are:
[ul]
[li]objects – all the objects in the scene, including lights, cameras, helpers, etc.[/li][li]geometry – geometry objects only[/li][li]lights[/li][li]cameras[/li][li]helpers[/li][li]shapes[/li][li]selection – the objects currently selected in the scene[/li][li]selectionSets – all the selection sets in the scene[/li][li]meditMaterials – all the materials in the Material Editor[/li][/ul]The automatic collections make certain operations easier. For example, if you want to do something to all the geometry (3D objects) in a scene, you can simply perform this operation on all the objects in the geometry collection. You would do this in a for loop using this construction:
for i in geometry do …
In the loop above, the variable i would contain the geometry object. You can then perform some kind of operation on it, for example changing the Z position of each object to 100.
for i in geometry do i.pos.z = 100
Each automatic collection can also be treated like an array. Imagine that there is an array called geometry that contains all the 3D objects. You could do the same thing as in the code above by using it as an array:
for i = 1 to geometry.count do geometry[i].pos.z = 100
For/Collect
In a For loop, if you are collecting up items from a collection to put in an array, instead of using “do” at the end of the line, you can use “collect”. Here, you make the results of the For loop equal to an array. For example:
objArray = for obj in geometry collect obj
Note that the line starts with the array name, then an equals sign. This is ALWAYS the construction when using collect. There has to be an array name at the left for the items to “collect” into.
The line above puts all the geometry objects in the array objArray. This might seem like a silly thing to do, since they’re already in the geometry array. So here is a more useful usage:
objArray = for obj in geometry where obj.pos.x < 100 collect obj
This would take all the geometry objects with an X position less than 100 and put them in the array. You can get pretty fancy with this collection business. Let’s look at another usage. This one uses the property .baseobject, which each geometry object has. The .baseobject property tells you the type of object it is.
objArray = for obj in geometry where obj.baseobject == sphere collect obj
This collects spheres only into the array.