check_rig

#coding=UTF-8

import checkingBoxBase as cbb
from maya.cmds import *
import maya.mel as mm

reload(cbb)
“”"
class checkingBoxCmd(cbb.checkingBoxCmd):
pass
“”"
class checkingBoxUI(cbb.checkingBoxUI):
title = 'Checking Box - Rig ’
win_height = 400
def updateList(self, *args):
cbb.checkingBoxUI.updateList(self,*args)
#checking1()
CheckObjectKFrame()
#texFileCheck()
clearRedundantShapes()
clearUnusedNodes()
clearLightLinkers()
cheakHypershade()
#checkFaceShade()
#delHistory()
#checkAxis()
checkSameObjs()
nameShapes()
#checkUVSets()
#checkNormals()
clearUnknownNode()
removeOpenedWindow()

Cmds ========================================

class checking1(cbb.checkingBoxCmd):
label = u’checking1’
def cmd(self):
#self.cont = ‘’
print ‘checking1’
self.cont += u’Finish’
return 1
def showInfo(self):
cbb.checkingBoxCmd.showInfo(self)
text(al=‘left’,l=‘other info’)
class CheckObjectKFrame(cbb.checkingBoxCmd):
label = u’检查所有大纲物体有没有K帧’
def cmd(self):
try:
sel = cmds.ls(type=“transform”)
self.l = []
for i in sel:
key = cmds.keyframe( i, query=True, keyframeCount=True )
if key == 0:
pass
else:
self.l.append(i)
if len(self.l) == 0:
self.cont = u’检查完成,没有K帧。’
return 1
else:
self.showInfo()
return 0
except:
self.cont = u’检查完成,有K帧。’
return 0
def showInfo(self):
cbb.checkingBoxCmd.showInfo(self)
setParent(self.infoUI)
columnLayout(adj=1)
iconTextButton(l=u"有K帧的物体名:",h=18,style=‘iconAndTextHorizontal’,bgc=[0.8,0.8,0.8])
# setParent(’…’)
# setParent(’…’)
for obj in self.l:
columnLayout(adj=1)
#iconTextButton(l=u"有K帧的物体名:",h=18,style=‘iconAndTextHorizontal’,bgc=[0.8,0.8,0.8])
columnLayout(adj=1,co=(‘left’,20))
iconTextButton(l=obj,h=18,style=‘iconAndTextHorizontal’,
c=‘from maya.cmds import *;select("%s")’%obj)
setParent(’…’)
setParent(’…’)
class clearLightLinkers(cbb.checkingBoxCmd):
label = u’清理灯光链接’
def cmd(self):
try:
mm.eval(“jrLightLinksCleanUp”)
self.cont = u’清理完成。’
return 1
except:
self.cont = u’清理失败。’
return 0
class removeOpenedWindow(cbb.checkingBoxCmd):
label = u’关闭多余窗口,并线框显示’
def cmd(self):
try:
from scripts.general import remove_opened_windows
remove_opened_windows.main()
import scripts.general.panel as panel
panel.Panel().set_outliner_persp()
except Exception:
self.cont = u’清理失败。’
return 0
else:
self.cont = u’清理完成。’
return 1
class clearUnknownNode(cbb.checkingBoxCmd):
label = u’清理无法识别的节点’
def cmd(self):
try:
from scripts.general import delete_unknown_node
delete_unknown_node.main()
self.cont = u’清理完成。’
return 1
except:
self.cont = u’清理失败。’
return 0
class checkSameObjs(cbb.checkingBoxCmd):
label = u’检查同名的物体’
def cmd(self):
import checkSameName
reload(checkSameName)
ins = checkSameName.checkSameName()
ins.check()
if ins.list=={}:
return 1
else:
self.cont = u’点击下列物体名称进行选择’
return 0
def showInfo(self):
cbb.checkingBoxCmd.showInfo(self)
import checkSameName
ins = checkSameName.checkSameName()
ins.check()
ins.showUI(self.infoUI)
class checkNormals(cbb.checkingBoxCmd):
label = u’检查法线’
def cmd(self):
mm.eval(‘setNamedPanelLayout “Single Perspective View”’)
modelEditor(‘modelPanel4’,e=1,twoSidedLighting=0,udm=1)
setFocus(‘modelPanel4’)
mm.eval(‘DisplayShaded’)
self.cont = u’单视图显示\n’
self.cont += u’单个默认灯光\n’
self.cont += u’使用默认材质显示\n’
self.cont += u’实体显示\n’
self.cont += u’\n请检查各物体的法线…\n’
return .5
class checkUVSets(cbb.checkingBoxCmd):
label = u’检查UV’
def cmd(self):
cont = u’’
objs = ls(type=‘mesh’)
for obj in objs:
auv = polyUVSet(obj, q=1, auv=1)
if len(auv)>1:
cont += u’%s存在多个UVSet:\n’%obj
for uv in auv:
cont += ‘%s,’%uv
cont += ‘\n’
cuv = polyUVSet(obj,q=1, cuv=1)
if cuv!= ‘map1’:
cont += u’当前UV:%s\n’%cuv
if cont != ‘’:
self.cont = cont
return 0
else:
self.cont = u’所有物体UVSet正常!\n’
self.cont += u’请检查UV是否有重叠和扭曲的情况…\n’
return .5
class clearUnusedNodes(cbb.checkingBoxCmd):
label = u’清理无用的节点,相机,灯光,层,mentalray,海龟节点等’
def cmd(self):
self.cont = ‘’
# Get nodes
cams = mm.eval(‘listTransforms -cameras’)
cmds.select(“defaultLightSet”,hi=True)
lits = ls(sl=True,type=‘transform’)
select(cl=True)
nodes = ls(type=[‘displayLayer’,‘renderLayer’])
try:
nodes.extend(ls(type=‘mentalraySubdivApprox’)) # For mental ray
except:
pass
tbl = [“TurtleRenderOptions”,“TurtleUIOptions”,“TurtleBakeLayerManager”,“TurtleDefaultBakeLayer”]
# Del nodes
self.cont += self.delNodes(cams) # del cameras
self.cont += self.delNodes(lits) # del lights
self.cont += self.delNodes(nodes) # del other nodes
self.delNodes(tbl)
try:
mm.eval(‘MLdeleteUnused’) # del shaders
except:
self.cont += ‘Unused Shader Node\n’
# Result
list = u’清理列表:\n’
list += ‘camera\nlight\ndisplayLayer\nrenderLayer\nmentalraySubdivApprox\nUnused Shader Node\n’
list += ‘\n’
if self.cont==’’:
self.cont = list + u’已完全清理!’
return 1
else:
self.cont = list + u’下列节点清理失败,可能是参考灯光,手动清理:\n’ + self.cont
return 0
def delNodes(self,nodes):
defaultNodes = [‘top’,‘side’,‘front’,‘persp’,‘defaultLayer’,‘defaultRenderLayer’,‘defaultObjectSet’]
act = ‘’
for node in nodes:
if node not in defaultNodes:
try:
delete( node )
except:
act = node + ‘\n’
return act
class cheakHypershade(cbb.checkingBoxCmd):
label = u’清理材质编辑器无用节点’
def cmd(self):
mm.eval(‘hyperShadePanelMenuCommand(“hyperShadePanel1”, “deleteUnusedNodes”);’)
self.cont = u’清理完成。’
return 1
class nameShapes(cbb.checkingBoxCmd):
label = u’shape名称与transform名称一致’
def cmd(self):
self.cont = ‘’
do = ‘’
notdo = ‘’
nodes = ls(type=‘transform’)
for node in nodes:
shapes = listRelatives(node,s=1,f=1,type=(‘mesh’,‘nurbsSurface’))
if shapes!=None:
shape = shapes[0]
name = node.rsplit(’|’,1)[-1] + ‘Shape’
if not shape.endswith(name):
try:
rename(shape,name)
do += ‘%s %s\n’%(shape,name)
except:
notdo += ‘%s\n’%shape
if not do==’’:
self.cont += u’重命名物体:\n’
self.cont += do
if not notdo==’’:
self.cont += u’重命名失败:\n’
self.cont += notdo
if self.cont==’’:
self.cont += u’所有shape名称都与transform名称一致!’
return 1
elif notdo==’’:
return 1
else:
return 0
class clearRedundantShapes(cbb.checkingBoxCmd):
label = u’清除多余的shape节点’
def cmd(self):
count = 0
nodes = ls(type=‘transform’)
for node in nodes:
shapes = listRelatives(node,s=1,f=1,ni=1)
if shapes!=None and len(shapes)>1:
shapes.pop(0)
delete(shapes)
count += 1
self.cont = u’处理多余的shape节点: %s\n\n’%count
self.cont += u’注:\n不处理中介节点’
return 1
class delHistory(cbb.checkingBoxCmd):
label = u’删除历史’
def cmd(self):
self.cont = self.zeroSmooth()
self.cont += self.unlockNormal()
self.cont += self.delHistory()
if self.cont==’’:
self.cont = u’场景中无模型物体!!!’
return 1
def delHistory(self):
cont = ‘’
nodes = ls(type=(‘mesh’,‘nurbsSurface’))
if nodes!=[]:
delete(nodes,ch=1)
cont = u’删除历史:%s\n’%len(nodes)
return cont
def unlockNormal(self):
cont = ‘’
nodes = ls(type=(‘mesh’,‘nurbsSurface’))
if nodes!=[]:
polyNormalPerVertex(nodes, ufn=1)
cont = u’Unlock Normal 节点: %s\n’%len(nodes)
return cont
def zeroSmooth(self):
cont = ‘’
nodes = ls(type=‘polySmoothFace’)
for node in nodes:
setAttr((node+’.divisions’),0)
if nodes!=[]:
cont = u’处理smooth节点: %s\n’%len(nodes)
return cont
class checkAxis(cbb.checkingBoxCmd):
label = u’轴心点回物体中心,位移旋转缩放属性设为默认值’
def cmd(self):
error = ‘’
objs = ls(type=(‘mesh’,‘nurbsSurface’))
for obj in objs:
p = listRelatives(obj,p=1,f=1)[0]
xform(p,cp=1)
try:
makeIdentity(p,a=1,t=1,r=1,s=1,n=0)
except:
error += ‘%s\n’%p
if error!=’’:
self.cont = u’以下物体处理失败:\n’
self.cont += error
self.cont += u’物体属性被锁定或者被连接,\n请手动检查…’
return 0.5
self.cont = u’处理物体: %s\n’%len(objs)
return 1
class texFileCheck(cbb.checkingBoxCmd):
label = u’检查贴图路径’
def cmd(self):
selFile = ls(type=‘file’)
l = []
self.a = []
for sf in selFile:
texFilePath = getAttr("%s.fileTextureName"%sf).split(’/’)[0]
if texFilePath != ‘X:’:
self.a.append(sf)
l.append(texFilePath)
l = set(l)
l = list(l)
if len(l) == 1:
if l[0] == ‘X:’:
self.cont = u"贴图路径全部指认X盘"
return 1
else:
self.showInfo()
return 0
elif len(l) == 0:
self.cont = u"没有指认任何贴图"
return 0.5
else:
self.showInfo()
self.cont += u"检查并修改"
return 0
def showInfo(self):
cbb.checkingBoxCmd.showInfo(self)
setParent(self.infoUI)
columnLayout(adj=1)
iconTextButton(l=u"不是X盘路径的贴图路径来源于:",h=18,style=‘iconAndTextHorizontal’,bgc=[0.8,0.8,0.8])
# setParent(’…’)
# setParent(’…’)
for obj in self.a:
columnLayout(adj=1)
#iconTextButton(l=u"有K帧的物体名:",h=18,style=‘iconAndTextHorizontal’,bgc=[0.8,0.8,0.8])
columnLayout(adj=1,co=(‘left’,20))
iconTextButton(l=obj,h=18,style=‘iconAndTextHorizontal’,
c=‘from maya.cmds import *;select("%s")’%obj)
setParent(’…’)
setParent(’…’)

