Home Coding, Scripting, Shaders

Detuch elements by ID in 3ds max

Hi, I have a script in 3ds max that detaches model elements by ID, but it doesn't work when I select multiple objects, can anybody fix this script?
Thanks in advance!

Here's the script

(
for obj in selection do

macros.run "Modifier Stack" "Convert_to_Poly"


(
(
local MatID = 1
    
while (polyop.getNumFaces $ > 0) do
    (
    $.selectByMaterial MatID
    polyList = polyop.getFaceSelection $
    
    if (polyList.count > 0) do
        (
        newName = (uniquename "DetachedObject")
        polyOp.detachfaces $ polyList delete:true asnode:true name:newName    
        )
    MatID += 1
    )
)
)
)


Replies

  • Klunk
    Offline / Send Message
    Klunk ngon master
    1. macroScript explode_by_matid
    2. category:"Claudes Utils"
    3. tooltip:"explode by material id"
    4. ButtonText:"explode"
    5. icon:#("Standard_Modifiers", 22)
    6. (
    7. fn explode_by_matid poly del_original =
    8. (
    9. matids = #{};
    10. for f = 1 to poly.numfaces do matids[polyop.getFaceMatID poly f] = true;
    11.  
    12. for matid in matids do
    13. (
    14. poly.selectByMaterial matid;
    15. detach_faces = polyop.getFacesByFlag poly 1;
    16.  
    17. newName = uniquename "DetachedObject";
    18. polyOp.detachfaces poly detach_faces delete:true asnode:true name:newName
    19. )
    20. if del_original then delete poly;
    21. )
    22.  
    23. on execute do
    24. (
    25. selected_objs = $selection as array
    26. clearNodeSelection redraw:false;
    27. for obj in selected_objs where canconvertto obj Editable_Poly do
    28. (
    29. poly = convertToPoly obj;
    30. explode_by_matid poly true;
    31. )
    32. )
    33. on isEnabled do $selection.count > 0;
    34. )

  • Nels
Sign In or Register to comment.