------------------------------------------------------------------------- --Detaches all polygons of selected objects to separate nodes, with the option of resetting their transform/pivot and randomizing wirecolors. --Faster detaching method originally by Panayot Karabakalov aka "Anubis" @ Scriptspot.com --written by Christoph Bülter ------------------------------------------------------------------------- macroscript detachPolygons category:"Custom" ( try(destroyDialog ro_detachPolygons)catch() rollout ro_detachPolygons "Detach Polys" width:127 height:100 ( local killOriginal = true --use this to to have either keep or delete the original object local resetTransforms = true --use this to apply transform and pivot reset to the detached objects local randomWirecolors = true --use this to apply random colors to the detached objects checkbox chk_kill "Delete Original Object" pos:[4,4] width:103 height:16 checked:true checkbox chk_reset "Reset Transforms" pos:[4,20] width:103 height:16 checked:true checkbox chk_color "Randomize Wirecolor" pos:[4,36] width:147 height:16 checked:true button btn_detach "Detach Polygons" pos:[4,56] width:118 height:39 on chk_kill changed theState do ( if theState == true then killOriginal = true else killOriginal = false )--end on on chk_reset changed theState do ( if theState == true then resetTransforms = true else resetTransforms = false )--end on on chk_color changed theState do ( if theState == true then randomWirecolors = true else randomWirecolors = false )--end on on btn_detach pressed do ( if selection.count > 0 do ( max create mode local arrDetachedElements = #() local theFacecount = 0 rollout ro_detachPolygons_PB "Detaching Polygons..." width:300 height:16 ( progressBar pb_detach "" pos:[0,0] width:300 height:16 color:(color 255 0 0) ) local thePB = ro_detachPolygons_PB local arrSel = for i in selection where canConvertTo i Editable_Poly collect i for obj in arrSel do ( convertTo obj Editable_Poly local arrDetachedElements = #() --reset array of elements for each new object local theStartCount = obj.getNumFaces() local theFacecount = obj.getNumFaces() createDialog thePB thePB.pb_detach.color = red thePB.title = ("Detaching: '"+obj.name+"' with "+theFacecount as String+" Polys") --DETACH for f = obj.getNumFaces() to 1 by -1 do ( local newName = (obj.name + "_detached_" + (f as string)) polyop.detachFaces obj #{f} asNode:true name:newName local newObj = getNodeByName newName --optional: if randomWirecolors do newObj.wirecolor = (color (random 0 255) (random 0 255) (random 0 255)) if resetTransforms do append arrDetachedElements newObj thePB.pb_detach.value = 100.*(theStartCount-theFacecount)/theStartCount theFacecount = obj.getNumFaces() )--end for --optional: if not resetTransforms do destroyDialog thePB if killOriginal then delete obj --RESET TRANS if resetTransforms do ( thePB.pb_detach.color = green thePB.pb_detach.value = 0 thePB.title = ("Resetting Transforms on "+arrDetachedElements.count as String+" Objects") for i=1 to arrDetachedElements.count do ( resetXForm arrDetachedElements[i] convertTo arrDetachedElements[i] (Editable_Poly) resetTransform arrDetachedElements[i] resetScale arrDetachedElements[i] resetPivot arrDetachedElements[i] centerpivot arrDetachedElements[i] alignPivot arrDetachedElements[i] thePB.pb_detach.value = 100.*i/arrDetachedElements.count )--end for )--end if redrawViews() )--end for destroyDialog thePB clearSelection() )--end if )--end on ) createDialog ro_detachPolygons )--end macro