"""--------------------------------------------------------------------------------[REQUISITOS]--------------------------------------------------------------------------------"""
##[MODULOS,OBJETOS Y CLASS]##
# modulos
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import sys
# objetos y classes
MPxCommand = OpenMayaMPx.MPxNode # class (que no objeto) de la que heredar
##[VARIABLES]##
kHelpShortFlg = "-h"
kHelpLongFlg = "-help"
helpMessage = "este commando sirve para crear una joint mediante un command plugin"
kMyJointShortFlg = "-jRh"
kMyJointtLongFlg = "-jointRh"
#--[nombre del commando]--#
myCommandName = "myJointCommand"
"""----------------------------------------------------------------------------------[CLASS]----------------------------------------------------------------------------------"""
##[CLASS]##
class MyJointPluginCommand(MPxCommand):
#--[static Var]--#
myJointValue = None
#--[methods]--#
# __init__
def __init__(self):
super(MyJointPluginCommand,self).__init__()
# argumentParser
def argumentParser(self,argList):
syntax = self.syntax()
OpenMaya.MArgDatabase(syntax, argList) #MArgDatabase analiza(parse) command args, flags y flags args
mArgDatabase = OpenMaya.MArgDatabase(syntax, argList)
#--[flags]--]
# flag corta help corta/larga
if mArgDatabase.isFlagSet(kHelpShortFlg): # isFlagSet() viene heredado de la superclass de MArgDatabase que es MArgParse. Esto es para que queriee que flag le he dado
self.setResult(helpMessage) # el mesaje de ayuda como arg
return OpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kHelpLongFlg):
self.setResult(helpMessage)
return OpenMaya.MStatus.kSuccess
# flag corta joint corta/larga
if mArgDatabase.isFlagSet(kMyJointShortFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointShortFlg, 0) # aqui le digo que tipo de argumento espero recibir en la flag, y entr() los args son la flag, y el indice por defecto
return OpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kMyJointtLongFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointtLongFlg, 0)
return OpenMaya.MStatus.kSuccess
def isUndoable(self):
return true
def undoIt(self):
print "undo"
mFnDagNode = OpenMaya.MfnDagNode # para acceder al transform de lo que quiero borrar
mDagModifier = OpenMaya.MDagModifier(mFnDagNode.parent(0)) # es el stack de operacion
mDagModifier.deleteNode()
mDagModifier.doIt()
return OpenMaya.MStatus.kSuccess
def redoIt():
mFnDagNode = OpenMaya.MFnDagNode()
objJoint = mFnDagNode.create("joint", "myJoint")
return OpenMaya.MStatus.kSuccess
def doIt(self,argList):
print "yeeeee"
self.argumentParser(argList) # como siempre, en OOP para usar un metodo dentro de otro (nesting), uso self para indicar que el metodopertenece a la class
if self.myJointValue != None:
self.redoIt() # aqui dice es donde va el script donde pilla vertices y pone cubos. redoIt porque se puede hacer varias veces. Y doIt porque solo hace argumentParser una vez
else:
print " nada que crear "
return OpenMaya.MStatus.kSuccess #es importante devolver el estado de lo has hecho
"""----------------------------------------------------------------------------------[FUNCIONES]----------------------------------------------------------------------------------"""
##[FUNCIONES]##
# def para atachar pointer
def myCommandCreator():
return OpenMayaMPx.asMPxPtr(MyJointPluginCommand())
# MSyntax object
def mySyntaxCreator():
# creo objeto mSyntax
mSyntax = OpenMaya.MSyntax()
# addo flags
mSyntax.addFlag(kHelpShortFlg, kHelpLongFlg)
mSyntax.addFlag(kMyJointShortFlg, kMyJointShortFlg, OpenMaya.MSyntax.kDouble) #indico tipo de variable que debe recibir
return mSyntax
"""------------------------------------------------------------------------------[REGISTRO Y DESREGISTRO]-----------------------------------------------------------------------------"""
#--[initialization command plugin]--#
def initializePlugin(myMObject):
myPlugin = OpenMayaMPx.MFnPlugin(myMObject)
try:
myPlugin.registerCommand( myCommandName, myCommandCreator, mySyntaxCreator ) #attacho pointer
sys.stderr.write("\n se ha inicializado correctamente " + myCommandName)
except:
sys.stderr.write("\n meeeccc!! , fallo de registro de " + myCommandName)
#--[uninitialization command plugin]--#
def uninitializePlugin(myMObject):
myPlugin = OpenMayaMPx.MFnPlugin(myMObject)
try:
myPlugin.deregisterCommand(myCommandName) #aqui no requiere attachar pointer, ya esta dentro del core
sys.stderr.write("\n se ha desinicializado correctamente " + myCommandName)
except:
sys.stderr.write("\n meeeccc!! , fallo de desregistro de " + myCommandName)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9eef9d5d-099a-4db6-ab06-87eaf0150be7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
...
sure, so if I do cmds.myJointCommand(jRh=1) or cmds.myJointCommand(h=1)I get > # Error: RuntimeError: file <string> line 2: You are not licensed to use the "myJointCommand" command. #El miércoles, 4 de noviembre de 2015, 9:42:11 (UTC+1), Marcus Ottosson escribió:
Could you say again what the problem was, the help flag doesn't work? Would it be possible to post a minimal example of the problem?On 3 Nov 2015, at 17:51, Rudi Hammad <rudih...@gmail.com> wrote:
Hello again,I hope it is okey to keep asking. So far every thing I posted was solved so thanks a lot for thatI hope you could help me out wth that too.I bought Chayan Vinayak Dvd, and it excelent but there are some things that remain unclear. So I am trying to build this command plugin that just builds a joint when the argument jointRh is givenAlso, the help flag doesn´t work so...the command is cmds.myJointCommand(jRh=1)it register and unregister okey, so can someone try it out?Thanks
"""--------------------------------------------------------------------------------[REQUISITOS]--------------------------------------------------------------------------------"""
##[MODULOS,OBJETOS Y CLASS]##
# modulos
import maya.OpenMayaasOpenMaya
import maya.OpenMayaMPxasOpenMayaMPx
import sys
# objetos y classes
MPxCommand=OpenMayaMPx.MPxNode# class (que no objeto) de la que heredar
##[VARIABLES]##
kHelpShortFlg ="-h"
kHelpLongFlg ="-help"
helpMessage ="este commando sirve para crear una joint mediante un command plugin"
kMyJointShortFlg ="-jRh"
kMyJointtLongFlg ="-jointRh"
#--[nombre del commando]--#
myCommandName ="myJointCommand"
"""----------------------------------------------------------------------------------[CLASS]----------------------------------------------------------------------------------"""
##[CLASS]##
classMyJointPluginCommand(MPxCommand):
#--[static Var]--#
myJointValue =None
#--[methods]--#
# __init__
def __init__(self):
super(MyJointPluginCommand,self).__init__()
# argumentParser
def argumentParser(self,argList):
syntax =self.syntax()
OpenMaya.MArgDatabase(syntax, argList)#MArgDatabase analiza(parse) command args, flags y flags args
mArgDatabase =OpenMaya.MArgDatabase(syntax, argList)
#--[flags]--]
# flag corta help corta/larga
if mArgDatabase.isFlagSet(kHelpShortFlg):# isFlagSet() viene heredado de la superclass de MArgDatabase que es MArgParse. Esto es para que queriee que flag le he dado
self.setResult(helpMessage)# el mesaje de ayuda como arg
returnOpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kHelpLongFlg):
self.setResult(helpMessage)
returnOpenMaya.MStatus.kSuccess
# flag corta joint corta/larga
if mArgDatabase.isFlagSet(kMyJointShortFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointShortFlg,0)# aqui le digo que tipo de argumento espero recibir en la flag, y entr() los args son la flag, y el indice por defecto
returnOpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kMyJointtLongFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointtLongFlg,0)
returnOpenMaya.MStatus.kSuccess
def isUndoable(self):
returntrue
def undoIt(self):
print"undo"
mFnDagNode =OpenMaya.MfnDagNode# para acceder al transform de lo que quiero borrar
mDagModifier =OpenMaya.MDagModifier(mFnDagNode.parent(0))# es el stack de operacion
mDagModifier.deleteNode()
mDagModifier.doIt()
returnOpenMaya.MStatus.kSuccess
def redoIt():
mFnDagNode =OpenMaya.MFnDagNode()
objJoint = mFnDagNode.create("joint","myJoint")
returnOpenMaya.MStatus.kSuccess
def doIt(self,argList):
print"yeeeee"
self.argumentParser(argList)# como siempre, en OOP para usar un metodo dentro de otro (nesting), uso self para indicar que el metodopertenece a la class
ifself.myJointValue !=None:
self.redoIt()# aqui dice es donde va el script donde pilla vertices y pone cubos. redoIt porque se puede hacer varias veces. Y doIt porque solo hace argumentParser una vez
else:
print" nada que crear "
returnOpenMaya.MStatus.kSuccess #es importante devolver el estado de lo has hecho
"""----------------------------------------------------------------------------------[FUNCIONES]----------------------------------------------------------------------------------"""
##[FUNCIONES]##
# def para atachar pointer
def myCommandCreator():
returnOpenMayaMPx.asMPxPtr(MyJointPluginCommand())
# MSyntax object
def mySyntaxCreator():
# creo objeto mSyntax
mSyntax =OpenMaya.MSyntax()
# addo flags
mSyntax.addFlag(kHelpShortFlg, kHelpLongFlg)
mSyntax.addFlag(kMyJointShortFlg, kMyJointShortFlg,OpenMaya.MSyntax.kDouble)#indico tipo de variable que debe recibir
return mSyntax
"""------------------------------------------------------------------------------[REGISTRO Y DESREGISTRO]-----------------------------------------------------------------------------"""
#--[initialization command plugin]--#
def initializePlugin(myMObject):
myPlugin =OpenMayaMPx.MFnPlugin(myMObject)
try:
myPlugin.registerCommand( myCommandName, myCommandCreator, mySyntaxCreator )#attacho pointer
sys.stderr.write("\n se ha inicializado correctamente "+ myCommandName)
except:
sys.stderr.write("\n meeeccc!! , fallo de registro de "+ myCommandName)
#--[uninitialization command plugin]--#
def uninitializePlugin
...
--You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fbc9fe34-5cac-499c-a6e0-c99b59c7af21%40googlegroups.com.
Is there a reason you are aliasing MPxNode to MPxCommand? When you use MPxNode, you have to register an id with Maya. If you make your plugin actually subclass from the real MPxCommand, does it work?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1446640554.1346926.428847777.30F613DB%40webmail.messagingengine.com.
"""--------------------------------------------------------------------------------[REQUISITOS]--------------------------------------------------------------------------------"""
##[MODULOS,OBJETOS Y CLASS]##
# modulos
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import sys
# objetos y classes
MPxCommand = OpenMayaMPx.MPxCommand # class (que no objeto) de la que heredar
##[VARIABLES]##
kHelpShortFlg = "-h"
kHelpLongFlg = "-hlp"
helpMessage = "este commando sirve para crear una joint mediante un command plugin"
kMyJointShortFlg = "-j"
kMyJointtLongFlg = "-jnt"
#--[nombre del commando]--#
myCommandName = "myJointCommand"
"""----------------------------------------------------------------------------------[CLASS]----------------------------------------------------------------------------------"""
##[CLASS]##
class MyJointPluginCommand(MPxCommand):
#--[static Var]--#
myJointValue = None
#--[methods]--#
# __init__
def __init__(self):
super(MyJointPluginCommand,self).__init__()
# argumentParser
def argumentParser(self,argList):
syntax = self.syntax()
OpenMaya.MArgDatabase(syntax, argList) #MArgDatabase analiza(parse) command args, flags y flags args
mArgDatabase = OpenMaya.MArgDatabase(syntax, argList)
#--[flags]--]
# flag corta help corta/larga
if mArgDatabase.isFlagSet(kHelpShortFlg): # isFlagSet() viene heredado de la superclass de MArgDatabase que es MArgParse. Esto es para que queriee que flag le he dado
self.setResult(helpMessage) # el mesaje de ayuda como arg
return OpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kHelpLongFlg):
self.setResult(helpMessage)
return OpenMaya.MStatus.kSuccess
# flag corta joint corta/larga
if mArgDatabase.isFlagSet(kMyJointShortFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointShortFlg, 0) # aqui le digo que tipo de argumento espero recibir en la flag, y entr() los args son la flag, y el indice por defecto
return OpenMaya.MStatus.kSuccess
if mArgDatabase.isFlagSet(kMyJointtLongFlg):
self.myJointValue = mArgDatabase.flagArgumentBool(kMyJointtLongFlg, 0)
return OpenMaya.MStatus.kSuccess
def isUndoable(self):
return true
def undoIt(self):
print "undo"
mFnDagNode = OpenMaya.MfnDagNode # para acceder al transform de lo que quiero borrar
mDagModifier = OpenMaya.MDagModifier(mFnDagNode.parent(0)) # es el stack de operacion
mDagModifier.deleteNode()
mDagModifier.doIt()
return OpenMaya.MStatus.kSuccess
def redoIt():
mFnDagNode = OpenMaya.MFnDagNode()
objJoint = mFnDagNode.create("joint", "myJoint")
return OpenMaya.MStatus.kSuccess
def doIt(self,argList):
print "yeeeee"
self.argumentParser(argList) # como siempre, en OOP para usar un metodo dentro de otro (nesting), uso self para indicar que el metodopertenece a la class
if self.myJointValue != None:
self.redoIt() # aqui dice es donde va el script donde pilla vertices y pone cubos. redoIt porque se puede hacer varias veces. Y doIt porque solo hace argumentParser una vez
else:
print " nada que crear "
return OpenMaya.MStatus.kSuccess #es importante devolver el estado de lo has hecho
"""----------------------------------------------------------------------------------[FUNCIONES]----------------------------------------------------------------------------------"""
##[FUNCIONES]##
# def para atachar pointer
def myCommandCreator():
return OpenMayaMPx.asMPxPtr(MyJointPluginCommand())
# MSyntax object
def mySyntaxCreator():
# creo objeto mSyntax
mSyntax = OpenMaya.MSyntax()
# addo flags
mSyntax.addFlag(kHelpShortFlg, kHelpLongFlg)
mSyntax.addFlag(kMyJointShortFlg, kMyJointShortFlg, OpenMaya.MSyntax.kDouble) #indico tipo de variable que debe recibir
return mSyntax
"""------------------------------------------------------------------------------[REGISTRO Y DESREGISTRO]-----------------------------------------------------------------------------"""
#--[initialization command plugin]--#
def initializePlugin(myMObject):
myPlugin = OpenMayaMPx.MFnPlugin(myMObject)
try:
myPlugin.registerCommand( myCommandName, myCommandCreator, mySyntaxCreator ) #attacho pointer
sys.stderr.write("\n se ha inicializado correctamente " + myCommandName)
except:
sys.stderr.write("\n meeeccc!! , fallo de registro de " + myCommandName)
#--[uninitialization command plugin]--#
def uninitializePlugin(myMObject):
myPlugin = OpenMayaMPx.MFnPlugin(myMObject)
try:
myPlugin.deregisterCommand(myCommandName) #aqui no requiere attachar pointer, ya esta dentro del core
sys.stderr.write("\n se ha desinicializado correctamente " + myCommandName)
except:
sys.stderr.write("\n meeeccc!! , fallo de desregistro de " + myCommandName)...
...
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56dcb75b-ed97-4036-b5b4-6f0163bc8c4c%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56dcb75b-ed97-4036-b5b4-6f0163bc8c4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c6454f77-974a-486c-8937-5c0a2e3e4309%40googlegroups.com.