Notifications
Clear all

[Closed] Replacing an object while retaining hiearchy?

Hi,
I’m writing a macro that will replace an object with a dummy of the same name with identical transforms. I have it all working but i’m having trouble getting it to retain the original objects position in the hierarchy. I can get an objects parent and reparent the new dummy to the original parent, but if i’m replacing the parent it breaks all links parented to it. Here is the script i have so far. Does anyone know how to get an objects children and make sure when its replaced it has the same children? Thanks in advance for helping out a scripting noob
Cheers,
David

x = $.name
y = $.pos
z = $.rotation
ab = $.scale
bc = $.parent
delete $
mydummy = dummy ()
select mydummy
$.name = x
$.rotation = z
$.pos = y
$.scale = ab
$.parent = bc

5 Replies

objects have a .children property which returns an array of the object’s children. I don’t recall if you can set the .children property directly, but if not you can loop through this array and set each object’s .parent.

<allonym>

this should do what you want:

curObj = $
  
  newObj = dummy()
  
  newObj.name = curObj.name
  newObj.rotation = curObj.rotation
  newObj.pos = curObj.pos
  newObj.scale = curObj.scale
  newObj.parent = curObj.parent
  
  for c in curObj.children do (
  	c.parent = newObj
  )
  
  delete curObj

Or you could use instanceReplace().

d = dummy()
   objList = <objects you want to replace>
   
   for obj in objList do instanceReplace obj d
   
   -- If you want unique objects (non-instanced) uncomment the line below.
   --InstanceMgr.MakeObjectsUnique &objList #individual
   
   delete d

Thanks very much for the help

Another way to do it: (requires max 5.1 or higher)


$.baseobject = createinstance dummy

  • Martijn