Did you ever figure out how to do this?

On Monday, February 4, 2008 2:08:03 PM UTC-8, meljunky wrote:
>
> 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

-- 
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/1bcc5098-fd82-40de-a676-f5d45810ecda%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to