检查模型是否有点重合
思路:
先求所有点的位置的列表,然后去掉重复的点的位置,再遍历出重复的点加入新的列表,最后选择这些重复的点。
下面有两种写法,第二种更完善,更快一点
①
import maya.cmds as mc
sel = mc.ls(sl=True)
vtx_num = mc.polyEvaluate(v=True)
list_pos = []
for i in range(vtx_num):
vtx_name = 'pSphere1.vtx[{0}]'.format(i)
pos = mc.pointPosition(vtx_name)
list_pos.append(pos)
list_pop = []
for a in list_pos:
if list_pos.count(a) != 1:
if a in list_pop:
pass
else:
list_pop.append(a)
list_sel = []
for b in range(vtx_num):
for c in list_pop:
vtx_name = 'pSphere1.vtx[{0}]'.format(b)
if mc.pointPosition(vtx_name) == c:
list_sel.append(vtx_name)
mc.select(list_sel)
②
import maya.cmds as mc
sel = mc.ls(sl=True)
for obj in sel:
vtx_num = mc.polyEvaluate(obj,v=True)
dict = {}
allpos = []
for all in range(vtx_num):
trans = []
vtx_name = 'pSphere1.vtx[{0}]'.format(all)
vtx_pos = mc.pointPosition(vtx_name)
for b in vtx_pos:
trans.append(round(b,2))
allpos.append(trans)
dict[str(trans)] = vtx_name
list_sel = []
check =[]
for c in allpos:
if c not in check:
check.append(c)
else:
list_sel.append(dict.get(str(c)))
print allpos
mc.select(list_sel)