本文整理汇总了Python中maya.cmds.referenceQuery函数的典型用法代码示例。如果您正苦于以下问题:Python referenceQuery函数的具体用法?Python referenceQuery怎么用?Python referenceQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了referenceQuery函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_invalid
def get_invalid(instance):
"""Return invalid reference nodes in the instance
Terminology:
reference node: The node that is the actual reference containing
the nodes (type: reference)
referenced nodes: The nodes contained within the reference
(type: any type of nodes)
"""
referenced_nodes = cmds.ls(instance, referencedNodes=True, long=True)
if not referenced_nodes:
return list()
# Get reference nodes from referenced nodes
# (note that reference_nodes != referenced_nodes)
reference_nodes = set()
for node in referenced_nodes:
reference_node = cmds.referenceQuery(node, referenceNode=True)
if reference_node:
reference_nodes.add(reference_node)
# Check for failed edits on each reference node.
invalid = []
for reference_node in reference_nodes:
failed_edits = cmds.referenceQuery(reference_node,
editNodes=True,
failedEdits=True,
successfulEdits=False)
if failed_edits:
invalid.append(reference_node)
return invalid
示例2: doNameObject
def doNameObject(obj,sceneUnique = False,fastIterate = True):
"""
Names an object
ARGUMENTS:
obj(string) - the object we'd like to name
sceneUnique(bool)- whether to do a full scene check or just the faster check
RETURNS:
newName(string) on success
"""
### input check
assert mc.objExists(obj) is True, "'%s' doesn't exist" %obj
assert mc.referenceQuery(obj, isNodeReferenced=True) is not True, "'%s' is referenced, can't name!" %obj
name = returnUniqueGeneratedName(obj,sceneUnique, fastIterate)
nameFactory = NameFactory(obj)
if nameFactory.amIMe(name):
guiFactory.warning("'%s' is already named correctly."%nameFactory.nameBase)
return name
else:
objLong = mc.ls(obj,long=True)
renameBuffer = mc.rename(objLong,name)
shapes = mc.listRelatives(renameBuffer,shapes=True,fullPath=True)
if shapes:
for shape in shapes:
if not mc.referenceQuery(shape, isNodeReferenced=True):
name = returnUniqueGeneratedName(shape,sceneUnique, fastIterate)
mc.rename(shape,name)
return renameBuffer
示例3: exportShaders
def exportShaders(self):
"""export custom shaders from scene, ex: shaders for masks etc..."""
lays = rlayer.renderlayers()
finalExport = []
for l in lays:
if l.name == 'defaultRenderLayer':
continue
if l.overridedShader:
finalExport.append( l.overridedShader )
else:
if l.overridesWithConnections[1]:
finalExport.extend( l.overridesWithConnections[1] )
if finalExport:
shadersToExport = []
for i in finalExport:
if mc.referenceQuery( i, inr = True ) or i in shadersToExport: #is a referenced node
continue
if mc.referenceQuery( i.a.surfaceShader.input, inr = True ): #check if shader is a reference
continue
if i.a.displacementShader.input:
if mc.referenceQuery( i.a.displacementShader.input, inr = True ): #check if displacement is a reference
continue
shadersToExport.append( i )
mc.select( shadersToExport, r = 1, ne = 1 )
mc.file( self.shaderPath.path, op = "v=0", typ = "mayaAscii", pr = 1, es = 1 )
示例4: deformCharacterShapeSel
def deformCharacterShapeSel(self, value):
RN = mc.referenceQuery(self.core.skCharacter[int(value)-1], referenceNode=1)
Nodes = mc.referenceQuery(RN, nodes=1)
self.characterdeformShape = []
self.allCharacterRightdeformShape = []
for item in Nodes:
if self.nodeTypeSelf(item) in self.shapeType:
self.characterdeformShape.append(item)
for each in self.characterdeformShape:
itemP = mc.listRelatives(each, p=1)[0]
itemPP = mc.listRelatives(itemP, p=1)
if itemPP != None and mc.getAttr('%s.v'%itemP) != 0 and mc.getAttr('%s.v'%itemPP[0]) != 0:
self.allCharacterRightdeformShape.append(each)
self.allCharacterRightdeformShape.reverse()
for item in self.allCharacterRightdeformShape:
if mc.filterExpand( item, sm=(10,12)) == None:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
return self.allCharacterRightdeformShape
示例5: defineAsset
def defineAsset(self):
self.assetType, self.topGrp, self.astRes = None, None, None
self.refObjs = []
if not mc.referenceQuery(self.refNode,il=1):
utils.msgWin("Warning", "Reference not loaded for %s"%self.refNode, self.silent)
self.refLoaded = False
else:
self.refLoaded = True
self.assetPath = mc.referenceQuery(self.refNode, f = True, wcn = True)
self.assetPathCopyNum = mc.referenceQuery(self.refNode, f = True, wcn = False)
self.namespace = mc.file(self.assetPathCopyNum, q = 1, ns = 1)
if "/char/" in self.assetPath: self.assetType = "char"
if "/prop/" in self.assetPath: self.assetType = "prop"
if "/sets/" in self.assetPath: self.assetType = "sets"
if not self.assetType:
utils.msgWin("Error", "Error identifying asset type from asset path for %s"%self.refNode, self.silent)
self.validAsset = False
if self.refLoaded:
self.refObjs = mc.referenceQuery(self.refNode,n=1)
if not self.refObjs:
utils.msgWin("Error", "Couldn't find any referenced objects", self.silent)
self.validAsset = False
self.topGrp = self.refObjs[0]
if self.assetType == "prop":
topGrpAttrs = mc.listAttr(self.topGrp,ud=1)
if topGrpAttrs:
if ('Elements' in topGrpAttrs):
self.assetType = 'elms'
self.astRes = str(utils.findObjRes(self.topGrp))
示例6: cleanupReference
def cleanupReference( rfn ):
#Get reference node.
if cmds.nodeType( rfn ) == "reference":
rfn = rfn
elif os.path.isfile( rfn ):
rfn = cmds.referenceQuery( rfn, rfn=True )
else:
print "%s is not reference" % rfn
return None
references = []
pm = cmds.listConnections( rfn, type="proxyManager" )
if pm:
references = cmds.listConnections( "%s.proxyList" % pm[0], type="reference" )
if not references:
references = [ rfn ]
m_words = "|".join( references )
else:
references = [ rfn ]
m_words = rfn
edits = []
if references:
for i in range( 0, len( references )):
strings = cmds.referenceQuery( references[i], failedEdits=True, successfulEdits=True, editStrings=True )
if strings:
for i in range( 0, len( strings )):
if strings[i] not in edits:
if not re.findall( m_words, strings[i] ):
edits.append( strings[i] )
if edits:
removeEdits( rfn, edits )
示例7: _removeNativeModels
def _removeNativeModels(self, models):
""" Deletes provided native models.
:param models: list of native models
:return: <bool> success
"""
ret = True
for model in models:
nameInfo = cross3d.SceneWrapper._namespace(model)
fullName = cross3d.SceneWrapper._mObjName(model)
if cmds.referenceQuery(fullName, isNodeReferenced=True):
# The model is referenced and we need to unload it.
refNode = cmds.referenceQuery(fullName, referenceNode=True)
filename = cmds.referenceQuery(refNode, filename=True)
# If all nodes in the namespace are referenced, the namespace will be removed, otherwise
# the namespace will still exist and contain all of those unreferenced nodes.
cmds.file(filename, removeReference=True)
# Remove nodes that were parented to referneced nodes
leftovers = self.objects(wildcard='{refNode}fosterParent*'.format(refNode=refNode))
if leftovers:
self.removeObjects(leftovers)
# Local node processing: check for unreferenced items in the namespace and remove them.
namespace = nameInfo['namespace']
if cmds.namespace(exists=namespace):
cmds.namespace(removeNamespace=namespace, deleteNamespaceContent=True)
if cmds.namespace(exists=namespace):
print 'The namespace {ns} still exists the model {model} was not entirely removed.'.format(namespace, model=fullName)
ret = False
return ret
示例8: addReferences
def addReferences():
cmds.select("dsMetaData")
shotList = cmds.ls(type = "shot")
refList = cmds.ls(rf=True)
for shot in shotList:
""" skips namespaces"""
if re.search(":",shot):
sSplit = shot.split(":")
shot = sSplit[-1]
for ref in refList:
if cmds.referenceQuery(ref,n=True,dp=True) != None:
refNs = cmds.referenceQuery(ref,ns=True,shn=True)
refN = cmds.referenceQuery(ref,f=True,shn=True)
print refNs
print refN
if not cmds.objExists("dsMetaData." + str(shot) + "_" + refNs):
cmds.addAttr(ln= str(shot) + "_" + refNs, at="message", h=False,r=True)
cmds.addAttr(ln= str(shot) + "_" + refNs + "_viz", at='bool', h=False,r=True)
cmds.addAttr(ln= str(shot) + "_" + refNs + "_assetID",at="long",h=False,r=True)
cmds.addAttr(ln= str(shot) + "_" + refNs + "_version",dt="string",h=False,r=True)
connectReferences(str(shot)+ "_" + refNs,refNs,refN)
示例9: _modifiedAttrs
def _modifiedAttrs(self):
""" Returns a dictionary of modifications made to this referenced model.
For referneced models return info describing the modifications made by the referencing
system.
"""
modified = {}
if self.isReferenced():
fullName = self.path()
refNode = cmds.referenceQuery(fullName, referenceNode=True)
# Build the setAttr pattern
pattern = r'setAttr {node}.(?P<attr>[^ ]+)'.format(node = fullName.replace('|', r'\|'))
setAttrRegex = re.compile(pattern)
# TODO: Add patterns for other mel commands like addAttr, etc
for s in cmds.referenceQuery(refNode, editStrings=True):
# Process setAttr
match = setAttrRegex.match(s)
if match:
key = match.groupdict()['attr']
if s.endswith('"'):
# Found a string. Note, this does not include escaped quotes.
openingQuote = s[::-1].find('"', 1)
value = s[-openingQuote:-1]
else:
# its not a string
value = s.split(' ')[-1]
modified.setdefault(key, {}).setdefault('setAttr', {}).update(value=value, command=s)
return modified
示例10: listReferenceEdits
def listReferenceEdits( rfn ):
"""
List all edits for current reference node.
"""
result = []
successfull = []
if cmds.nodeType( rfn ) == "reference":
rfn = rfn
else:
rfn = cmds.referenceQuery( rfn, rfn=True )
edits = cmds.referenceQuery( rfn, failedEdits=True, successfulEdits=True, editStrings=True )
if edits:
edits = [ "".join( [ m_part for m_part in re.split( "\|:[A-z0-9:]+", edits[i] ) if m_part != "" ] ) for i in range( 0, len( edits )) ]
m_content = cmds.ls( cmds.referenceQuery( rfn, nodes=True, dagPath=True ), long=True )
for c in range( 0, len( m_content )):
m_levels = listReferenceLevels( m_content[c] )
for l in range( 0, len( m_levels )):
m_expr = re.compile( "(\A|\s|\||\")+([A-z0-9_|]+|){0}(\Z|\s|\$|\"|\.)+".format( "(\||)".join( m_levels[l][0].split( "|" ))))
for e in range( 0, len( edits )):
if edits[e] not in successfull:
if m_expr.findall( edits[e] ):
m_temp = [ rfn, m_content[c], m_levels[l][-1], m_levels[l][0], edits[e].split( " " )[0], edits[e] ]
result.append( m_temp )
successfull.append( edits[e] )
for e in range( 0, len( edits )):
if edits[e] not in successfull:
m_temp = [ rfn, "unknown", "unknown", "unknown", edits[e].split( " " )[0], edits[e] ]
result.append( m_temp )
return result
示例11: getAssetSelection
def getAssetSelection(self):
objs = mc.ls(sl=True)
assets = []
namespaces = []
if objs:
for obj in objs:
if mc.referenceQuery(obj, inr=True):
path = mc.referenceQuery(obj, f=True)
asset = entityInfo.info(path)
if not asset.name() in assets:
assets.append(asset.name())
else:
namespace = obj.split(':')[0]
if not namespace in namespaces:
namespaces.append(namespace)
for namespace in namespaces:
attr = '%s:Geo_Grp.assetName' % namespace
if mc.objExists(attr):
assetName = mc.getAttr(attr)
if not assetName in assets:
assets.append(assetName)
return assets
示例12: dupReferenceForSelectedObjects
def dupReferenceForSelectedObjects():
"""
Duplicate reference of the selected objects, only one time, and copy their edits
"""
allreadyDup = []
for a in mc.ls( sl = True ):
ap = mc.referenceQuery( a, referenceNode=True, topReference=True )
if any( ap == r for r in allreadyDup ):
print 'skipping',a
continue
allreadyDup.append( ap )
edits = mc.referenceQuery( ap , editStrings = True )
mc.select( a )
try:
mm.eval( 'duplicateReference 0 ""' )
except:
print 'maya de mierda'
baseOldName = edits[0][edits[0].find( '|' )+1:edits[0].find( ':' )]
baseNewName = mc.ls( sl = True )[0].split( ':' )[0]
for e in edits:
print '"""""""'
print e
print baseOldName,baseNewName
try:
mm.eval( e.replace( baseOldName, baseNewName, 1 ) )
except:
continue
示例13: clearHeadPart
def clearHeadPart(self, *args):
#find the current character
try:
character = cmds.optionMenu(self.widgets["characterList"], q = True, v = True)
except:
cmds.warning("No valid character selected")
#find any body part references
refs = cmds.ls(type = "reference")
headPartRefs = []
for ref in refs:
namespace = cmds.referenceQuery(ref, namespace = True)
if namespace.find("_headPart") != -1:
headPartRefs.append([ref, namespace])
#find out which, if any, are tied to this character and remove
for ref in headPartRefs:
joint = ref[1] + ":root"
constraint = cmds.listConnections(joint, type = "parentConstraint")[0]
target = cmds.listConnections(constraint + ".target")[0].partition(":")[0]
if target == character:
filename = cmds.referenceQuery(ref[0], filename = True)
cmds.file(filename, rr = True)
#unhide the original geometry
if cmds.objExists(character + ":Geo_Layer"):
cmds.setAttr(character + ":Geo_Layer.v", 1)
示例14: unloadReference
def unloadReference( rfn ):
#Get reference node.
result = []
if cmds.nodeType( rfn ) == "reference":
rfn = rfn
elif os.path.isfile( rfn ):
rfn = cmds.referenceQuery( rfn, rfn=True )
else:
print "%s is not reference" % rfn
return None
relatives = referenceRelatives( rfn, onlyLoaded=True, parents=False )
if cmds.referenceQuery( rfn, isLoaded=True ):
if relatives:
for i in range( len( relatives )-1, -1, -1 ):
parent = cmds.referenceQuery( relatives[i], parent=True, filename=True )
parent = parent and parent or "untitled"
pm = cmds.listConnections( relatives[i], type="proxyManager" )
if pm:
mcache = cmds.listConnections( "%s.proxyList" % pm[0], type="reference" )
else:
mcache = [ relatives[i] ]
for n in range( 0, len( mcache )):
if mcache[n] not in result:
result.append( mcache[n] )
pcache = cmds.referenceQuery( mcache[n], parent=True, filename=True )
pcache = pcache and pcache or "untitled"
if parent != pcache:
print "//Warning:\n//\treference is not valid:\n//\t{0} has parent {1}\n//\t{2} has parent {3}\n//\tplease check reference nodes connections.\n".format( relatives[i], parent, mcache[n], pcache )
if cmds.referenceQuery( mcache[n], isLoaded=True ):
print "unload reference: %s" % mcache[n]
cmds.file( unloadReference=mcache[n] )
return result
示例15: fixNode
def fixNode(self, nodeToFix, invert=False):
print ("\n" + nodeToFix)
# gets all attributes that need to be fixed
attrs = cmds.listAttr(nodeToFix, st=["hubElement"])
for attr in attrs:
print ("Found Attribute -> '" + attr + "'")
# check if the attribute is empty and if yes, fixs it
val = cmds.getAttr(nodeToFix + "." + attr)
condition = (not val or val != "neverBirdA")
if invert: condition = (val == "neverBirdA")
if condition:
msg = ("Attribute '" + attr + "' is empty or incorrect.")
if invert: msg = ("Attribute '" + attr + "' is OK.")
print msg
# if the attribute is locked, unlocks it first
isLocked = cmds.getAttr((nodeToFix + "." + attr), lock=True)
if isLocked:
print ("Attribute '" + attr + "' is locked. Unlocking it.")
isReferenced = cmds.referenceQuery((nodeToFix + "." + attr), isNodeReferenced=True)
if isReferenced:
try:
cmds.setAttr((nodeToFix + "." + attr), lock=False)
except:
print ("Attribute '" + attr + "' could not be unlocked, it is referenced.")
else:
cmds.setAttr((nodeToFix + "." + attr), lock=False)
# if the attribute is now unlocked, fixes the value
isLocked = cmds.getAttr((nodeToFix + "." + attr), lock=True)
if not isLocked:
msg = ("Attribute '" + attr + "'. Setting value to 'neverBirdA'")
if invert: msg = ("Attribute '" + attr + "'. Setting value to 'empty string'.")
print msg
newVal = "neverBirdA"
if invert: newVal = ""
print (nodeToFix + "." + attr)
print (cmds.getAttr((nodeToFix + "." + attr), settable=True))
cmds.setAttr((nodeToFix + "." + attr), newVal, type="string")
isReferenced = cmds.referenceQuery((nodeToFix + "." + attr), isNodeReferenced=True)
if not isReferenced:
print ("Attribute '" + attr + "'. Locking again")
cmds.setAttr((nodeToFix + "." + attr), lock=True)
else:
print ("Attribute '" + attr + "'. Is referenced, unable to locl again.")
else:
print ("Attribute '" + attr + "' could not be unlocked.")
else:
msg = ("Attribute '" + attr + "' is OK -> '" + val + "'")
if invert: msg = ("Attribute '" + attr + "' is not OK.")
print msg