Monday, September 28, 2009

Script - Explode Elements back into individual meshes

Ever find yourself having attached a bunch of stuff together and wanted to go back and re-explode the mesh?
Do you hate having to find each individual Element and clicking "Detach" a thousand times?  This script fixes that.
  • MAXScript > New Script.
  • Copy / Paste the text below into the blank page.
  • Press Control +A to select all of the text.
  • Left-Mouse click and drag this into your custom Toolbar.
  • To rename your button / change the icon, Right Click the button > Edit Button Appearance...
  • To use - Select your mesh, and press the tool button and then press Detach! which will break all of your elements back into individual objects.
  • Rejoice and be glad.


(



(
(
rollout rolTest "Detach Elems"
(
   button btRun "Detach!" width:90 align:#center offset:[0, -2]

   function detachToNodes oPoly =
   (
       if (classOf oPoly != Editable_Poly) then
           throw "Wrong input in function: detachToNodes()"
       
       local iNumFacesLastElem = 0
       local baElemFaces = #{}
       local sName = ""
   
       while (true) do
       (
           baElemFaces = polyOp.getElementsUsingFace oPoly 1
           sName = uniqueName oPoly.name
           polyOp.detachFaces oPoly baElemFaces delete:true asNode:true name:sName
           
           if ((polyOp.getNumFaces oPoly) == 0) then
           (
               delete oPoly
               exit
           )
   
           if (keyboard.escPressed == true) do
               throw "** escape key pressed **"
       )
   )

   on btRun pressed do
   (
       local currSel = selection as Array
       
       for obj in currSel do
           if ((classOf obj) == Editable_Poly) then
               detachToNodes obj
   )
) -- End Rollout

createDialog rolTest 96 27 style:#(#style_toolwindow, #style_border, #style_sysmenu)
)
)
)

No comments:

Post a Comment