Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. # Error: line 1: TypeError: file D:/Libraries/My Documents/maya/scriptstoolboxShapes.py line 332: an integer is required #
  2.  
  3. import maya.cmds as cmds
  4. import Attributor as attr #custom package to interact with nodes
  5. import maya.api.OpenMaya as om
  6. import maya.api.OpenMayaAnim as omAnim
  7.  
  8. class skinCluster(attr.node):
  9. outputGeometry = attr.connection("outputGeometry")
  10.  
  11. def getInfl_IDs(self,dagObj=False,pathFirst=False):
  12. infDags = self.skinFn.influenceObjects()
  13. infIds = {}
  14. for x in xrange(len(infDags)):
  15. infPath = attr.joint(nodeName=infDags[x].fullPathName()) if dagObj else infDags[x].fullPathName()
  16. infId = int(self.skinFn.indexForInfluenceObject(infDags[x]))
  17. if pathFirst:
  18. infIds[infPath] = infId
  19. else:
  20. infIds[infId] = infPath
  21. return dict(infIds)
  22. # Returns something like {0:"joint1",1:"joint2"}
  23. # useful for figuring out what list indexes to edit with weight tools
  24.  
  25. def __init__(self, nodeName=None, tracker=None, vertices=None, shapeNode=None):
  26. if not nodeName and vertices:
  27. nodeName = polygonShape(nodeName=vertices[0]).inMesh["in"][0]
  28. self.initialize(nodeName=nodeName, tracker=tracker)
  29. self.polygon = polygon(nodeName=self.outputGeometry["out"][0])
  30. self.shapeNode = shapeNode if shapeNode else polygonShape(nodeName=self.polygon.shapeNodes[0].path)
  31. self.skinFn = omAnim.MFnSkinCluster(self.tracker.obj)
  32. self.vertexComp = om.MFnSingleIndexedComponent().create(om.MFn.kMeshVertComponent)
  33.  
  34. def getWeights(self, vertices=None):
  35. vertWeights = self.skinFn.getWeights(self.polygon.tracker.dag, self.vertexComp)
  36. weights = list(vertWeights[-2])
  37. infCount = vertWeights[-1]
  38. weights = [weights[x:x+infCount] for x in range(0,len(weights),infCount)]
  39. dicty = {}
  40. for i, weight in enumerate(weights):
  41. if not vertices or i in vertices:
  42. dicty.update({i:weight})
  43. return dicty
  44. # returns a vert weight list
  45. # {0:[0.1, 0.2, 0.3, 0.4], 1:[etc..]}
  46.  
  47. def setWeights(self,values=None,normalize=True):
  48. vertices = values.keys() #gets all the verts that are going to be edited
  49. oldWeights = self.getWeights(vertices) #gets vert weights for undo
  50. oldValues = []
  51. newValues = []
  52. influences = self.getInfl_IDs().keys() # gets the influence indices
  53. for vert in vertices:
  54. oldValues += oldWeights[vert] # combine weights into a list
  55. newValues += values[vert] # combines the new weights to a list
  56. self.skinFn.setWeights(self.polygon.tracker.dag, self.vertexComp,
  57. om.MIntArray(influences), om.MDoubleArray(newValues),
  58. normalize=normalize, oldValues=om.MDoubleArray(oldValues))
  59.  
  60. <type 'OpenMaya.MDagPath'>
  61. <type 'OpenMaya.MObject'>
  62. <type 'OpenMaya.MIntArray'>
  63. <type 'OpenMaya.MDoubleArray'>
  64. <type 'bool'>
  65. <type 'OpenMaya.MDoubleArray'>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement