Detach all elements on multiple objects with a few options for better scene arrangement,
including convert to mesh, group by source or link to source or point helper.

Script
By Anubis · 2010-03-15
Detach all elements on multiple objects with a few options for better scene arrangement,
including convert to mesh, group by source or link to source or point helper.

Tags: groups, Editable Poly, detach, multiple, Editable Mesh, Elements
todor · 2021-09-13
Works good, thank you
Automating using the script
itay tzafrir · 2019-10-15
Is there a version of the script in which it works automatically with the same settings?
I want to run it using an outside script with only the "keep source object" on, the rest should be off and press detach, without even opening the dialog
Thanks
.
miauu · 2019-10-15
Save this as a .ms file.
/*
Detach Elements v.1.0
Author : Anubis [project3d.narod.ru]
Created: [2010-01-18] - entire code
Updated: [2010-03-15] - added notes
Requirement: any 3ds Max version
Description:
Detach all elements on multiple objects
Usage Notes:
Sometime in 3ds Max 2008/2009 Undo buffer become empty
after script usage. This come from the major undo bug in this
Max releases, i.e. it's not related to the script code itself.
Solution:
Use Max Edit Hold/Fetch feature instead in 3ds Max 2008/2009.
*/
-- if Detach2Elements != undefined do
-- if classOf Detach2Elements == RolloutClass do
-- destroyDialog Detach2Elements
-- rollout Detach2Elements "Detach Elements"
(
--// Top level Locals
local srcObjs = #() -- source objs
local tmpObjs = #() -- temporary
local endObjs = #() -- for conv2Mesh
local eleGroups = #() -- for UnGrouping
local keepSource = true
local UndoOn = false
local isGroup = false
local cPivot = false
--// Functions
fn DetachToElements obj cPivot &endObjs num:1 = (
while obj.getNumFaces() != 0 do (
polyop.setFaceSelection obj #{1}
obj.selectElement()
ele = polyop.getFaceSelection obj
newName = (num as string)
num += 1 -- pump up counter
polyop.detachFaces obj ele asNode:true name:newName
newObj = getNodeByName newName
append endObjs newObj
attachObjects obj newObj
)
if cPivot do centerPivot obj.children
)
mapped fn renameChildren ch = (
ch.name = ch.parent.name + ch.name
)
--// UI
-- group "Base Options"
-- (
-- checkBox keepSource "Keep Source Objects" checked:true
-- checkBox UndoOn "Enable Undo" checked:false --enabled:false
-- )
-- group "New Objects"
-- (
-- checkBox outMesh "Convert to Mesh" checked:false
-- checkBox isGroup "Group by Source" checked:false
-- checkBox cPivot "Center Pivot" checked:false
-- )
-- group ">>>"
-- (
-- button detach "Detach" width:140
-- label feed "..."
-- progressbar progBar color:green
-- )
--// this function must be here! (ie after UI def.)
fn runEntirely = (
-- feed.text = "Detaching..."
local total = (tmpObjs.count as string) -- total objects
for i = 1 to tmpObjs.count do (
-- feed.text = "Detaching... " + (i as string) + "/" + total -- progress
DetachToElements tmpObjs[i] cPivot endObjs
grp = group tmpObjs[i].children name:(srcObjs[i].name + "_Elements")
append eleGroups grp -- for UnGrouping ...
attachObjects srcObjs[i] grp move:false -- link G to source obj.
renameChildren grp.children -- rename
-- progBar.value = 100. * i / tmpObjs.count -- % progress
)
-- progBar.value = 0 -- reset progressbar
-- feed.text = "Finalize..."
eleGroups = for g in eleGroups where isValidNode g collect g -- important!
if not isGroup do
( -- if you rid of groups...
if not keepSource do ( -- and original objs deleted...
local n = 1 -- get for progressBar
for g in eleGroups do ( -- to preserve hierarchy...
holder = point pos:g.pos name:g.name
g.parent = holder -- replace GroupHead with Point.
-- progBar.value = 100. * n / eleGroups.count -- % progress
n += 1 -- pump up counter
)
)
-- progBar.value = 0 -- reset progressbar
ungroup eleGroups -- now ungroup all at once
)
if not keepSource do (delete srcObjs)
)
--// Events
-- on detach pressed do
-- (
-- feed.text = "Initialize..."
--// filter selection
srcObjs = for i in selection where canConvertTo i Editable_Poly collect i
-- save your time
if srcObjs.count == 0 then (
-- feed.text = "* Nothing to proceed *"
)
else ( --// Runtime...
disableSceneRedraw()
-- feed.text = "Preparation..."
max create mode
setWaitCursor() -------------------
TimeStart = timestamp()
numObjs = objects.count
snapshot srcObjs -- make copies...
tmpObjs = ( -- and collect 'em
for i = (numObjs + 1) to objects.count collect objects[i]
)
convertTo tmpObjs Editable_Poly
--// the "core" in Undo context
with undo "Detach" UndoOn ( runEntirely() )
delete tmpObjs -- KEEP this Out Off Undo context !!!
---------------------
endObjs = for i in endObjs where isValidNode i collect i -- important!
-- if outMesh.state do convertToMesh endObjs
select endObjs
-- feed.text = "Done!"
TimeEnd = (timestamp() - TimeStart) / 1000.
setArrowCursor() --------------------
enableSceneRedraw()
redrawViews()
format "Time:\t%sec.\n" TimeEnd
) -- end (Runtime)
-- ) -- end (on detach pressed)
) -- end of rollout
-- createDialog Detach2Elements
Automating using the script
itay tzafrir · 2019-10-15
WOW!!!
WORKS LIKE A CHARM
THANK YOU SO MUCH!!
I prefer this one, its one option and works superbly!
brainsgonedead · 2016-08-09
work!
bleras · 2016-08-06
Works great and its fast! tx!
Cool
Nevil · 2014-04-12
Hi Panayot
Cool stuff, just a little problem when pushing the Detach button on other object after Detach the fist one the script select the parts of older detached object, you can fix that by clean the arrays holding that nodes on end of the Detach button action.
Thank you.
detaching but keeping same group hierarchy
mahmouds12 · 2013-09-16
hello I need to detach all elements but keeping same group hierarchy for example I have a group called "group_1" Inside it i have 3 groups inside each group some editable polys
-Group_1
-group_A
-EDITPOLY01
-EDITPOLY02
-EDITPOLY03
-group_B
-EDITPOLY01
-EDITPOLY02
-EDITPOLY03
-group_C
-EDITPOLY01
-EDITPOLY02
-EDITPOLY03
I need my source objs to be deleted but keep the same group hierarchy Also I have objects imported from other software which has the same name... when i try to detach elements of a selected object... the script detach another object with the same name Thanks :)
help will be appreciated :)
if you talk about Max 2012
Anubis · 2012-03-26
then everything is possible, lol :)
freezeeeee
ruhl · 2012-03-23
hey anubis,
when i'm using your script. In some time when i push Detach button max freeze and nothing happened?
I think this is a some kind of bug.
new · 2011-08-30
thx
yea would be great
antokhio · 2011-07-17
thank you! Script is great!
if possible would also love to have an option to detach
in order from left upper corner to bottom right pls!
thinking about axis priority even
Y1
X2
Z3
or a small option XY YX XZ....
hi antokhio
Anubis · 2011-07-17
interesting... i try to imagine the point of your request. that w'd not change the result. if its something about the names then after detaching you may sort your elements by position and rename them.
samuelmq · 2011-01-10
liked it a lot, thx.
Yes
Anubis · 2010-11-09
Hey Ian, ya, of course, why not :)
When save a bit free time, I'll include this feature.
[Edit] Ok, here is (as separate macros), enjoy ;)
W DIGITAL · 2010-11-08
hi anubis,
can we add an option, to detach all polygons as well?
stenionet · 2010-03-30
Very useful.
Thanks.