ScriptSpot

Forum topic · General Scripting

Edit Poly Modifier Quick Detach

By jeremiah_bigley · 2013-03-26

Description

Hey guys I am trying to create a script that will allow me to detach subobject elements without being asked(options dialog box).

If I understand correctly you can't access the Edit Poly Modifier Detach options? (Detach as element, Detach as clone, ect.)

So I have been playing with some work arounds... Problem is! They both create extremely unstable geometry. They detach fine... but when I go to the newly created object and try to, for example, move the faces or chamfer a vertex... max crashes. On my work computer and home computer.

Any ideas to a better solution or to stabilize what I have?
Any help would be greatly appreciated. Been at this a few nights now.. :(

Work Around #1
- this one adds a second editpoly modifier... detaches with default settings then deletes the second editpoly modifier back off.

OriginalSOL = subobjectlevel
modPanel.addModToSelection (Edit_Poly ()) ui:on
$.modifiers[#Edit_Poly].name = "DetachEditPoly"

subobjectLevel = 4
$.modifiers[#Edit_Poly].DetachToObject "Junk"


DetachModIndex = modPanel.getModifierIndex $ $.modifiers[#DetachEditPoly]
deleteModifier $ DetachModIndex


EditpolyIndex = ((modPanel.getModifierIndex $ (modPanel.getCurrentObject())) + 1)
modPanel.setCurrentObject $.modifiers[EditpolyIndex]
subobjectlevel = 0

select $Junk
subobjectlevel = 4
$.EditablePoly.SetSelection #Face #{}

Work Around #2
- this one duplicates the mesh, takes the new one, jumps into face subobject level, inverts the selection, deletes it. Goes back to the original object, deletes originally selected faces.


OriginalDetachObj = $
OriginalModIndex = (modPanel.getModifierIndex $ (modPanel.getCurrentObject()))
OriginalSOL = subobjectlevel
--
suspendediting()
maxOps.cloneNodes $ cloneType:#copy newNodes:&nnl
select nnl
resumeediting()

modPanel.setCurrentObject $.modifiers[OriginalModIndex]
subobjectlevel = OriginalSOL
max select invert
$.modifiers[#Edit_Poly].ButtonOp #DeleteFace
max select all
subobjectlevel = 0

while(modPanel.getModifierIndex $ (modPanel.getCurrentObject())) != 1 do
(
	deleteModifier $ 1
)
macros.run "Modifier Stack" "Convert_to_Poly"


select OriginalDetachObj
modPanel.setCurrentObject $.modifiers[OriginalModIndex]
subobjectlevel = OriginalSOL
$.modifiers[#Edit_Poly].ButtonOp #DeleteFace
Comments (4)

Detach elements from Editable Poly

DMZScripts · 2019-10-17

This works for me in 3ds max 2017.
It detaches all elements from and editable poly object. Hope it is this what you wanted.


function fn_detachElements nin_Object = 
( 
 naOut = #()
 if classof nin_Object == Editable_Poly do
 ( 
   suspendediting()
   try
   (
    undo off
    (
     with redraw off
     (
     while polyOp.getNumFaces nin_Object != 0 do 
     (
      elementSel  = (polyOp.getElementsUsingFace nin_Object #{1})
      baseName  = nin_Object.name
      newName   = (uniqueName baseName)
       
      polyOp.detachFaces nin_Object elementSel asNode:true name:newName
      detachedObj = (getNodeByName newName)
      append naOut detachedObj
     )
      
     for o in naOut do
     (
      baseName  = (substring o.name 1 (o.name.count-3))
      uniquePart  = (substring o.name (o.name.count-2) o.name.count)
      finalName   = (baseName + "_" + uniquePart)
      o.name    = finalName
      centerPivot o
     )
    )
   )
  )
  catch(messageBox "error: detach objects")
  resumeediting()
   
  delete nin_Object
 )
 naOut as array
)

ep = teapot()
convertToPoly ep
fn_detachElements ep

Hi

Sen · 2013-03-29

Are you just try :


subobjectLevel = 4 	
$.EditablePoly.SetSelection #Face #{......}
polyop.detachfaces $ #{.....} asNode:true name:"YourString" -- detach as node 

Don't add modifier , no need .

hmmm

jeremiah_bigley · 2013-03-29

guess no one has any ideas :/

Working?

smann · 2019-09-16

did you ever get this to work? or figure out access to the detach as clone checkbox?