Thứ Hai, 16 tháng 7, 2018

build symmetric dictionary using python in maya

import maya.cmds as mc
preciseMax=0.001
verDic=mc.ls(os=True,fl=True)
lefDic={}
rightDic={}
middleList={}
for verDicI in verDic:
pos=mc.xform(verDicI,q=True,ws=True,t=True)
if pos[0]>=- preciseMax and pos[0]<=preciseMax:
middleList[verDicI]=pos
elif pos[0]>preciseMax:
lefDic[verDicI]=pos
else:
rightDic[verDicI]=pos


symDic={}
for lefDicI in lefDic.keys():
for rightDicI in rightDic.keys():
if rightDic[rightDicI][0]<=-lefDic[lefDicI][0]+preciseMax and rightDic[rightDicI][0]>=-lefDic[lefDicI][0]-preciseMax:
if rightDic[rightDicI][1]<=lefDic[lefDicI][1]+preciseMax and rightDic[rightDicI][1]>=lefDic[lefDicI][1]-preciseMax:
if rightDic[rightDicI][2]<=lefDic[lefDicI][2]+preciseMax and rightDic[rightDicI][2]>=lefDic[lefDicI][2]-preciseMax:
symDic[lefDicI]=rightDicI
break