12 from builtins
import next
16 import maya.api.OpenMaya
as om
20 The presence of this function tells Maya that the plugin produces, and
21 expects to be passed, objects created using the Maya Python API 2.0.
31 class blindDoubleData(om.MPxData):
32 s_id = om.MTypeId( 0x80058 )
33 s_name =
"py2BlindDoubleData"
37 om.MPxData.__init__(self)
41 return blindDoubleData()
43 def readASCII(self, args, lastParsedElement):
45 self.fValue = args.asDouble(lastParsedElement)
46 lastParsedElement = lastParsedElement+1
47 return lastParsedElement
49 def readBinary(self, istream, length):
50 rawData = io.BytesIO(istream)
51 reader = pickle.Unpickler(rawData)
53 self.fValue = reader.load()
58 data = str(self.fValue)
63 def writeBinary(self):
64 rawData = io.BytesIO()
65 writer = pickle.Pickler(rawData)
67 writer.dump( self.fValue )
68 return bytearray(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 =
"py2BlindDoubleData"
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)
116 fnDN.findPlug(blindDoubleDataCmd.s_name,
True)
124 fnAttr = om.MFnTypedAttribute()
126 newAttr = fnAttr.create( blindDoubleDataCmd.s_name, briefName, blindDoubleData.s_id )
130 fnDN.addAttribute( newAttr )
134 plug = om.MPlug( dependNode, newAttr )
138 newData = blindDoubleData()
139 newData.setValue( 3.2 )
143 plug.setMPxData( newData )
147 sData = plug.asMObject()
151 pdFn = om.MFnPluginData( sData )
153 assert(isinstance(data, blindDoubleData))
158 def isUndoable(self):
167 def initializePlugin(obj):
168 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
170 plugin.registerData(blindDoubleData.s_name, blindDoubleData.s_id, blindDoubleData.creator)
172 sys.stderr.write(
"Failed to register data\n")
176 plugin.registerCommand(blindDoubleDataCmd.s_name, blindDoubleDataCmd.creator)
178 sys.stderr.write(
"Failed to register command\n")
181 def uninitializePlugin(obj):
182 plugin = om.MFnPlugin(obj)
184 plugin.deregisterCommand(blindDoubleDataCmd.s_name)
186 sys.stderr.write(
"Failed to deregister command\n")
190 plugin.deregisterData(blindDoubleData.s_id)
192 sys.stderr.write(
"Failed to deregister data\n")