Notifications
Clear all

[Closed] center group ungroup 2 axis

Ive been messaging with user: Cyfer about my problem but we agreed that posting it here might be a better idea for other people to give some input or learn something.

Im trying to get a script done where I have a bunch of objects. Make sure they are all UNGROUPED first (continue this ungroup command until everything is ungrouped), then group the objects together, center them ONLY on X and Y axis and then UNGROUP everything again.

Please dont mind the newbie script im using (actionman).

Old script I made:

on centergroup pressed do
 	 (
 		 actionMan.executeAction 0 "40021"  -- Selection: Select All
 		 if $dummy.group then
 		 actionMan.executeAction 0 "40141"  -- Groups: Ungroup
 		 else
 		 actionMan.executeAction 0 "40140" -- group selected
 		 $group01.pos = [0,0,0] 
 		 actionMan.executeAction 0 "40141"  -- Groups: Ungroup	
 		 
 		 
 	 )

After consulting Cyfer I was told to use the following line:


 for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
 Group objects

Thus code became:

	on centergroup pressed do
 	(
 		actionMan.executeAction 0 "40021"  -- Selection: Select All
 		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
 		Group objects
 		$group01.pos = [0,0,0] 
 		actionMan.executeAction 0 "40141"  -- Groups: Ungroup	
 		
 		
 	)

Now a weird problem appears:

When I click the button for the script this is what I get. Everything seems selected, as in the righttop it says 6 objects selected which I think refers to the 6 blocks in the viewport, but the viewport stats show 0 entity selected.

When I click the [select tool] and click on one of the blocks they still seem to appear in a group while my script clearly has an ungroup as final command.

When I use the script and I leave everything ungrouped, I get the following after clicking the button:

20 entities selected… errr what?

About the AXIS question:

For example: If I build a car that consist of a numerous amount of objects I want to GROUP the objects, and put the middle of the car on the 0,0 point of the X,Y axis. I dont want the car go through the floor (Z-axis). So I want only to be able to control the X and Y axis when using the center command. Is this possible?

t.i.a.

8 Replies

screwed around a little, saw that the actionman UNGROUP line didnt work at all.

deleted it and copied the second line from the code and added a clearSelection function which cleaned up the entity mess I guess.

	on centergroup pressed do
 	(
 		actionMan.executeAction 0 "40021"  -- Selection: Select All
 		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
 		Group objects 
 		$group01.pos = [0,0,0] 
 		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
 		clearSelection()
 		)
 		
 )

Works like a charm, but all I need now is the group ONLY centering on X and Y and not Z

I read that the X, Y and Z AXIS in maxscript are predefined by respectively [1.0.0], [0.1.0] and [0.0.1]. So what I think ( probably not correct) is find a way to move the objects along the [1.0.0] and [0.1.0] and that will solve my problem. I think… any ideas? In the meantime ill do my best to search more info about this.

center the object pivots in x and y but leave the Z as it is ?
thats what i understand from your post

i thought you were looking for grouping the objects again at the end !
anyways , see if this is what you need


fn RecurseGroupMember = 
(
	for o in objects do (
	o.pivot = [0,0,o.pivot.z]
	if (IsGroupMember o == true)  then
	(
		ExplodeGroup (GetNodeByname(o.parent.name) )
		RecurseGroupMember ()
	)		
								)
)

RecurseGroupMember()

Yup that is what I meant

So first make sure everything is ungrouped
Then group everything together
Move center on X axis
Move center on Y axis
Ungroup

I tried the script but I think there might a mistake. It has 2 x the recurse endtags
So it didnt work. After I removed the last endtag it opens the panel but
then gives the following error: Unknown property: “pivot” in undefined.

I tried combining with the code I already had, under a button function, the rollout opens, but when I click on the button, nothing happens…

   on centergroup pressed do
	(
		fn RecurseGroupMember = 
(
		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
			for i in objects do (
	i.pivot = [0,0,i.pivot.z]
	if (IsGroupMember i == true)  then
	(
		ExplodeGroup (GetNodeByname(i.parent.name) )
		
	)		
								)
)
RecurseGroupMember()
		)
		
)

HAd another go with the script and now the button works again, but now all objects move again to 0.0.0 so Z is moving again

on centergroup pressed do
	(
		fn RecurseGroupMember = 
(
		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
		Group objects 
		for i in $group01 do (
	$group01.pos = [0,0,i.pivot.z]
	if (IsGroupMember i == true)  then
	(
		ExplodeGroup (GetNodeByname(i.parent.name) )
		
	)		
								)
)
RecurseGroupMember()
		)
		
)

w00t DID IT!!!

works completely like I wanted. Thnx Cyfer

 on centergroup pressed do
	(
		fn RecurseGroupMember = 
(
		for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
		Group objects 
		for i in $group01 do (
	$group01.pos = [0,0,i.pivot.z]
	for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
		clearSelection()
								)
)
RecurseGroupMember()
		)
		
)

I have a follow up question for this script. Im working on an extended version of this script where you:

“Group the objects, then take the Group-pivot point and center it on X and Y and on Z-axis put the Pivot on the lowest point of all objects, so z.min. And then move the group to the 0 line on the X and Y-axis.

Ive tried a couple different scripts but somehow the group moves to the center on the Z axis and i cant figure out why.

Here’s my script!

fn RecurseGroupMember = 
			(
			for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
			Group objects 
			for i in $group01 do (
			$group01.pos = [0,0,i.min.z]
			for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
			clearSelection()
			)
			)
		RecurseGroupMember()

and another one that doesnt work

fn RecurseGroupMember = 
			(
			for i in objects do (if (i != undefined and isGroupmember i == true) do unGroup (GetNodeByname(i.parent.name) ))
			Group objects 
			for obj in $Group01.children do obj.pos = 
				  (					
				  obj.pivot = [obj.center.x,obj.center.y,obj.min.z]											
				  )
					$Group01.pos = [0,0,0]		
				   ungroup $Group01
		  
			)
			
		RecurseGroupMember()

Any ideas anyone? t.i.a.

There is your basic idea above. Everything else looks too complicated for me.


   -- make everything ungrouped for sure
 for obj in (objects as array) where isgrouphead obj do ungroup obj
 -- select all objects and store selection z-minimum
 select objects
 min_z = selection.min.z
 -- group all objects
 gr = group selection -- group dummy pos automatically set to center of selection
   -- set x and y of selection center to world Zero
 gr.pos.x = gr.pos.y = 0
   -- shift Z of selection to set selection minimum to world Zero
 gr.pos.z -= min_z
   -- ungroup
 ungroup gr
 

that’s it.

Hi DenisT,

Great, thanks for the elaborated explanation, there was no way I would’ve figured it out on my own, that script works perfect, all I needed was the Z position part. thnx