Notifications
Clear all

[Closed] Selection Position Matrix

I was wondering if there is a way to get a ‘selections’ position matrix…not each individual objects.

I’m basically merging a number of objects in with code…

and i’d like to move them as a selection to a new location while keeping their current relative position from each other. If that makes sense.

It seems you can’t access the selection.pos matrix. The only other way i thought of achieving what i need would be some vector math.

Anyone have any thoughts?

12 Replies
 dest = [0,0,0] 
CurPos = selection.center
SelectMove = Dest - CurPos
s = selection as array
for o in s do 
(
o.pos += selectMove
)

That worked perfectly…thanks for the fast reply.

Selection sets don’t actually have a position.

What’s a little odd is that Max’s “centering” of the transform gizmo isn’t actually the “center” location. So if it’s critical that your selection set’s transform gizmo ends up in a certain point that won’t work. What you’d probably need to do in such a situation is group the objects. That will have a position. Move that. And then ungroup.

I had thought of doing something like that, but is there any possible unexpected results that could result from adding a group node and then un grouping a list of objects? I haven’t worked with groups much in max, only maya.

Theoretically if you select objects in an open group it would break their grouping assignment. I suppose you would want to store each object’s original grouping/parenting status before the group is made.

What if…

i just went through all the nodes,

check to see if and was in an open group, and store all the heads of the open groups.

then closed those groups

   then put the entire selection into groupA    

   moved groupA

   ungrouped groupA

and then rewent though the original groups and openned the ones that were open

…could any unexpected results come from that?

Thanks again for the replies, like i said i haven’t worked much with groups.

Should work although I can think of a scenario based on scenes I have where this would still break.

You select an object that is part of an open group that is inside of another open group. Once it closes the group it wouldn’t know whether the parent group should be closed as well. It would take a human decision to decide at what level you want groups to be automatically closed etc…

All of this however is pure speculation. imo the location of the transform gizmo of an arbitrary selection is so variable I would prefer to use the “.center” value anyway just for mathematical consistancy. The location of the transform gizmo is also variable depending on UI selections “individual, center… etc”

Ok, i’m doing some work with the selection center, and i came across this weird result.

Ok make a group of boxes and store their selection.center matrix as A

then make a new object and set its .pos matrix to the variable A… they don’t line up, at least on my computer, and my bosses computer.

We are working on Max 7.

is anyone getting similar results? any reason why they don’t line up?

1 Reply
(@bobo)
Joined: 12 months ago

Posts: 0

Code?
You don’t expect us to know what you have written, right?

Your right, without an example, hard to see…ok this is quick and dirty because i’m at work…but should illustrate my point


       (
       	A = box()  -- create 3 boxes
       	B = box()
       	C = box()
       	
       	-- set the 3 boxes positioned apart, and scale them differently so they are not uniform
       	
       	A.pos = [-204.62,-233.351,425.624] ; A.scale = [3.90731,3.90731,3.90731] ; A.name ="Box_in_Selection_01"
       	B.pos = [-293.596,212.092,210.862] ; B.scale = [4.64474,4.64474,4.64474] ; B.name ="Box_in_Selection_02"
       	C.pos = [215.864,-193.491,159.17]  ; C.scale = [2.72215,2.72215,2.72215] ; C.name = "Box_in_Selection_03"
       	
       	select $Box_in_Selection*							 -- select the newly created boxes
       	
       	Box_Selection_Matrix = selection.center 			 -- stores where the supposed center of the selection is
       	
       	
       	D = box() 	 -- created to compare center location
       	
       	
       	
       	D.pos = Box_Selection_Matrix ; D.name = "Offset_Box"   -- set the new box's position to be equal to the selection center position
       	
       	
       	
       	-- to show where the selection center matrix is located
       	select $Box_in_Selection* 
       	toolMode.selectionCenter() -- so that the selection mode is set to selection.center
       	
       	
       	
       
       
       )
       
   I'm pasting directly from max, so its going to be a little messed up tabbing wise...sorry.
  
  Anyways,  on my computer here....the newly created box does not line up with the selection gizmo..when, i believe, it should...unless i'm doing something wrong.  again working on max 7.
Page 1 / 2