def changeValue(attr, slider, *args):
value = cmds.floatSliderGrp(slider, q=True, v=True)
cmds.setAttr(attr, value)
# def focusToCamera():
#get camera from focus window
# panel = cmds.getPanel(wf=True)
# cam = cmds.modelEditor(panel, q=True, camera=True)
#----------get camera from focus . . .
#----------have camera list to select from . . .
# (coverageX)
# (coverageY)
python类getPanel()的实例源码
def __enter__(self):
if MAYA_VERSION >= 2016.5:
if not mc.ogs(query=True, pause=True):
mc.ogs(pause=True)
else:
self.sel = mc.ls(sl=True)
self.modelPanels = mc.getPanel(type='modelPanel')
#unfortunately there's no good way to know what's been isolated, so in this case if a view is isolated, skip it.
self.skip = list()
for each in self.modelPanels:
if mc.isolateSelect(each, query=True, state=True):
self.skip.append(each)
self.isolate(True)
mc.select(clear=True)
self.resetAutoKey = mc.autoKeyframe(query=True, state=True)
mc.autoKeyframe(state=False)
def getOutliners():
return [toQtObject(i) for i in cmds.getPanel(typ="outlinerPanel")]
def getCurrentCamera():
'''
Returns the camera that you're currently looking through.
If the current highlighted panel isn't a modelPanel,
'''
panel = mc.getPanel(withFocus=True)
if mc.getPanel(typeOf=panel) != 'modelPanel':
#just get the first visible model panel we find, hopefully the correct one.
for p in mc.getPanel(visiblePanels=True):
if mc.getPanel(typeOf=p) == 'modelPanel':
panel = p
mc.setFocus(panel)
break
if mc.getPanel(typeOf=panel) != 'modelPanel':
OpenMaya.MGlobal.displayWarning('Please highlight a camera viewport.')
return False
camShape = mc.modelEditor(panel, query=True, camera=True)
if not camShape:
return False
camNodeType = mc.nodeType(camShape)
if mc.nodeType(camShape) == 'transform':
return camShape
elif mc.nodeType(camShape) in ['camera','stereoRigCamera']:
return mc.listRelatives(camShape, parent=True, path=True)[0]
def visibleInGraphEditor(self):
'''
Initializes the keySelection object with curves visibile in graph editor.
Returns True if successful.
'''
if not 'graphEditor1' in mc.getPanel(visiblePanels=True):
return False
graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)
if not graphVis:
return False
for each in graphVis:
try:
self._curves.extend(mc.keyframe(each, query=True, name=True))
except StandardError:
pass
if not self._curves:
return False
return True
def get_current_camera():
"""Returns the currently active camera.
Searched in the order of:
1. Active Panel
2. Selected Camera Shape
3. Selected Camera Transform
Returns:
str: name of active camera transform
"""
# Get camera from active modelPanel (if any)
panel = cmds.getPanel(withFocus=True)
if cmds.getPanel(typeOf=panel) == "modelPanel":
cam = cmds.modelEditor(panel, query=True, camera=True)
# In some cases above returns the shape, but most often it returns the
# transform. Still we need to make sure we return the transform.
if cam:
if cmds.nodeType(cam) == "transform":
return cam
# camera shape is a shape type
elif cmds.objectType(cam, isAType="shape"):
parent = cmds.listRelatives(cam, parent=True, fullPath=True)
if parent:
return parent[0]
# Check if a camShape is selected (if so use that)
cam_shapes = cmds.ls(selection=True, type="camera")
if cam_shapes:
return cmds.listRelatives(cam_shapes,
parent=True,
fullPath=True)[0]
# Check if a transform of a camShape is selected
# (return cam transform if any)
transforms = cmds.ls(selection=True, type="transform")
if transforms:
cam_shapes = cmds.listRelatives(transforms, shapes=True, type="camera")
if cam_shapes:
return cmds.listRelatives(cam_shapes,
parent=True,
fullPath=True)[0]
def frameGraphEditor(centerCurrentTime=False):
'''
If graph editor has focus, frame the selected or visible animation curves.
'''
panel = mc.getPanel(up=True)
if not panel:
panel = mc.getPanel(withFocus=True)
if not panel:
return False
panelType = mc.getPanel(to=panel)
if panelType != 'scriptedPanel':
return False
scriptedType = mc.scriptedPanel(panel, query=True, type=True)
if scriptedType != 'graphEditor':
return False
graphEditor = panel+'GraphEd'
keySel = utl.KeySelection()
if keySel.selectedKeys():
pass
elif keySel.visibleInGraphEditor():
pass
if keySel.selected:
times = keySel.getSortedKeyTimes()
start = times[0]
end = times[-1]
else:
keySel.frameRange()
start = keySel._timeRangeStart
end = keySel._timeRangeEnd
values = sorted(keySel.keyframe(query=True, valueChange=True))
minValue = values[0]
maxValue = values[-1]
if start == end:
start = start-1
end = end+1
if maxValue == minValue:
minValue = minValue-0.5
maxValue = maxValue+0.5
#add a 10% padding
timePadding = (end-start)/10.0
valuePadding = (maxValue-minValue)/10.0
mc.animView(graphEditor, startTime=start-timePadding, endTime=end+timePadding, minValue=minValue-valuePadding, maxValue=maxValue+valuePadding)
if centerCurrentTime:
mc.animCurveEditor(graphEditor, edit=True, lookAt='currentTime')
return True