def readBinary(self, inStream, numBytesToRead): """Read in 4 byte packs to cStringIO, unpickle from there :note: this method is more complicated than it needs be since asCharPtr does not work ! It returns a string of a single char ... which is not the same :) ! :note: YES, this is a CUMBERSOME way to deal with bytes ... terrible, thanks maya :), thanks python""" sio = cStringIO.StringIO() scriptutil = api.MScriptUtil() scriptutil.createFromInt(0) intptr = scriptutil.asIntPtr() # require multiple of 4 ! if numBytesToRead % 4 != 0: raise AssertionError("Require multiple of for for number of bytes to be read, but is %i" % numBytesToRead) bitmask = 255 # mask the lower 8 bit shiftlist = [0, 8, 16, 24] # used to shift bits by respective values for i in xrange(numBytesToRead / 4): api.MStreamUtils.readInt(inStream, intptr, True) intval = scriptutil.getInt(intptr) # convert to chars - endianess should be taken care of by python for shift in shiftlist: sio.write(chr((intval >> shift) & bitmask)) # END for each byte # END for all 4 bytes to read self.__data = cPickle.loads(binascii.a2b_base64(sio.getvalue())) sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def nodeCreator(cls): """ !@Brief Node creator function. Get maya API help for more informations. """ return OpenMayaMPx.asMPxPtr(cls())
def cmdCreator(): # Create the command """ Return: pointer to the command """ ptr = OpenMayaMPx.asMPxPtr(SamplePyCmd()) return ptr
def readASCII(self, args, lastParsedElement): try: if args.length() > 0: parsedIndex = OpenMaya.MScriptUtil.getUint(lastParsedElement) self.__fValue = args.asDouble( parsedIndex ) parsedIndex += 1 OpenMaya.MScriptUtil.setUint(lastParsedElement,parsedIndex) fValueDictionary[OpenMayaMPx.asHashable(self)]=self.__fValue except: sys.stderr.write("Failed to read ASCII value.") raise
def readASCII(self, args, lastParsedElement): """Read base64 element and decode to cStringIO, then unpickle""" parsedIndex = api.MScriptUtil.getUint(lastParsedElement) base64encodedstring = args.asString(parsedIndex) self.__data = cPickle.loads(binascii.a2b_base64(base64encodedstring)) parsedIndex += 1 api.MScriptUtil.setUint(lastParsedElement,parsedIndex) # proceed the index # update tracking dict sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def __del__(self): """Remove ourselves from the dictionary to prevent flooding :note: we can be called even if maya is already unloaded or shutting down""" if mpx.asHashable is not None: del(sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)]) # call super just to be on the safe side in future, currently it appears # not to be required try: super(PyPickleData, self).__del__() except AttributeError: # Maya 2008 and following do not require this anymore as they # do not have a del method implemented apparently pass
def doEditFlags(self): theParser = self._parser() theControl = kPythonPtrTable.get(OpenMayaMPx.asHashable(self._control()), None) if theParser.isFlagSet(kNopFlag): theControl.setOperation(kNop) elif theParser.isFlagSet(kMultFlag): theControl.setOperation(kMult) elif theParser.isFlagSet(kAddFlag): theControl.setOperation(kAdd) elif theParser.isFlagSet(kRedrawFlag): theControl.redrawCells() theControl.redrawLabels() else: OpenMayaMPx.MPxControlCommand.doEditFlags(self)
def doPress(self, event): OpenMayaMPx.MPxSelectionContext.doPress(self, event) spc = OpenMaya.MSpace.kWorld # If we are not in selecting mode (i.e. an object has been selected) # then set up for the translation. # if not self._isSelecting(): argX = OpenMaya.MScriptUtil() argX.createFromInt(0) argXPtr = argX.asShortPtr() argY = OpenMaya.MScriptUtil() argY.createFromInt(0) argYPtr = argY.asShortPtr() event.getPosition(argXPtr, argYPtr) self.__startPos_x = OpenMaya.MScriptUtil(argXPtr).asShort() self.__startPos_y = OpenMaya.MScriptUtil(argYPtr).asShort() self.__view = OpenMayaUI.M3dView.active3dView() camera = OpenMaya.MDagPath() self.__view.getCamera(camera) fnCamera = OpenMaya.MFnCamera(camera) upDir = fnCamera.upDirection(spc) rightDir = fnCamera.rightDirection(spc) # Determine the camera used in the current view # if fnCamera.isOrtho(): if upDir.isEquivalent(OpenMaya.MVector.zNegAxis, kVectorEpsilon): self.__currWin = MoveContext.kTop elif rightDir.isEquivalent(OpenMaya.MVector.xAxis, kVectorEpsilon): self.__currWin = MoveContext.kFront else: self.__currWin = MoveContext.kSide else: self.__currWin = MoveContext.kPersp # Create an instance of the move tool command. # newCmd = self._newToolCommand() self.__cmd = kTrackingDictionary.get(OpenMayaMPx.asHashable(newCmd), None) self.__cmd.setVector(0.0, 0.0, 0.0)
def nodeCreator(): return OpenMayaMPx.asMPxPtr( dynNode() )
def nodeCreator(cls): return OpenMayaMPx.asMPxPtr(cls())
def nodeCreator(): return OpenMayaMPx.asMPxPtr( vertSnapDeformer() )
def creator(): return OpenMayaMPx.asMPxPtr(gear_curveCns())
def initializePlugin(mobject): mplugin = omMPx.MFnPlugin(mobject) try: mplugin.registerNode( kPluginNodeTypeName, stickyDeformerId, nodeCreator, nodeInitializer, omMPx.MPxNode.kDeformerNode ) except: sys.stderr.write( "Failed to register node: %s\n" % kPluginNodeTypeName )
return OpenMayaMPx.asMPxPtr( moveManipContext() )
def nodeCreator(): '''creator ''' return OpenMayaMPx.asMPxPtr(oyTrajectoryDrawer())
def nodeCreator(): return OpenMayaMPx.asMPxPtr(CVG())
def nodeCreator(): return ompx.asMPxPtr(ParentConstraint())
def cmdCreator(): return ompx.asMPxPtr(ParentConstraintCmd())
def uninitializePlugin(obj): fnPlugin = OpenMayaMpx.MFnPlugin(obj) fnPlugin.deregisterNode(varfkNode.kPluginNodeId)
def initializePlugin(obj): fnPlugin = OpenMayaMpx.MFnPlugin(obj, 'Bogdan Diaconu', '1.0', 'Any') fnPlugin.registerNode('varfkNode', varfkNode.kPluginNodeId, creator, initialize)
def creator(): return OpenMayaMpx.asMPxPtr(varfkNode())
def nodeCreator(): # TODO change this node name return OpenMayaMPx.asMPxPtr(nodeName)
def uninitializePlugin(mobject): mplugin = OpenMayaMPx.MFnPlugin(mobject) try: mplugin.deregisterNode( nodeID ) except: sys.stderr.write( "Failed to unregister command: %s\n" % nodeName )
def creator(): return OpenMayaMPx.asMPxPtr( gear_percentageToU() )
def nodeCreator(cls): print('nodeCreator') return ommpx.asMPxPtr(cls())
def cmdCreator(): return OpenMayaMPx.asMPxPtr( scriptedCommand() )
def nodeCreator(): return OpenMayaMPx.asMPxPtr(ehm_pushDeformer())
def contextCmdCreator(): """Wrapper function that created the command""" return OpenMayaMPx.asMPxPtr(mayaSelctionCtxCmd())
def uninitializePlugin(mobject): mplugin = omMPx.MFnPlugin(mobject) try: mplugin.deregisterNode( stickyDeformerId ) except: sys.stderr.write( "Failed to unregister node: %s\n" % kPluginNodeTypeName )
def cmdCreator(): return ompx.asMPxPtr(selPoles())
def nodeCreator(): return omMPx.asMPxPtr( stickyDeformer() )
def nodeCreator(): return OpenMayaMPx.asMPxPtr( sceneMsgCmd() )
def commandCreator(): return OpenMayaMPx.asMPxPtr(createCameraFrustum())
def normalizeCreator(): return OpenMayaMPx.asMPxPtr( normalize() )
def nodeCreator(): return OpenMayaMPx.asMPxPtr(jiggleNode())
def locatorManipCreator(): return OpenMayaMPx.asMPxPtr(swissArmyLocatorManip())
def uninitializePlugin(mObj): plugin = OpenMayaMPx.MFnPlugin(mObj) try: plugin.deregisterNode(nodeId) except: sys.stderr.write('Faild to unload plugin: %s' % nodeName)
def create(cls): return mpx.asMPxPtr( cls() )
def cmdCreator(): return OpenMayaMPx.asMPxPtr(WhatIsCmd())
def nodeCreator(): return OpenMayaMPx.asMPxPtr(stretchSplineSolver())
def nodeCreatorLSystem(): return OpenMayaMPx.asMPxPtr( LSystemInstanceNode() )
def ms_environment_nodeCreator(): return OpenMayaMPx.asMPxPtr(ms_environment())
def nodeCreatorRandom(): return OpenMayaMPx.asMPxPtr( randomNode() )
def cmdCreator(): return OpenMayaMPx.asMPxPtr(InheritParentsName())
def initializePlugin(mobject): # Create menu buildMenu = "if (`menu -exists LSystemInstance`) { deleteUI LSystemInstance; }; " buildMenu += "menu -parent MayaWindow -label \"LSystemInstance\" -tearOff true LSystemInstance; " mel.eval(buildMenu) mplugin = OpenMayaMPx.MFnPlugin(mobject) # load randomNode commands try: mplugin.registerNode(kPluginNodeTypeName2, randomNodeId, nodeCreatorRandom, nodeInitializerRandom) # default randomNode network defaultRandom = "polySphere; hide; instancer; createNode randomNode; " defaultRandom += "connectAttr pSphere1.matrix instancer1.inputHierarchy[0]; " defaultRandom += "connectAttr randomNode1.outPoints instancer1.inputPoints; " cmds.menuItem(label="RandomNode Default", parent="MayaWindow|LSystemInstance", command=defaultRandom, sourceType="mel") # custom randomNode network customRandom = "$selection = `ls -selection`; " customRandom += "if(size($selection) != 1) { error \"Select one object\"; }; " customRandom += "hide; instancer; createNode randomNode; " customRandom += "connectAttr ($selection[0] + \".matrix\") instancer1.inputHierarchy[0]; " customRandom += "connectAttr randomNode1.outPoints instancer1.inputPoints; " cmds.menuItem(label="RandomNode Selection", parent="MayaWindow|LSystemInstance", command=customRandom, sourceType="mel") except: sys.stderr.write("Failed to register node: %s\n" % kPluginNodeTypeName2) # load LSystem commands try: mplugin.registerNode(kPluginNodeTypeName1, LSystemInstanceNodeId, nodeCreatorLSystem, nodeInitializerLSystem) # default LSystem network defaultLSystem = "polyCube; instancer; createNode LSystemInstanceNode; " defaultLSystem += "connectAttr pCube1.matrix instancer1.inputHierarchy[0]; " defaultLSystem += "connectAttr LSystemInstanceNode1.branches instancer1.inputPoints; " defaultLSystem += "polySphere; instancer; " defaultLSystem += "connectAttr pSphere1.matrix instancer2.inputHierarchy[0]; " defaultLSystem += "connectAttr LSystemInstanceNode1.flowers instancer2.inputPoints; " defaultLSystem += "select -add pCube1; " defaultLSystem += "hide; " cmds.menuItem(label="LSystem Default", parent="MayaWindow|LSystemInstance", command=defaultLSystem, sourceType="mel") # custom LSystem network customLSystem = "$selection = `ls -selection`; hide; " customLSystem += "if(size($selection) != 2) { error \"Select two objects (branches, flowers)\"; }; " customLSystem += "instancer; createNode LSystemInstanceNode; " customLSystem += "connectAttr ($selection[0] + \".matrix\") instancer1.inputHierarchy[0]; " customLSystem += "connectAttr LSystemInstanceNode1.branches instancer1.inputPoints; " customLSystem += "instancer; " customLSystem += "connectAttr ($selection[1] + \".matrix\") instancer2.inputHierarchy[0]; " customLSystem += "connectAttr LSystemInstanceNode1.flowers instancer2.inputPoints; " cmds.menuItem(label="LSystem Custom", parent="MayaWindow|LSystemInstance", command=customLSystem, sourceType="mel") except: sys.stderr.write( "Failed to register node: %s\n" % kPluginNodeTypeName1 )
def creator(): return OpenMayaMPx.asMPxPtr(cvShapeInverter())
def helixManipCreator(): #print "helixManip: helixManipCreator called" return OpenMayaMPx.asMPxPtr(helixManip())
def create(): return OpenMayaMPx.asMPxPtr(Ik2bCGA())
OpenMayaMPx.MPxContextCommand.__init__(self)
def uninitializePlugin(mobject): mplugin = OpenMayaMPx.MFnPlugin(mobject) try: mplugin.deregisterCommand( kPluginCmdName ) except: sys.stderr.write( "Failed to unregister command: %s\n" % kPluginCmdName )
def moveManipCreator(): return OpenMayaMPx.asMPxPtr( moveManip() )
def nodeCreator(): return OpenMayaMPx.asMPxPtr(TDtrigonometricNode())
def nodeCreator(): return OpenMayaMPx.asMPxPtr(wheelNode())
def nodeCreator(cls): return ommpx.asMPxPtr(cls())
def makeObj(self): return OpenMayaMPx.asMPxPtr(mayaSelectionContext())
def initializePlugin(obj): plugin = ommpx.MFnPlugin( obj , 'matthieuCantat', '1.0', 'Any') try: plugin.registerNode( dynamicTrs.kPluginNodeTypeName, dynamicTrs.kPluginNodeId, dynamicTrs.nodeCreator, dynamicTrs.nodeInitializer) except: raise Exception('Failed to register node: {0}'.format(dynamicTrs.kPluginNodeTypeName) )
def delaunayCreator(): return OpenMayaMPx.asMPxPtr( delaunay() )
def nodeCreator(): return ompx.asMPxPtr(DsRaycast())