Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

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

  1. <div>cmds.select(cmds.polyListComponentConversion(tf = True))
  2.  
  3. </div><div>faces = cmds.filterExpand(sm=34)
  4.  
  5. </div><div>if cmds.filterExpand(sm=34):
  6.  
  7. </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

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

    1. <div>selectObj = cmds.ls(selection = True, tr = True)</div><div><br></div><div>if len(selectObj) == 0 :
    2. cmds.select(cmds.polyListComponentConversion(tf = True))
    3. faces = cmds.filterExpand(sm=34)
    4. if cmds.filterExpand(sm=34):
    5. cmds.polyDelFacet(faces)
    6. else:
    7. <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.