forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addFilepathMetadata
48 lines (34 loc) · 1.6 KB
/
addFilepathMetadata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def addFilePathMetaData():
# Adds metaData of saved name to the mayaFile metaData slot
nodeName = "defaultArnoldDriver.customAttributes"
filePath = cmds.file(q=1,sn=1)
mayaFile = {"type":"STRING","name":"mayaFile","value": filePath}
def addAttribute(nodeName, value):
#add an attribute
nextIndex = 0
if cmds.getAttr(nodeName, multiIndices= True):
nextIndex = cmds.getAttr(nodeName, multiIndices= True)[-1] + 1
cmds.setAttr(nodeName+'['+str(nextIndex)+']', "%s %s %s" % (value["type"],value["name"],value["value"]), type="string")
def changeAttribute(nodename, value):
for nodeNameIndex,i in enumerate(pymel.core.getAttr(nodeName)):
j= i.split(" ")
if len(j)>1:
if j[1] == 'mayaFile':
cmds.setAttr(nodeName+'['+str(nodeNameIndex)+']', "%s %s %s" % (value["type"],value["name"],value["value"]), type="string")
break
attributes=[]
for i in pymel.core.getAttr(nodeName):
j= i.split(" ")
if len(j)>1:
attributes.append( j[1])
if "mayaFile" in attributes:
metaDataAction = "mayaFile attribute existed, overwrote with new filename."
#change the attribute
changeAttribute(nodeName,mayaFile)
else:
#add an attribute
metaDataAction = "mayaFile attribute did not exist. Added it for you."
addAttribute(nodeName,mayaFile)
print "Added metaData"
#sys.stdout.write("metaData status: %s\n" %metaDataAction)
#end