Jump to content

Move Grouped Object using max script


abdullahsorathia
 Share

Recommended Posts

I am new to max and problem that i am facing is I have objects that are grouped togother there are 3 objects a box , a frame surrounding the box which has UV map and some rivets like objects on the frame. and name this group as storage When I try to move the grouped object using max script all the objects inside the group moves move individually rather than moving as a whole like a whole. Is there any other possible solution to do this or a method though which i can achieve the same.

 

Shglt.png

 

select $Storage
maxOps.cloneNodes (selection as array) cloneType:#instance newNodes:&nnl #nodialog
select nnl
nnl.pos =  [1,2,1];

Link to comment
Share on other sites

  • 11 months later...

when you move a group in the UI in max it applies the transform to the dummy, but the information about the positions of stuff relative to each other inside the group is not an inherent part of the group - the group simply notes that it has nodes in it and that those nodes are instances of objects in your scene.

 

You'll note that when you manually create an instance of a group in the UI, open it and move one of the objects, that the original group remains unaffected.

 

Here, by writing "nnl.pos [1,2,1]", you are telling Max to apply a point3 value to the position transform of each of the objects inside your array "nnl" and it responds by aligning the pivot points of everything in your group including the dummy to that position.

 

note that nnl contains the dummy as well as all of the objects; my group named "tigger", which contains 3 boxes returns an array "nnl" which looks like this

 

 

#($Dummy:tigger001 @ [100.000000,100.000000,100.000000], $Box:christopher001 @ [110.000000,90.000000,100.000000], $Box:pinface001 @ [110.000000,110.000000,80.000000], $Box:piglet001 @ [90.000000,110.000000,100.000000])

 

you only need to do what max would do if you were moving a group around in the UI, which is move the dummy.

 

piglet = mybox = box length:20 width:20 height:20 pos:[0,20,20] name:"piglet"
christopher = box length:20 width:20 height:20 pos:[20,0,20] name:"christopher"
pinface = box length:20 width:20 height:20 pos:[20,20,0] name:"pinface"
select #($christopher, $pinface, $piglet)
group selection name:"tigger"

fn moveGroup newPos targetObj = (
select targetObj
foo = maxOps.cloneNodes (selection as array) cloneType:#instance newNodes:&nnl #nodialog
select nnl
nnl[color="red"][1][/color].pos = newPos
)

moveGroup [100,100,100] $tigger
--nnl[2].pos = [200,200,200] /*remove the comment -- at the beginning of this line and one of the boxes in the group will be moved without affecting the original group instance*/ 

Edited by batteryoperatedlettuce
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...