ScriptSpot home

Detach Elements

Downloads

Release history (1)
  • Version 1.0Listed version

    Listing updated

    No download linked to this version

Other files (2)
3ds Max compatibility
Unknown
Report a problem
Community compatibilityNo compatibility reports yet

No reports yet for the available releases.

Community reviewsNo reviews yet.

Listing details

Version
1.0
Original version requirement
any 3ds Max version
Author’s update date
Legacy votes
69
Listing created
How compatibility works

Compatibility comes from the author’s supported range or requirements in the original listing. A tested version records what the author tried.

“2020 unconfirmed” in the catalog means support for 3ds Max 2020 is still unknown.

Community reports record successful tests on specific releases.

Posted by

Anubis

Panayot Karabakalov

More by this author

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.

Detach Elements

Setup & notes

Please read the notes inside the code as well.

Update:
Recently asked me for installation instructions so I add macroScript.
Briefly, put Detach_Elements.ms into your scripts folder and run .mcr file once.
After that you'll find it into Tools category in your Costumize User Interface.

Comments (17)
Todor Vankov

Works good, thank you

itay tzafrir

Automating using the script

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

.

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

Reply to miauu
itay tzafrir

Automating using the script

WOW!!!

WORKS LIKE A CHARM

THANK YOU SO MUCH!!

pablo

work!

Works great and its fast! tx!

Nevil Redfield(Nasser Merati)

Cool

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.

mahmoud

detaching but keeping same group hierarchy

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 :)

Panayot Karabakalov

if you talk about Max 2012

then everything is possible, lol :)

george

freezeeeee

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.

info

thx

antokhio

yea would be great

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....

Reply to antokhio
Panayot Karabakalov

hi antokhio

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

liked it a lot, thx.

Panayot Karabakalov

Yes

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 ;)

Attachments
V-MOTION

hi anubis,
can we add an option, to detach all polygons as well?

stenionet

Very useful.
Thanks.