本文整理匯總了Python中maya.cmds.channelBox方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.channelBox方法的具體用法?Python cmds.channelBox怎麽用?Python cmds.channelBox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.channelBox方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getChannelBoxMenu
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def getChannelBoxMenu():
"""
Get ChannelBox, convert the main channel box to QT and return the QMenu
which is part of the channel box' children.
:return: Maya's main channel box menu
:rtype: QMenu
"""
channelBox = getChannelBox()
for child in channelBox.children():
if type(child) == QMenu:
cmd = "generateChannelMenu {0} 1".format(qtToMaya(child))
mel.eval(cmd)
return child
# ----------------------------------------------------------------------------
示例2: getSelectedChannels
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def getSelectedChannels():
'''
Return channels that are selected in the channelbox
'''
if not mc.ls(sl=True):
return
gChannelBoxName = mm.eval('$temp=$gChannelBoxName')
sma = mc.channelBox(gChannelBoxName, query=True, sma=True)
ssa = mc.channelBox(gChannelBoxName, query=True, ssa=True)
sha = mc.channelBox(gChannelBoxName, query=True, sha=True)
channels = list()
if sma:
channels.extend(sma)
if ssa:
channels.extend(ssa)
if sha:
channels.extend(sha)
return channels
示例3: _populateSelectionField
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def _populateSelectionField(self, channel, field, *args):
selectedChannels = None
if channel:
selectedChannels = getSelectedChannels()
if not selectedChannels:
raise RuntimeError('Please select an attribute in the channelBox.')
if len(selectedChannels) > 1:
raise RuntimeError('Please select only one attribute.')
sel = mc.ls(sl=True)
if not sel:
raise RuntimeError('Please select a node.')
if len(sel) > 1:
raise RuntimeError('Please select only one node.')
selection = sel[0]
if selectedChannels:
selection = selection+'.'+selectedChannels[0]
mc.textFieldButtonGrp(field, edit=True, text=selection)
示例4: _populateSelectionList
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def _populateSelectionList(self, channel, control, *args):
selectedChannels = None
if channel:
selectedChannels = getSelectedChannels()
if not selectedChannels:
raise RuntimeError('Please select an attribute in the channelBox.')
if len(selectedChannels) > 1:
raise RuntimeError('Please select only one attribute.')
sel = mc.ls(sl=True)
if not sel:
raise RuntimeError('Please select a node.')
if len(sel) > 1:
raise RuntimeError('Please select only one node.')
selection = sel[0]
if selectedChannels:
selection = selection+'.'+selectedChannels[0]
mc.textScrollList(control, edit=True, append=[selection])
示例5: setNonKeyable
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def setNonKeyable(self, objList, attrList, *args):
"""Set nonKeyable to attributes for objects in lists.
"""
if objList and attrList:
for obj in objList:
for attr in attrList:
if cmds.objExists(obj+"."+attr):
try:
# set lock and hide of given attributes:
cmds.setAttr(obj+"."+attr, keyable=False, channelBox=True)
except:
print "Error: Cannot set", obj, ".", attr, "as nonKeayble, sorry."
示例6: copyAttr
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def copyAttr(self, sourceItem=False, attrList=False, verbose=False, *args):
""" Get and store in a dictionary the attributes from sourceItem.
Returns the dictionary with attribute values.
"""
# getting sourceItem:
if not sourceItem:
selList = cmds.ls(selection=True, long=True)
if selList:
sourceItem = selList[0]
else:
print self.dpUIinst.langDic[self.dpUIinst.langName]["e015_selectToCopyAttr"]
if cmds.objExists(sourceItem):
if not attrList:
# getting channelBox selected attributes:
currentAttrList = cmds.channelBox('mainChannelBox', query=True, selectedMainAttributes=True)
if not currentAttrList:
# list all attributes if nothing is selected:
currentAttrList = cmds.listAttr(sourceItem, visible=True, keyable=True)
attrList = currentAttrList
if attrList:
# store attribute values in a dic:
self.attrValueDic = {}
for attr in attrList:
if cmds.objExists(sourceItem+'.'+attr):
value = cmds.getAttr(sourceItem+'.'+attr)
self.attrValueDic[attr] = value
if verbose:
print self.dpUIinst.langDic[self.dpUIinst.langName]["i125_copiedAttr"]
return self.attrValueDic
示例7: getChannelBox
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def getChannelBox():
"""
Get ChannelBox, convert the main channel box to QT.
:return: Maya's main channel box
:rtype: QWidget
"""
channelBox = mayaToQT(CHANNELBOX)
return channelBox
示例8: updateSearch
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def updateSearch(self, matchString, nodes):
"""
Loop over all keyable attributes and match them with the search string.
:param str matchString: Search string to match with attributes
:param list nodes: List of nodes to process the attributes from
"""
# reset of search string is empty
if not matchString:
cmds.channelBox(CHANNELBOX, edit=True, fixedAttrList=[])
return
# split match string
matches = []
matchStrings = matchString.lower().split()
# get matching attributes
for node in nodes:
attrs = cmds.listAttr(node, k=True, v=True)
for attr in attrs:
if (
not attr in matches and
self.matchSearch(attr, matchStrings)
):
matches.append(attr)
# append null if not matches are found ( cannot use empty list )
if not matches:
matches.append("null")
# filter channel box
cmds.channelBox(CHANNELBOX, edit=True, fixedAttrList=matches)
# ------------------------------------------------------------------------
示例9: install
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def install(threshold=0.75):
"""
Add the search interface and colouring functionality to Maya's main
channel box. If channelBoxPlus is already installed a RuntimeError
exception will be thrown. A threshold can be set, this threshold
determines when the attributes should change colour. the higher the
threshold the more the 2 attributes will have to match up to stay the same
colour.
:param float threshold: Threshold for attribute colour change
:raises RuntimeError: When the channel box plus is already installed.
"""
global CHANNELBOX_PLUS
# validate channel box plus
if CHANNELBOX_PLUS:
raise RuntimeError("Channel box plus is already installed!")
# get channel box
channelBox = getChannelBox()
# get channel box layout
parent = channelBox.parent()
layout = parent.layout()
layout.setSpacing(0)
# initialize search widget
CHANNELBOX_PLUS = SearchWidget(parent, threshold)
# add search widget to layout
if type(layout) == QLayout:
item = layout.itemAt(0)
widget = item.widget()
layout.removeWidget(widget)
layout.addWidget(CHANNELBOX_PLUS)
layout.addWidget(widget)
else:
layout.insertWidget(0, CHANNELBOX_PLUS)
示例10: main
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def main(selectedChannels=True, transformsOnly=False, excludeChannels=None):
'''
Resets selected channels in the channel box to default, or if nothing's
selected, resets all keyable channels to default.
'''
gChannelBoxName = mm.eval('$temp=$gChannelBoxName')
sel = mc.ls(sl=True)
if not sel:
return
if excludeChannels and not isinstance(excludeChannels, (list, tuple)):
excludeChannels = [excludeChannels]
chans = None
if selectedChannels:
chans = mc.channelBox(gChannelBoxName, query=True, sma=True)
testList = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ','scaleX','scaleY','scaleZ',
'tx','ty','yz','rx','ry','rz','sx','sy','sz']
for obj in sel:
attrs = chans
if not chans:
attrs = mc.listAttr(obj, keyable=True, unlocked=True)
if excludeChannels and attrs:
attrs = [x for x in attrs if x not in excludeChannels]
if transformsOnly:
attrs = [x for x in attrs if x in testList]
if attrs:
for attr in attrs:
try:
default = mc.attributeQuery(attr, listDefault=True, node=obj)[0]
mc.setAttr(obj+'.'+attr, default)
except StandardError:
pass
utl.deselectChannels()
示例11: deselectChannels
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def deselectChannels():
'''
Deselect selected channels in the channelBox
by clearing selection and then re-selecting
'''
if not getSelectedChannels():
return
sel = mc.ls(sl=True)
mc.select(clear=True)
mc.evalDeferred(partial(mc.select,sel))
示例12: on_add_btn_clicked
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import channelBox [as 別名]
def on_add_btn_clicked(self):
selNodes = cmds.ls(sl=1, ap=1)
if not selNodes:
om.MGlobal.displayError("Please select some nodes and attributes.")
return
selAttrs = (cmds.channelBox("mainChannelBox", q=1, sma=1) or []) \
+ (cmds.channelBox("mainChannelBox", q=1, sha=1) or []) \
+ (cmds.channelBox("mainChannelBox", q=1, ssa=1) or []) \
+ (cmds.channelBox("mainChannelBox", q=1, soa=1) or [])
if not selAttrs:
selAttrs = cmds.listAttr(selNodes, v=1, k=1, sn=1)
selAttrs = list(set(selAttrs))
try:
selAttrs.remove('v')
except:
pass
self.table.clearSelection()
for node in selNodes:
for attr in selAttrs:
name = "%s.%s" % (node, attr)
minVal, maxVal = 0.0, 1.0
hasMinVal, hasMaxVal = False, False
if not cmds.objExists(name):
continue
# Set minVal
if cmds.attributeQuery(attr, node=node, minExists=1):
minVal = cmds.attributeQuery(attr, node=node, min=1)[0]
hasMinVal = True
if cmds.attributeQuery(attr, node=node, softMinExists=1):
minVal = cmds.attributeQuery(attr, node=node, smn=1)[0]
hasMinVal = True
# Set maxVal
if cmds.attributeQuery(attr, node=node, maxExists=1):
maxVal = cmds.attributeQuery(attr, node=node, max=1)[0]
hasMaxVal = True
if cmds.attributeQuery(attr, node=node, softMaxExists=1):
maxVal = cmds.attributeQuery(attr, node=node, smx=1)[0]
hasMaxVal = True
currVal = cmds.getAttr(name)
if hasMinVal: minVal = minVal - currVal
if hasMaxVal: maxVal = maxVal - currVal
self.appendRow()
self.setRow(self.numRow()-1, [name, minVal, maxVal])
#----------------------------------------------------------------------