mayaTD第四周练习

批量reference练习

import maya.cmds as mc
import os, re
    
def reference_files(rf_filepath):    
    path_ns = re.sub('_Rig|_LGH|_GEO|_SFC'+'_v\d{3}', '', os.path.basename(rf_filepath)) 
    mc.file(rf_filepath, r=True, ns=path_ns)

def select_file():
    current_snpath = os.path.dirname(mc.file(sn=True,q=True))
    file_type = '''Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;
                FBX (*.fbx);;obj (*.obj);;abc (*.abc);;All Files (*.*)'''
    rf_filepath = mc.fileDialog2(startingDirectory = current_snpath,
                                 ff=file_type,cap='mti-reference',
                                 fm=4,okc='reference')
    return rf_filepath if rf_filepath else []
                                             
if __name__ == '__main__':      
    map(reference_files,select_file())

maya创建物体窗口练习

import maya.cmds as mc

def create_windows():
    global slider
    
    wnd_name = 'custom_poly'
    if mc.window(wnd_name,q=True,exists=True):
        mc.deleteUI(wnd_name,wnd=True)
        
    if mc.windowPref(wnd_name,q=True,exists=True):
        mc.windowPref(wnd_name,r=True)
    
    wnd = mc.window(wnd_name, t= wnd_name.title())    
    mc.rowLayout(numberOfColumns=4, columnWidth3=(80, 75, 150), 
                 adjustableColumn=2, columnAlign=(1, 'right'), 
                 columnAttach=[(1, 'both', 0), (2, 'both', 0), 
                 (3, 'both', 0)] )
    mc.shelfButton(annotation='Create a polySphere', image1='polySphere.png', 
                   c='mc.polySphere(r=mc.floatSliderGrp(slider, q=True, v=True))',
                   rpt=True)
    slider = mc.floatSliderGrp(label='Scale', field=True, fieldMinValue=0.01, 
                               fieldMaxValue=1000.0, value=1 )
    
    mc.showWindow()
    
if __name__ == '__main__':
    create_windows()

maya设置指定相机仅拍屏polygons

import maya.cmds as mc
    
def cam_playblast(cam='Cam_Palyblast1'):
    current_panel =mc.getPanel(withFocus=True)   
    if not mc.ls(cam):
        mc.camera(n= cam)

    mc.modelPanel(current_panel, e=True, cam=cam)
    mc.modelEditor(current_panel, e=True, alo = False)
    mc.modelEditor(current_panel, e=True, polymeshes = True)  
    return  mc.playblast(fmt='avi', f="Test_Movie.avi", qlt=100, p=100, fp=4)

if __name__ == '__main__':
    cam='Cam_Palyblast1'
    cam_playblast(cam)

你可能感兴趣的:(mayaTD第四周练习)