Home Technical Talk

Pedro's Super Smart Create for Maya

interpolator
Offline / Send Message
maxivz interpolator
Having to learn Maya coming from Max I was really missing the super smart create script Pedro made
So I'm trying my best to recreate it, being pretty new to Maya and python I'm sure this things can be done way more efficient and the functionality could be improved, so please feel free to post suggestions.
I have developed it in python using Maya 2016, but it should work in any version as far as I know as I didn't use anything fancy
Anyways, here's the tool (the descriptions are taken from Pedro's thread, so you can compare the functionality):

Connects verts that belong to the same face 



Divides the selected edge in 2, putting a vert in the middle of the edge

Connects the selected edges if there is faces in between the edges

Caps selected borders

Bridges selected edges( it sometimes doesn't work, but it seems to be a bug with the bridge tool in maya(?), I only recommend bridging between small selections)

When you select 2 adjacent edges it creates a face

Bridges selected polys


Second release! Fixed bugs and stuff. Please report any issues you have and please post any suggestions for improving the code/functionality/fixing stuff, i'm just starting with Maya and python scripting and I would love critics that could help me improve!

Script:
import maya.cmds as cmds
'''
Original script idea by Pedro Amorim ( http://edgesize.com/ )
Maya implementation by Maximiliano Vazquez (artbymaxi.com)
'''
#functions
def Intersect(a, b):
    return list(set(a) & set(b))
 
def Difference(a,b):
    return list(set(a)- set(b))
     
def AreBorder(selectedEdges):
    cmds.select( selectedEdges[0], r=True )
    cmds.pickWalk( d='left' , typ="edgeloop")
    possibleEdgeBorders  = cmds.filterExpand(sm=32)
    cmds.select(selectedEdges, r= True)
&nbsp;&nbsp;&nbsp;&nbsp;if set(possibleEdgeBorders) <= set(selectedEdges):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return True
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
def FaceBetweenEdges(edgeSelection):
&nbsp;&nbsp;&nbsp;&nbsp;#Maybe a better option to do this?
&nbsp;&nbsp;&nbsp;&nbsp;for edge in edgeSelection:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjacentFaces = cmds.filterExpand(cmds.polyListComponentConversion(edge,fe = 1, tf = 1),sm=34)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjacentEdges = cmds.filterExpand(cmds.polyListComponentConversion(adjacentFaces,ff = 1, te = 1),sm=32)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if edge in adjacentEdges:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjacentEdges.remove(edge)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if len(Intersect(adjacentEdges,edgeSelection)) > 0:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return True
&nbsp;&nbsp;&nbsp;&nbsp;return False
 
def GetEdgeNumber(edge):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return int(edge.split('[')[1].split(']')[0])
 
def AreAdjacent(edges):
&nbsp;&nbsp;&nbsp;&nbsp;vertsA = cmds.filterExpand(cmds.polyListComponentConversion(edges[0],fe = 1, tv = 1),sm=31)
&nbsp;&nbsp;&nbsp;&nbsp;vertsB = cmds.filterExpand(cmds.polyListComponentConversion(edges[1],fe = 1, tv = 1),sm=31)
&nbsp;&nbsp;&nbsp;&nbsp;return len(Intersect(vertsA,vertsB)) == 1
 
#Main Function
#If Verts Selected
verts = cmds.filterExpand(sm=31)
 
if verts:
&nbsp;&nbsp;&nbsp;&nbsp;if len(verts) < 40:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for vert in verts:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyConnectComponents(vert,verts)
&nbsp;&nbsp;&nbsp;&nbsp;else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maya.mel.eval("ShrinkPolygonSelectionRegion;")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyTriangulate(ch = 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.select(verts,r=1)
&nbsp;&nbsp;&nbsp;&nbsp; 
#if edges selected
edges = cmds.filterExpand(sm=32)
if edges:
&nbsp;&nbsp;&nbsp;&nbsp;if len(edges) == 1:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oldVerts = cmds.polyListComponentConversion(fe = 1, tv = 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polySubdivideEdge(ch = 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newVerts = cmds.polyListComponentConversion(fe = 1, tv = 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.select(Difference(newVerts,oldVerts), r = 1)
&nbsp;&nbsp;&nbsp;&nbsp;elif FaceBetweenEdges(edges):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.dR_DoCmd("connectTool")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maya.mel.eval("escapeCurrentTool;")
&nbsp;&nbsp;&nbsp;&nbsp;elif AreBorder(edges):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyCloseBorder(ch = 1)
 
&nbsp;&nbsp;&nbsp;&nbsp;elif AreAdjacent(edges):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edges = cmds.filterExpand(sm=32)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyAppend(a=[GetEdgeNumber(edges[0]),GetEdgeNumber(edges[1])])
&nbsp;&nbsp;&nbsp;&nbsp;else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyBridgeEdge( ch=1, divisions = 0)
&nbsp;&nbsp;&nbsp;&nbsp; 
#if faces selected
faces = cmds.filterExpand(sm=34)
if cmds.filterExpand(sm=34):
&nbsp;&nbsp;&nbsp;&nbsp;if len(faces) > 1:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edges = cmds.polyListComponentConversion(ff = 1, te = 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyDelFacet(faces)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.select( edges , r= 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmds.polyBridgeEdge( ch=1, divisions = 0)

Replies

Sign In or Register to comment.