Python maya.cmds.attributeQuery() Examples
The following are 30
code examples of maya.cmds.attributeQuery().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: attribute.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def enumStringToValue(attr, lowercase=False): """ Creates a dictionary mapper for enum values. This util can be used to set enum attributes with string values. :param str attr: :param bool lowercase: :return: enumStringToValue :rtype: dict """ node, attr = tuple(attr.split(".", 1)) enumString = cmds.attributeQuery(attr, node=node, listEnum=True)[0] enumDict = {} for i, str in enumerate(enumString.split(":")): if lowercase: str = str.lower() enumDict[str] = i return enumDict
Example #2
Source File: uExport.py From uExport with zlib License | 6 votes |
def convertSkelSettingsToNN(delete=1): orig = 'SkeletonSettings_Cache' if cmds.objExists(orig): if cmds.nodeType(orig) == 'unknown': new = cmds.createNode('network') for att in cmds.listAttr(orig): if not cmds.attributeQuery(att, node=new, exists=1): typ = cmds.attributeQuery(att, node=orig, at=1) if typ == 'typed': cmds.addAttr(new, longName=att, dt='string') if cmds.getAttr(orig + '.' + att): cmds.setAttr(new + '.' + att, cmds.getAttr(orig + '.' + att), type='string') elif typ == 'enum': cmds.addAttr(new, longName=att, at='enum', enumName=cmds.attributeQuery(att, node=orig, listEnum=1)[0]) cmds.delete(orig) cmds.rename(new, 'SkeletonSettings_Cache')
Example #3
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def loadSelectedSet(self): selection = BT_GetSelectedSet() if not selection: return False if not cmds.attributeQuery('Blend_Node', ex = True, n = selection): cmds.warning('Blend_Node attribute not found! This set might not be connected to a BlendTransforms node yet.') return False self.ui.poseList.clear() self.ui.setEdit.setText(selection) poses = BT_GetPosesFromSet(selection) if not poses: return False self.ui.poseList.addItems(poses) return True
Example #4
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def loadSelectedSet(self): selection = BT_GetSelectedSet() if not selection: return False if not cmds.attributeQuery('Blend_Node', ex = True, n = selection): cmds.warning('Blend_Node attribute not found! This set might not be connected to a BlendTransforms node yet.') return False self.ui.poseList.clear() self.ui.setEdit.setText(selection) poses = BT_GetPosesFromSet(selection) if not poses: return False self.ui.poseList.addItems(poses) return True
Example #5
Source File: ml_puppet.py From ml_tools with MIT License | 6 votes |
def attributeMenuItem(node, attr): plug = node+'.'+attr niceName = mc.attributeName(plug, nice=True) #get attribute type attrType = mc.getAttr(plug, type=True) if attrType == 'enum': listEnum = mc.attributeQuery(attr, node=node, listEnum=True)[0] if not ':' in listEnum: return listEnum = listEnum.split(':') mc.menuItem(label=niceName, subMenu=True) for value, label in enumerate(listEnum): mc.menuItem(label=label, command=partial(mc.setAttr, plug, value)) mc.setParent('..', menu=True) elif attrType == 'bool': value = mc.getAttr(plug) label = 'Toggle '+ niceName mc.menuItem(label=label, command=partial(mc.setAttr, plug, not value))
Example #6
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def loadSelectedSet(self): selection = BT_GetSelectedSet() if not selection: return False if not cmds.attributeQuery('Blend_Node', ex = True, n = selection): cmds.warning('Blend_Node attribute not found! This set might not be connected to a BlendTransforms node yet.') return False self.ui.poseList.clear() self.ui.setEdit.setText(selection) poses = BT_GetPosesFromSet(selection) if not poses: return False self.ui.poseList.addItems(poses) return True
Example #7
Source File: ml_centerOfMass.py From ml_tools with MIT License | 6 votes |
def getRootAndCOM(node): ''' Given either the root or COM, return root and COM based on connections. ''' com = None root = None if mc.attributeQuery(COM_ATTR, node=node, exists=True): com = node messageCon = mc.listConnections(com+'.'+COM_ATTR, source=True, destination=False) if not messageCon: raise RuntimeError('Could not determine root from COM, please select root and run again.') root = messageCon[0] else: messageCon = mc.listConnections(node+'.message', source=False, destination=True, plugs=True) if messageCon: for each in messageCon: eachNode, attr = each.rsplit('.',1) if attr == COM_ATTR: com = eachNode root = node break return root, com
Example #8
Source File: ml_graphEditorMask.py From ml_tools with MIT License | 5 votes |
def channelBox(*args): shortNames = utl.getSelectedChannels() if not shortNames: return sel = mc.ls(sl=True) channels = [mc.attributeQuery(x, longName=True, node=sel[-1]) for x in shortNames] filterChannels(channels)
Example #9
Source File: uExport.py From uExport with zlib License | 5 votes |
def attrExists(attr): if '.' in attr: node, att = attr.split('.') return cmds.attributeQuery(att, node=node, ex=1) else: cmds.warning('attrExists: No attr passed in: ' + attr) return False
Example #10
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def selectedChannels(self): ''' Initializes the keySelection object with selected channels. Returns True if successful. ''' chanBoxChan = getSelectedChannels() if not chanBoxChan: return False #channels may be on shapes, include shapes in the list nodes = self.nodeSelection shapes = mc.listRelatives(self.nodeSelection, shapes=True, path=True) if shapes: nodes.extend(shapes) nodes = list(set(nodes)) for obj in nodes: for attr in chanBoxChan: if mc.attributeQuery(attr, node=obj, exists=True): self._channels.append('.'.join((obj,attr))) if not self._channels: return False return True
Example #11
Source File: assetImporter4.py From tutorials with MIT License | 5 votes |
def findImported(self): """ findImported() -> list of (str nodeName, Asset) Searches the scene for all assets that have been imported and returns a list of tuples. The first element of each tuple is the name of the top node of the item in the scene, and the second element is the Asset object. """ transforms = cmds.ls(type="transform", long=True) if not transforms: return [] results = [] for t in transforms: if not cmds.attributeQuery(self.ATTR_ASSET_NAME, node=t, exists=True): continue name = cmds.getAttr("%s.%s" % (t, self.ATTR_ASSET_NAME)) show = cmds.getAttr("%s.%s" % (t, self.ATTR_ASSET_SHOW)) self.show = show asset = self.list(name) if asset: asset = asset[0] else: asset = None results.append( (t, asset) ) return results
Example #12
Source File: assetImporter3.py From tutorials with MIT License | 5 votes |
def findImported(self): """ findImported() -> list of (str nodeName, Asset) Searches the scene for all assets that have been imported and returns a list of tuples. The first element of each tuple is the name of the top node of the item in the scene, and the second element is the Asset object. """ transforms = cmds.ls(type="transform", long=True) if not transforms: return [] results = [] for t in transforms: if not cmds.attributeQuery(self.ATTR_ASSET_NAME, node=t, exists=True): continue name = cmds.getAttr("%s.%s" % (t, self.ATTR_ASSET_NAME)) show = cmds.getAttr("%s.%s" % (t, self.ATTR_ASSET_SHOW)) self.show = show asset = self.list(name) if asset: asset = asset[0] else: asset = None results.append( (t, asset) ) return results
Example #13
Source File: dge.py From cmt with MIT License | 5 votes |
def attribute_type(a): tokens = a.split(".") node = tokens[0] attribute = tokens[-1] if attribute.startswith("worldMatrix"): # attributeQuery doesn't seem to work with worldMatrix return "matrix" return cmds.attributeQuery(attribute, node=node, at=True)
Example #14
Source File: __init__.py From maya2katana with GNU General Public License v3.0 | 5 votes |
def get_ramp_attr(node_name, attr): """ Translate the old attribute names if needed """ if cmds.attributeQuery("colorRamp", node=node_name, exists=True): new_ramp_attributes = { r"^colors\[(\d+)\]$": r"^colorRamp\[(\d+)\]\.colorRamp_Color$", "colors[{index}]": "colorRamp[{index}].colorRamp_Color", "{node}.colors[{index}]": "{node}.colorRamp[{index}].colorRamp_Color", "{node}.positions[{index}]": "{node}.colorRamp[{index}].colorRamp_Position", "{node}.positions": "{node}.colorRamp", } attr = new_ramp_attributes.get(attr, attr) return attr
Example #15
Source File: ml_pivot.py From ml_tools with MIT License | 5 votes |
def editPivot(self, *args): sel = mc.ls(sl=True) if not sel: om.MGlobal.displayWarning('Nothing selected.') return if len(sel) > 1: om.MGlobal.displayWarning('Only works on one node at a time.') return if mc.attributeQuery('ml_pivot_handle', exists=True, node=sel[0]): #we have a pivot handle selected return self.node = sel[0] if is_pivot_connected(sel[0]): driverAttr = pivot_driver_attr(sel[0]) if driverAttr: self.editPivotDriver(driverAttr) else: om.MGlobal.displayWarning('Pivot attribute is connected, unable to edit.') return self.editPivotHandle()
Example #16
Source File: ml_pivot.py From ml_tools with MIT License | 5 votes |
def editPivotDriver(self, driver): self.pivotDriver = driver #get driver range node,attr = driver.split('.',1) value = mc.getAttr(driver) minValue = mc.attributeQuery(attr, node=node, minimum=True)[0] maxValue = mc.attributeQuery(attr, node=node, maximum=True)[0] #create a ui with a slider self.pivotDriverWindow = 'ml_pivot_editPivotDriverUI' if mc.window(self.pivotDriverWindow, exists=True): mc.deleteUI(self.pivotDriverWindow) window = mc.window(self.pivotDriverWindow, width=1, height=1) mc.columnLayout() self.floatSlider = mc.floatSliderButtonGrp(label=attr, field=True, value=value, buttonLabel='Bake', minValue=minValue, maxValue=maxValue, buttonCommand=self.doEditPivotDriver ) mc.showWindow( window ) mc.window(self.pivotDriverWindow, edit=True, width=1, height=1)
Example #17
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def getMirrorAxis(node): axis = [] if mc.attributeQuery('mirrorAxis', exists=True, node=node): mirrorAxis = mc.getAttr('{}.mirrorAxis'.format(node)) if mirrorAxis and not hasFlippedParent(node): axis = mirrorAxis.split(',') return axis
Example #18
Source File: ml_resetChannels.py From ml_tools with MIT License | 5 votes |
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()
Example #19
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def getNodesOfTypeBelow(node, nodeType): nodes = [] allKids = mc.listRelatives(node, ad=True, pa=True) for kid in allKids: if mc.attributeQuery(PUP_ID_PREFIX+nodeType, exists=True, node=kid): nodes.append(kid) return nodes
Example #20
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def getTag(node, tag): ntAttr = PUP_ID_PREFIX+tag if mc.attributeQuery(ntAttr, exists=True, node=node): return mc.getAttr(node+'.'+ntAttr) return False
Example #21
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def getNodeType(node): if mc.attributeQuery('asset_type', node=node, exists=True): return mc.getAttr(node+'.asset_type', asString=True) return getTag(node, 'nodeType')
Example #22
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def showAllControls(puppet, *args): elements = mc.listRelatives(puppet, pa=True) for element in elements: for visAttr in ('geoVisibility','controlVisibility','secondaryControlVisibility'): if mc.attributeQuery(visAttr, exists=True, node=element): mc.setAttr(element+'.'+visAttr, 1)
Example #23
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def isNodePuppetControl(node): if mc.attributeQuery(PUP_ID_PREFIX+'control', exists=True, node=node): return True if getNodeType(node) == 'control': return True return False
Example #24
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def copyPose(fromNode, toNode, flip=False): attrs = mc.listAttr(fromNode, keyable=True) if not attrs: return #if attributes are aliased, get the real names for mirroring axis aliases = mc.aliasAttr(fromNode, query=True) if aliases: for alias,real in zip(aliases[::2],aliases[1::2]): if alias in attrs: attrs.remove(alias) attrs.append(real) axis = getMirrorAxis(toNode) for attr in attrs: if attr == 'mirrorAxis': continue if not mc.attributeQuery(attr, node=toNode, exists=True): continue fromPlug = '{}.{}'.format(fromNode, attr) toPlug = '{}.{}'.format(toNode, attr) fromValue = mc.getAttr(fromPlug) toValue = mc.getAttr(toPlug) if attr in axis: fromValue *= -1.0 toValue *= -1.0 try: utl.setAnimValue(toPlug, fromValue) except:pass if flip: try: utl.setAnimValue(fromPlug, toValue) except:pass
Example #25
Source File: mayasceneobject.py From cross3d with MIT License | 5 votes |
def _setNativeRotationOrder(cls, nativePointer, order): """ Sets the transform rotation order for the provided object to the provided value. Args: order: cross3d.constants.RotationOrder enum """ # Set the rotation order for the camera. tform = cls._mObjName(cls._asMOBject(nativePointer)) enumValues = cmds.attributeQuery('rotateOrder', node=tform, listEnum=True) if enumValues: enumValues = enumValues[0].split(':') rotName = RotationOrder.labelByValue(order) cmds.setAttr('{}.rotateOrder'.format(tform), enumValues.index(rotName.lower()))
Example #26
Source File: extract_formats.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 5 votes |
def disconnect(self, node, connectionType): import maya.cmds as cmds connections = [] for connection in node.connections(type=connectionType, plugs=True): src = connection dst = connection.connections( destination=True, source=False, plugs=True )[0] # Skip locked attributes if dst.get(lock=True): continue connections.append({"source": src, "destination": dst}) connection // dst # Reset attribute values = cmds.attributeQuery( dst.name(includeNode=False), node=node.name(), listDefault=True ) try: cmds.setAttr( node.name() + '.' + dst.name(includeNode=False), *values ) except: pass return connections
Example #27
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #28
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #29
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #30
Source File: bindings.py From mGui with MIT License | 5 votes |
def can_access(self, datum, field_name): try: return cmds.ls(datum) and cmds.attributeQuery(field_name, node=datum, w=True) except RuntimeError: return False except TypeError: return False