class checkFaceShade(cbb.checkingBoxCmd):
label = u’检查面材质,或模型有无材质’
def cmd(self):
self.l = []
try:
a = ls(type=(‘mesh’,‘nurbsSurface’))
g = pickWalk(a,d=“up”)
select(cl=True)
l = []
for i in g:
getSGs = listConnections(listRelatives(i, shapes=1, f=1)[0], destination=1, source=0, plugs=0, s=1, type=“shadingEngine”)
print getSGs
if len(getSGs) == 1:
pass
else:
self.l.append(i)
for ig in getSGs:
if ig == ‘initialShadingGroup’:
self.l.append(i)

        if len(self.l) == 0:
            self.cont = u"模型材质材质正确且无面材质。"
            return 1
        else:
            self.showInfo()
            return 0.5
    except:
        self.cont = u"错误。"
        return 0

def showInfo(self):
    cbb.checkingBoxCmd.showInfo(self)
    setParent(self.infoUI)
    columnLayout(adj=1)
    iconTextButton(l=u"有面材质的或lamber1材质物体名:",h=18,style='iconAndTextHorizontal',bgc=[0.8,0.8,0.8])
    # setParent('..')
    # setParent('..')
    for obj in self.l:
        columnLayout(adj=1)
        #iconTextButton(l=u"有K帧的物体名:",h=18,style='iconAndTextHorizontal',bgc=[0.8,0.8,0.8])
        columnLayout(adj=1,co=('left',20))
        iconTextButton(l=obj,h=18,style='iconAndTextHorizontal',
                       c='from maya.cmds import *;select("%s")'%obj)
        setParent('..')
        setParent('..')

Main ------------------

def checkRig():
obj = checkingBoxUI(‘checkRig’)
obj.build()
obj.show()

猜你喜欢

转载自blog.csdn.net/Acce_vic/article/details/88931816