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):
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!
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
)
if
set
(possibleEdgeBorders) <
=
set
(selectedEdges):
return
True
def
FaceBetweenEdges(edgeSelection):
#Maybe a better option to do this?
for
edge
in
edgeSelection:
adjacentFaces
=
cmds.filterExpand(cmds.polyListComponentConversion(edge,fe
=
1
, tf
=
1
),sm
=
34
)
adjacentEdges
=
cmds.filterExpand(cmds.polyListComponentConversion(adjacentFaces,ff
=
1
, te
=
1
),sm
=
32
)
if
edge
in
adjacentEdges:
adjacentEdges.remove(edge)
if
len
(Intersect(adjacentEdges,edgeSelection)) >
0
:
return
True
return
False
def
GetEdgeNumber(edge):
return
int
(edge.split(
'['
)[
1
].split(
']'
)[
0
])
def
AreAdjacent(edges):
vertsA
=
cmds.filterExpand(cmds.polyListComponentConversion(edges[
0
],fe
=
1
, tv
=
1
),sm
=
31
)
vertsB
=
cmds.filterExpand(cmds.polyListComponentConversion(edges[
1
],fe
=
1
, tv
=
1
),sm
=
31
)
return
len
(Intersect(vertsA,vertsB))
=
=
1
#Main Function
#If Verts Selected
verts
=
cmds.filterExpand(sm
=
31
)
if
verts:
if
len
(verts) <
40
:
for
vert
in
verts:
cmds.polyConnectComponents(vert,verts)
else
:
maya.mel.
eval
(
"ShrinkPolygonSelectionRegion;"
)
cmds.polyTriangulate(ch
=
1
)
cmds.select(verts,r
=
1
)
#if edges selected
edges
=
cmds.filterExpand(sm
=
32
)
if
edges:
if
len
(edges)
=
=
1
:
oldVerts
=
cmds.polyListComponentConversion(fe
=
1
, tv
=
1
)
cmds.polySubdivideEdge(ch
=
1
)
newVerts
=
cmds.polyListComponentConversion(fe
=
1
, tv
=
1
)
cmds.select(Difference(newVerts,oldVerts), r
=
1
)
elif
FaceBetweenEdges(edges):
cmds.dR_DoCmd(
"connectTool"
)
maya.mel.
eval
(
"escapeCurrentTool;"
)
elif
AreBorder(edges):
cmds.polyCloseBorder(ch
=
1
)
elif
AreAdjacent(edges):
edges
=
cmds.filterExpand(sm
=
32
)
cmds.polyAppend(a
=
[GetEdgeNumber(edges[
0
]),GetEdgeNumber(edges[
1
])])
else
:
cmds.polyBridgeEdge( ch
=
1
, divisions
=
0
)
#if faces selected
faces
=
cmds.filterExpand(sm
=
34
)
if
cmds.filterExpand(sm
=
34
):
if
len
(faces) >
1
:
edges
=
cmds.polyListComponentConversion(ff
=
1
, te
=
1
)
cmds.polyDelFacet(faces)
cmds.select( edges , r
=
1
)
cmds.polyBridgeEdge( ch
=
1
, divisions
=
0
)
Replies
I have updated the script and the first post, its now a lot more stable, a lot faster, now you can connect more than 2 edges and the connect tool for vertexes is faster
We noticed that you didn't match cases of the functions defined and the functions called, so I had to go through and do that to get the script to function. Once I did that, it worked awesome and I will be using it religiously now!
Thanks.
@Pedro Amorim :
I am working on more smart scripts like this, I should make a new thread soon
I have updated the script once more with two more bug fixes. Hopefully there's no more bugs now, but make sure to report any bug if you find one
Edge select: // Error: Line 2.1: Syntax error
What function are you trying to call? When is the error triggering? Has it started with the new version of the script?
I will give it a shot on Maya 2016 Extension 2 SP2 asap, and I'll let you know if I find any issue.
Thanks for sharing this !