Hello again,
I hope it is okey to keep asking. So far every thing I posted was solved so
thanks a lot for that
I 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 given
Also, 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.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 [email protected].
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.