Home Technical Talk

[Python][Maya] Delete components

polycounter
Offline / Send Message
Pinned
Justo polycounter
Hi guys, I was making a script that´d delete components replicating Max's behaviour, like when you hit delete on a vertex\edge, it´ll convert that selection to face mode and then delete it.

<div>cmds.select(cmds.polyListComponentConversion(tf = True))

</div><div>faces = cmds.filterExpand(sm=34)

</div><div>if cmds.filterExpand(sm=34):

</div><div>			cmds.polyDelFacet(faces)</div>


It works! But now I wanted to add a clause or something that´d say "If there are no components selected...just use the regular delete command" or sth like that. (like for deleting objects, or any other type of element that are not vertex/edge/faces).

Does anyone now a simple manner to do this?

Replies

  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    put in a if condition to test if "faces" is null

    if faces is not 0 :<br>&nbsp;do stuff<br>else<br>&nbsp;delete things
  • Justo
    Offline / Send Message
    Justo polycounter
    Hey @sprunghunt , thanks for replying. Maybe I'm forgetting something obvious here, but that condition is not enough. If I create a cube and execute that from object mode, without even entering to faces or making any subobject selection, it still enters into the if and deletes faces. (if faces != 0:    or   if faces is not 0:  )
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    Justo said:
    Hey @sprunghunt , thanks for replying. Maybe I'm forgetting something obvious here, but that condition is not enough. If I create a cube and execute that from object mode, without even entering to faces or making any subobject selection, it still enters into the if and deletes faces. (if faces != 0:    or   if faces is not 0:  )
    sorry I was being a bit vague -- here's some more detailed code:

    <div>selectObj = cmds.ls(selection = True, tr = True)</div><div><br></div><div>if len(selectObj) == 0 :
        cmds.select(cmds.polyListComponentConversion(tf = True))
        faces = cmds.filterExpand(sm=34)
        if cmds.filterExpand(sm=34):
            cmds.polyDelFacet(faces)
    else:
    <span style="background-color: transparent; color: inherit; font-size: inherit; font-family: "Open Sans", sans-serif;">    cmds.delete(selectObj)</span></div>
  • Justo
    Offline / Send Message
    Justo polycounter
    @sprunghunt Ohh I see, you're using the ls command for the condition. Thanks for writing that, it works great! Would you happen to know though why it doesn't work on control vertices in curves?
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    Justo said:
    @sprunghunt Ohh I see, you're using the ls command for the condition. Thanks for writing that, it works great! Would you happen to know though why it doesn't work on control vertices in curves?
    if I run the script when I have a control vertex selected it does nothing. That's to be expected because a nurbs control vertex cannot be converted to a face. And a control vertex is not a transform - which is what the 'ls' command excludes.
  • Justo
    Offline / Send Message
    Justo polycounter
    Awesome, I see. Thank you for explaining that man :) I'll see if I can add another condition to take those into account, but as it is, your code works wonderfully. Thanks again!
Sign In or Register to comment.