Saturday 25 April 2015

A simple Instancer

Have you ever thought that Max (or any other software for that matter) lacks some super basic functionality? Well sometimes the functionality is there, but only available through scripting!
That's one of those cases : you copied objects and later realise that you should have instanced them. There's no way (that I know of) to do that afterward in Max interface, but there's a simple command that does just this : instanceReplace


So I did a very simple macro script that brings up a window where you choose the objects to instance, then pick the object which will be instantiated and voilĂ ! Piece of cake.

The objects will then have the same modifiers but will all keep their respective animations, controllers, materials, object ID, etc.

The code is not too long, so I'll put it here:
-------------------------------------------------
--Make Instances---------------------------------
--Vincent Schneider 2015-------------------------
-------------------------------------------------
 macroScript makeInstances  
 ButtonText:"Make Instances"  
 category:"Vin"   
 internalcategory:"Vin"  
 Icon:#("SubObjectIcons",31)  
 (  
      local destNodes  
      local nodeNames  
        
      fn getSel =  
      (  
           destNodes = selection as array  
           nodeNames = for i in destNodes collect i.name  
      )  
        
      getSel()  
        
      rollout instRoll "Make Instances"  
      (  
           listBox lBox "Destination Nodes" items:nodeNames  
           button btnGet "Get Dest. Nodes"  
           pickButton pbtnNode "Pick Source Node"  
             
           on btnGet pressed do  
           (  
                getSel()  
                lBox.items = nodeNames  
           )  
             
           on pbtnNode picked obj do with undo label:"Make Instance" on  
           (   
            if obj != undefined do  
                (  
                     pbtnNode.text = obj.name  
                     instanceReplace destNodes obj  
                )
           )
      )
      createDialog instRoll  
 )  


You can find the script here, instructions on how to use macro scripts can be found here.

No comments:

Post a Comment