returning a value to a script from a command plugin

516 views
Skip to first unread message

ranxerox

unread,
Mar 10, 2010, 6:44:12 PM3/10/10
to python_inside_maya

hey all, I've been writing a command plugin which does come
calculations based on it's input and returns a vector back to the
script which was calling it. It's been a while since I've written a
plugin and I've never written one in python so please excuse the
simplicity of the question but I haven't found my answer in the
documentation so as a last resort I'll post it here.

this is the end of my "doIt" method for my class derived from
OpenMayaMPx.MPxCommand, I am trying to return the vector 'vecDegrees'
back to the python script which is calling this command:

retval = OpenMaya.MScriptUtil()
retval.createFromDouble(vecDegrees[0],vecDegrees[1],vecDegrees[2],0)
retvalFltPtr = retval.asFloat4Ptr()
return retvalFltPtr

from gleaning the documentation I guessed that this was the correct
way to do it, but I am still getting an error from the calling script
which is trying to index the return value, it says 'NoneType' object
is unsubscriptable, so I guess I'm still returning a NoneType
object.

is this the correct way to return a value from a scripted command
plugin ? I tried various methods (such as appendToResult) but got
various errors and the documentation is really not very helpful. Any
help would be much appreciated for this seemingly simple task.

thanks

-Greg

Chad Vernon

unread,
Mar 10, 2010, 7:52:02 PM3/10/10
to python_in...@googlegroups.com
In MPxCommand, doIt() is supposed to return an MStatus.  In order to get the actual command to return something, use the setResult() or appendToResult() methods.


Chad Vernon

unread,
Mar 10, 2010, 7:54:04 PM3/10/10
to python_in...@googlegroups.com
And for a bunch of doubles, you'll need to return either an MDoubleArray with setResult or call appendToResult several times with each value.

ranxerox

unread,
Mar 10, 2010, 8:34:20 PM3/10/10
to python_inside_maya

thanks a lot Chad, I had tried that initially and had received some
error message which led me to believe that I had been exploring an
incorrect route. So .. if the command returns an MStatus object how
do you actually get the result of the command from the calling
script ?

thanks

-Greg

On Mar 10, 7:54 pm, Chad Vernon <chadver...@gmail.com> wrote:
> And for a bunch of doubles, you'll need to return either an MDoubleArray
> with setResult or call appendToResult several times with each value.
>

> On Wed, Mar 10, 2010 at 4:52 PM, Chad Vernon <chadver...@gmail.com> wrote:
> > In MPxCommand, doIt() is supposed to return an MStatus.  In order to get
> > the actual command to return something, use the setResult() or
> > appendToResult() methods.
>

Chad Vernon

unread,
Mar 10, 2010, 9:05:29 PM3/10/10
to python_in...@googlegroups.com
When you call the command from script, it will return whatever you put in the setResult or appendToResult command.  It doesn't return the MStatus returned in the doIt() method.


ranxerox

unread,
Mar 11, 2010, 11:53:10 AM3/11/10
to python_inside_maya

thanks a lot Chad, it works now. I'm not sure what I was doing
wrong which led me to believe that appendToResult wasn't the correct
way to do it. Maybe it's because it isn't used in any of the python
plugin command examples.

anyway, thanks again.

-Greg

On Mar 10, 9:05 pm, Chad Vernon <chadver...@gmail.com> wrote:
> When you call the command from script, it will return whatever you put in
> the setResult or appendToResult command.  It doesn't return the MStatus
> returned in the doIt() method.
>

Reply all
Reply to author
Forward
0 new messages