Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Detach Faces to separate objects...

Detach Faces to separate objects...

blakestone
Collaborator Collaborator
7,039 Views
6 Replies
Message 1 of 7

Detach Faces to separate objects...

blakestone
Collaborator
Collaborator
I understand that the MacroRecorder will only provide limited information of what 3dsMax is actually doing however in this example it does provide some useful information when detaching an objects face when done by hand... However when I try to replicate this via MaxScript it does not give the same result, it does detach the faces but does not detach them as a new object.

Does anyone know what the additional step/parameter I need to do this?


(

local my_selection = selection
local my_faces = my_selection.faces

for faces in my_faces do (
my_selection.setSelection #Face #{faces.index}
my_selection.detachToElement #Face keepOriginal:off
)

redrawViews()

)

0 Likes
7,040 Views
6 Replies
Replies (6)
Message 2 of 7

Steve_Curley
Mentor
Mentor
DetachToElement doesn't detach the selection to a new object, only to an element of the current object (as far as I can see anyway). Equivalent to using the Detach button and ticking the "To Element" checkbox.
Try the PolyOp methods instead.

(
local polyList = #{}

polyList = polyOp.getFaceSelection selection
polyOp.detachFaces selection polyList delete:true asNode:true
)

That will detach all the selected polys to a single new object. If you want each discontinuous element detached separately then it will be a bit more involved, likewise if you want an object per poly.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 7

blakestone
Collaborator
Collaborator
Thanks Steve I figured it out... This script will detach each face as their own separate object:


(

local my_selection = selection
local my_faces = undefined
local my_total = undefined
local my_faceSelection = undefined
local my_prefix = "newFace_"

-- ==========================================================================================
-- Function: detach all faces in selected object
-- if multiple objects are selected only the first object in the array will be executed

function detachAllFaces = (

-- convert selected object to Editable Poly if it not already is
if (classOf my_selection != Editable_Poly) then (convertToPoly my_selection)

my_faces = my_selection.faces
my_total = my_faces.count

-- detach all faces
for A1 = my_total to 1 by -1 do (
polyOp.setFaceSelection my_selection #{A1}
my_faceSelection = polyOp.getFaceSelection my_selection
polyOp.detachFaces selection my_faceSelection delete:true asNode:true name:(my_prefix + (A1 as string))
)

-- delete original object (which no longer has any attached faces)
delete my_selection

)

-- ==========================================================================================

detachAllFaces()

-- ==========================================================================================

)
0 Likes
Message 4 of 7

barigazy
Enthusiast
Enthusiast
--detach faces, add name on the last created object, put pivot at the center of object (single face in this case)
fn detachOneByOne obj my_prefix: cntPivot: =
(
local poDetach = polyOp.detachFaces
for face = obj.faces.count to 1 by -1 do poDetach obj #{face} delete:true asNode:true name:(my_prefix+face as string)
if cntPivot do centerPivot objects
)
fn detachAllFaces affectFirstObj:on = if selection.count != 0 do
(
local objArr = for o in selection where isKindOf o geometryClass and not isKindOf o TargetObject collect (if not isKindOf o Editable_Poly do convertToPoly o ; o)
if objArr.count == 0 then messageBox "Select Geometry Objects Only!" title:"Warning" beep:off else
(
if affectFirstObj then
(
detachOneByOne objArr my_prefix:"newFace_" cntPivot:on
delete objArr
)
else
(
for o in objArr do (detachOneByOne o my_prefix:(o.name+"_newFace_") cntPivot:on)
delete objArr
)
clearSelection() ; free objArr
)
)
--if you want to detach all faces from first object in selection then run:
detachAllFaces()
--or if you want to affect all selected objects then use next line
detachAllFaces affectFirstObj:off

if you want to detach all faces from first object in selection then run:
detachAllFaces()

or if you want to affect all selected objects then use next line
detachAllFaces affectFirstObj:off

Also you can try this script http://www.scriptspot.com/3ds-max/scripts/select-objects-by-bitmaptex
0 Likes
Message 5 of 7

raoul_emilian
Enthusiast
Enthusiast

And how to use that script from scriptspot? Where i press to detach all faces to elements ? For me it doesnt work

0 Likes
Message 6 of 7

denisT.MaxDoctor
Advisor
Advisor

@raoul_emilian wrote:

And how to use that script from scriptspot? Where i press to detach all faces to elements ? For me it doesnt work


There is usually no point in continuing a topic that is more than three years old, especially if you didn't start it.

Open a new one where you clearly explain your needs or problems.

0 Likes
Message 7 of 7

raoul_emilian
Enthusiast
Enthusiast
Uuuu
0 Likes