Home Technical Talk

[Maya] Small Smart Collapse Script

polycounter
Offline / Send Message
Justo polycounter
Short script that collapses component clusters for Maya 2018 :) Full credits to eltarbos!




(Python) Code:
import maya.cmds as cmds<br>sel = cmds.ls(sl=1, fl=1)<br>convVerts = cmds.polyListComponentConversion(sel, tv=1)<br>cmds.scale(0, 0, 0, cs=1, r=1)<br>cmds.polyMergeVertex( convVerts, d=0.000001 )

Original Post:



So I've been getting into Python in hopes of not banging my head as frequently as I do whenever I get to make my own scripts. Right now I was trying to mimic Max' merging ways, in which it welds to the center of separate clusters of selected components. For this, I think I would need to...

1-make a for operation that would evaluate whether the component right next to the selected one is also selected or not; so that it knows when a selected shell ends.
2-Calculate the center of these shells.
3-Weld to center by individual shells one at a time.

Maybe I'm going wrong about this though...perhaps I could just skip 2) and do 3) while hiding momentarily individual shells so that it doesnt all weld together...

Does anyone know of any scripts that do any of these 3 steps (mainly 1) ), so that I can have a look at how it's written?

Replies

  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    Hi Justo,
    If you are on maya 2018, thanks to the improved component space, you can use this simple script:
    import maya.cmds as cmds<br>sel = cmds.ls(sl=1, fl=1)<br>convVerts = cmds.polyListComponentConversion(sel, tv=1)<br>cmds.scale(0, 0, 0, cs=1, r=1)<br>cmds.polyMergeVertex( convVerts, d=0.000001 )


  • Justo
    Options
    Offline / Send Message
    Justo polycounter
    Hey @eltarbos , that seems to do the trick, thank you. What is this "improved component space" you're talking about? Any info you could give on the code you just gave would be super helpful to learn from. This is what I understand by reading it:
    import<span>&nbsp;maya</span>.<span>cmds&nbsp;</span>as<span>&nbsp;cmds
    </span>
    # Here you're getting the selection made<br><span>sel&nbsp;</span>=<span>&nbsp;cmds</span>.ls(sl=1,<span>&nbsp;fl</span>=1)
    
    #Then you convert that face selection to vertices<br><span>convVerts&nbsp;</span>=<span>&nbsp;cmds</span>.polyListComponentConversion(sel,<span>&nbsp;tv</span>=1)
    
    #Then you scale those verts down...to its individual clusters...somehow...<br>cmds.scale(0,&nbsp;0,&nbsp;0,<span>&nbsp;cs</span>=1,<span>&nbsp;r</span>=1)
    
    #Then you weld<br>cmds.polyMergeVertex(<span>&nbsp;convVerts</span>,<span>&nbsp;d</span>=0.000001&nbsp;)

    cs=1? WHat's that? Cant find that in the documentation. That's the new component space? What is it?

  • Justo
    Options
    Offline / Send Message
    Justo polycounter
    Also it seems to work too even with adjacent loops of edges! Even though if converted to verts they'd be all one big cluster! GENIUS! What is this sorcery?!
  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    Yes, cs is for component space.
    In this mode, in maya 2018, every component shell has its own pivot on the averaged normal of its components.
    In previous versions, you had only one pivot at the average normal of all selected components.
  • Justo
    Options
    Offline / Send Message
    Justo polycounter
    @elbatros So, in other words, it's kind of doing what I wanted to do with point 1) up in the first post, right? Finding shells of components, then assigning pivots to them. Only better, because it even can work with adjacent loops?
  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    What you described in your first post was exactly what you'd need to do with previous maya version. Now, you have a function that makes it for you.
  • Justo
    Options
    Offline / Send Message
    Justo polycounter
    It's great to see such a thing automated. Thanks again. Changed the title of this thread in case anyone else finds this useful. You rock eltarbos!
  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
  • Visum
    Options
    Offline / Send Message
    Visum polycounter lvl 7
    This looks useful.
    Too bad i'm on LT :neutral:

Sign In or Register to comment.