第一种: import maya.OpenMaya as OpenMaya import maya.OpenMayaUI as OpenMayaUI
def _get_camera_name(): '''获取当前相机名 ''' view = OpenMayaUI.M3dView.active3dView() camDag = OpenMaya.MDagPath() view.getCamera(camDag) camera = camDag.fullPathName() name= cmds.listRelatives(camera, parent = True)[0]
return name