meljunky
unread,Feb 4, 2008, 5:08:03 PM2/4/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python_inside_maya
I am teaching myself on how to create a template command python
plugin.
What I done so far:
1) Accepts a flag called -f/-from
2) If no flag is specified then a default string is used.
3) A method of allowing undo
What I am trying to do:
1) Accepts argument that does not use a flag. Similar to a
pointConstraint's command:
pointConstraint -offset 0 0 0 -weight 1; //Use the current selected
objects
pointConstraint -offset 0 0 0 -weight 1 sphere1 sphere2; //Use the
nodes for the constraint provided they exist
I simply want to print the selection if no nodes are specified ot
print the nodes specified like sphere1 sphere2
Where I am at:
I got the syntaxCreator to look for a selection using
syntax.useSelectionAsDefault(True)
syntax.setObjectType(syntax.kSelectionList, 0);
I cannot get the doIt function to recognized the selection or the
specified nodes.
It will make creating commands easier since it follows the same
format.. far as I know.
Thanks
##############################################################
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import sys
kPluginCmdName = "helloWorld"
kHelloFromFlag = "-f"
kHelloFromLongFlag = "-from"
print "helloWorldCmd.py has been loaded..."
# command
class scriptedCommand(OpenMayaMPx.MPxCommand):
def __init__(self):
OpenMayaMPx.MPxCommand.__init__(self)
self.__fromWhere = "George"
def doIt(self, args):
# Parse the arguments.
argData = OpenMaya.MArgDatabase(self.syntax(), args)
####################################################
#Where I am trying to get the recognization to work#
####################################################
if argData.isFlagSet(kHelloFromFlag):
self.__fromWhere =
argData.flagArgumentString(kHelloFromFlag, 0)
self.redoIt()
def redoIt(self):
print "Hello World from", self.__fromWhere
def isUndoable (self):
return True
def undoIt(self):
print "Goodbye World!"
#Cmd Creator
def cmdCreator():
return OpenMayaMPx.asMPxPtr( scriptedCommand() )
# Syntax creator
def syntaxCreator():
syntax = OpenMaya.MSyntax()
syntax.addFlag(kHelloFromFlag, kHelloFromLongFlag,
OpenMaya.MSyntax.kString)
syntax.useSelectionAsDefault(True)
syntax.setObjectType(syntax.kSelectionList, 0);
return syntax
# Initialize the script plug-in
def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj, "Autodesk", "1.0", "Any")
try:
plugin.registerCommand( kPluginCmdName, cmdCreator, syntaxCreator)
sys.stderr.write( "Register command complete: %s\n" %
kPluginCmdName )
except:
sys.stderr.write( "Failed to register command: %s\n" %
kPluginCmdName )
# Uninitialize the script plug-in
def uninitializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
try:
plugin.deregisterCommand(kPluginCmdName)
except:
sys.stderr.write( "Failed to unregister command: %s\n" %
kPluginCmdName )
raise