0% found this document useful (0 votes)
187 views11 pages

1 - Maya Commands - Arguments PDF

This document discusses adding argument syntax to custom Maya commands. It covers the classes needed to define and handle command flag input, including MSyntax, MArgDatabase, MArgParser and MArgList. It provides examples of retrieving arguments from these classes, checking for flags, and adding help text for custom commands. The document is intended as training material for a Maya developer workshop on custom command arguments.

Uploaded by

GustavoLadino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views11 pages

1 - Maya Commands - Arguments PDF

This document discusses adding argument syntax to custom Maya commands. It covers the classes needed to define and handle command flag input, including MSyntax, MArgDatabase, MArgParser and MArgList. It provides examples of retrieving arguments from these classes, checking for flags, and adding help text for custom commands. The document is intended as training material for a Maya developer workshop on custom command arguments.

Uploaded by

GustavoLadino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Maya Commands Arguments – Day 4

Kristine Middlemiss, Senior Developer Consultant


Autodesk Developer Network (ADN)

© 2012 Autodesk 1
Agenda
• Adding Argument Syntax to Custom Commands

© 2012 Autodesk 2
Adding Arguments

© 2012 Autodesk 3
Command Arguments
• These flags and arguments are optional.
• Users can specify parameters to a Maya Command in two
ways:
• Command Flags and Flag Arguments
• Command Arguments

Python Example: cmds.headsUpDisplay(“myHUD”, s= 0, b=0, label=“myHUD”)


MEL Example: headsUpDisplay -s 0 –b 0 –label “myHUD” myHUD

• Basic command structure:


• myCommand –myFlag <optionalFlagArg> <optionalCmdArg>

• Can have multiple command flags and arguments but only


one command arguments.
© 2012 Autodesk 4
Custom Command
• The classes you need to work with when writing syntax
objects are:
• MSyntax
• MArgDatabase
• MArgParser
• MArgList

• These classes are required for defining and handling


command flag input.

• You must use the MSyntax and MArgParser classes to


support arguments within a scripted MPxCommand.
© 2012 Autodesk 5
Syntax Objects Classes
• MSyntax:
• Used to specify flags and arguments passed to commands.

• MArgDatabase:
• Used only to create an MArgDatabase object, then uses parent
class functions (MArgParser) to work with the parsed objects.

• MArgParser:
• Used to parse and store all of the flags, arguments and objects
which are passed to a command.

• MArgList:
• Used to create and hold the list of arguments that are passed to a
command, this is where you can6 retrieve them from.
© 2012 Autodesk
MSyntax
This newSyntax() method is used during the command
registration into our plug-in:
• Syntax registration:
mplugin.registerCommand( kPluginCmdName, cmdCreator, syntaxCreator )

• Syntax definition:

cFlagShort = “-str”
cFlagLong = “-string”

def syntaxCreator():
syntax = OpenMaya.MSyntax()
syntax.addFlag( cFlagShort, cFlagLong )
return syntax
© 2012 Autodesk 7
MSyntax
How to retrieve arguments, that have been set by the user:
MPxCommand::syntax()
def doIt(self, args):

argData = OpenMaya.MArgDatabase(self.syntax(), args)

if( argData.isFlagSet( cFlagLong) ) :


argString = argData.flagArgumentString(cFlagLong, 0)
if (argData.isFlagSet(cFlagShort)):
argString = argData.flagArgumentString(cFlagShort, 0)

© 2012 Autodesk 8
Command with Arguments
• Retrieve arguments from MArgList

cmds.myCmd(q=True)

#- This is a method which will be used by our command doIt() method to


#- check arguments passed into our command call.
def parseArgs ( self, args ):
argData = OpenMaya.MArgDatabase( self.syntax(), args)
if argData.isFlagSet(kQuietFlag):
self.quiet = 1

def doIt(self, args):


self.parseArgs ( args )

© 2012 Autodesk 9
Help on Custom Command
• Automatic Help
help myCmd;
• Adding your custom help
helpFlagShort = “-h”
helpFlagLong = “-help”

helpText = “\nThe myCmd command is used to …..”

def syntaxCreator():
syntax = OpenMaya.MSyntax()
syntax.addFlag(helpFlagShort , helpFlagLong)

def doIt(self, args):


argData = OpenMaya.MArgDatabase(self.syntax(), args)
if argData.isFlagSet(helpFlagShort ) :
self.setResult( helpText )
return OpenMaya.MStatus.kSuccess

© 2012 Autodesk 10
Autodesk

© 2012 Autodesk 11

You might also like