[Closed] Maxscript help with selections
I trying to figure out a way that I can have a circle that when objects are placed within its radius it will select them. or more that when you click on the cirlce to select it it then selects the objects located inside its radius. Any ideas?
Here is a simple example:
fn selectInsideCircle =
(
if selection.count == 1 and classof selection[1] == Circle do
(
local theCircle = selection[1]
local theTM = inverse theCircle.transform
local theArray = for o in objects where o != theCircle and not o.isHiddenInVpt and not o.isFrozen collect
(
local thePos = o.pos * theTM
if sqrt (thePos.x^2+thePos.y^2) <= theCircle.radius then
o
else
dontcollect
)
selectMore theArray
)
)
callbacks.removeScripts id:#selectByCircle
callbacks.addScript #selectionSetChanged "selectInsideCircle()" id:#selectByCircle
Evaluate to engage.
Select any Circle shape and all visible unfrozen objects that are inside the spatial cylinder defined by the circle (in other words, not necessarily in the same plane but inside the radius in the local XY plane of the Circle regardless of their Z) will be selected, too.
To disable, call the line
callbacks.removeScripts id:#selectByCircle
It could be improved by making a MacroScript to register and unregister the callback (the function should be defined as global).
Thats awesome. Thanks Bobo.
How would I edit this so it selects everything in the z and x or in the x and y but not all directions or maybe limit one direction more that the other 2?
My idea is to use this to rig a rubix cube. So that you can move the circle with out it affecting any of the cubes. When you get the circle over the group of 9 boxes you want to rotate you run this script through a button in an attribute holder and you can rotate that group of boxes. Then click the button again to turn it off move the circle and do it again. Not sure if this approach is going to work or not though.
I was initially trying to send out a ray from the circles center. Then use intersectRayScene to collect all the objects the ray hits and add them to an array. Then select that array along with the circle.
I guess my question now is will either of these work when it comes time to animate?
Just curious have you seen the video about rigging a rubik’s cube over at the AREA?
-Eric
Awesome thanks, I guess I am not that original then. He doesn’t post his scripts though but it seems like something bobo just posted.