15 import maya.api.OpenMaya
as om
19 The presence of this function tells Maya that the plugin produces, and
20 expects to be passed, objects created using the Maya Python API 2.0.
30 class blindDoubleData(om.MPxData):
31 s_id = om.MTypeId( 0x80003 )
32 s_name =
"blindDoubleData"
36 om.MPxData.__init__(self)
40 return blindDoubleData()
42 def readASCII(self, args, lastParsedElement):
44 self.fValue = args.asDouble(lastParsedElement)
45 lastParsedElement = lastParsedElement+1
46 return lastParsedElement
48 def readBinary(self, istream, length):
49 rawData = io.BytesIO(istream)
50 reader = pickle.Unpickler(rawData)
52 self.fValue = reader.load()
56 def writeASCII(self, ostream):
57 data = str(self.fValue)
60 ostream[:] = bytearray(data,
"ascii")
62 def writeBinary(self, ostream):
63 rawData = io.BytesIO()
64 writer = pickle.Pickler(rawData)
66 writer.dump( self.fValue )
68 ostream[:] = rawData.getvalue()
70 def copy(self, other):
71 self.fValue = other.fValue
74 return blindDoubleData.s_id
77 return blindDoubleData.s_name
79 def setValue(self, newValue):
80 self.fValue = newValue
87 class blindDoubleDataCmd(om.MPxCommand):
88 s_name =
"blindDoubleData"
92 om.MPxCommand.__init__(self)
96 return blindDoubleDataCmd()
99 sList = om.MGlobal.getActiveSelectionList()
100 self.iter = om.MItSelectionList(sList, om.MFn.kInvalid)
106 while not self.iter.isDone():
110 dependNode = self.iter.getDependNode()
113 fnDN = om.MFnDependencyNode(dependNode)
115 fullName =
"blindDoubleData"
117 fnDN.findPlug(fullName,
True)
125 fnAttr = om.MFnTypedAttribute()
127 newAttr = fnAttr.create( fullName, briefName, blindDoubleData.s_id )
131 fnDN.addAttribute( newAttr )
135 plug = om.MPlug( dependNode, newAttr )
139 newData = blindDoubleData()
140 newData.setValue( 3.2 )
144 plug.setMPxData( newData )
148 sData = plug.asMObject()
152 pdFn = om.MFnPluginData( sData )
154 assert(isinstance(data, blindDoubleData))
159 def isUndoable(self):
168 def initializePlugin(obj):
169 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
171 plugin.registerData(blindDoubleData.s_name, blindDoubleData.s_id, blindDoubleData.creator)
173 sys.stderr.write(
"Failed to register data\n")
177 plugin.registerCommand(blindDoubleDataCmd.s_name, blindDoubleDataCmd.creator)
179 sys.stderr.write(
"Failed to register command\n")
182 def uninitializePlugin(obj):
183 plugin = om.MFnPlugin(obj)
185 plugin.deregisterCommand(blindDoubleDataCmd.s_name)
187 sys.stderr.write(
"Failed to deregister command\n")
191 plugin.deregisterData(blindDoubleData.s_id)
193 sys.stderr.write(
"Failed to deregister data\n")