Perhaps it was mentioned here already, but:
Additionally, MStatus information no matter how it is passed out from the
method you call regarding the API documentation, will be thrown as
exception.

Thus I personally ignore MStatus pointers and return values of any kind if
writing python, and just decide to catch them whereever probability of
failure is high.

In c++, the API never throws to transmit status information.

Regards,
Sebastian

On Mon, Feb 16, 2009 at 9:40 PM, ryant <[email protected]> wrote:

>
> Judd told me that my statement about the pointer was incorrect. I
> stand corrected, there are cases you can use arguments that are
> declared as a pointer. It is only the MString and MStatus that you
> cant use.
>
> RyanT
> Technical Artist
> www.rtrowbridge.com
> Naughty Dog Inc.
>
> On Feb 16, 12:17 pm, ryant <[email protected]> wrote:
> > Also:
> >
> > int numVertices (MStatus *ReturnStatus=NULL) const
> >
> > This function says the MStatus argument is a "*" pointer. I believe
> > there is not a single case in the Maya API where Python can pass a
> > object to a argument declared as a pointer. All MStatus and MString
> > arugments are declared as pointers so you can not use them with
> > Python. You can pass a regular Python string in the place of a MString
> > though. So that kind of contradicts what I said, but the point is you
> > cant use that they say you can use. Also if you attempt to pass
> > generic bool, double, floats and other types to a argument and it
> > fails it is probably a documentation error. I have found that
> > sometimes using MScriptUtil to declare a pointer of that type will
> > allow me to use the function. Even if that function does not declare
> > that the argument is a reference.
> >
> > RyanT
> > Technical Artistwww.rtrowbridge.com/blog
> > Naughty Dog Inc
> >
> > On Feb 15, 6:27 pm, Jason Osipa <[email protected]> wrote:
> >
> > > "Why do my eyes hurt?"
> >
> > > "Because you've never used them before"
> >
> > > I'm feeling a little THAT right now.  Thank you a 1000 times over.
> >
> > > On Sun, Feb 15, 2009 at 6:19 PM, Dean Edmonds <[email protected]
> >wrote:
> >
> > > > On Sun, Feb 15, 2009 at 14:16, jasonosipa <[email protected]>
> wrote:
> >
> > > > > What do const, &, and * each mean?
> >
> > > > > When you look at documentation for an object, each argument can
> have a
> > > > > lot of different markup, and I'm not confident with guesses at what
> > > > > those mean, so I'll just ask:
> >
> > > > > What do const, &, and * each mean?  What does "blank" mean, where
> > > > > there is no const at the head of the line, and no * or & ?  How
> about
> > > > > the stuff after the = in the argument?  Is that just a "recommended
> > > > > default"?  Does const only show up for things that are MObjects?
> >
> > > > As Tim explained, '&' and '*' are slightly different ways of passing
> > > > the value itself. If neither of those is present than what gets
> passed
> > > > is a copy of the value.
> >
> > > > In terms of translating all that markup into Pythonic terms, you
> first
> > > > have to differentiate between simple types, like integers and floats,
> > > > and object types.
> >
> > > > In Python, if I pass an object to a function the function can
> directly
> > > > manipulate it and the caller will be able to see the results of that
> > > > manipulation. For example:
> >
> > > >    class myObj:
> > > >        someValue = 12
> >
> > > >    def changeObj(theObj):
> > > >        theObj.someValue = 15
> >
> > > >    testObj = myObj()
> >
> > > >    print testObj.someValue
> > > >    12
> >
> > > >    changeObj(testObj)
> > > >    print testObj.someValue
> > > >    15
> >
> > > > The same is *not* true when passing a simple value to a function:
> >
> > > >    def changeValue(theValue):
> > > >        theValue = 15
> >
> > > >    someValue = 12
> > > >    print someValue
> > > >    12
> >
> > > >    changeValue(someValue)
> > > >    print someValue
> > > >    12
> >
> > > > In C++ there is no such differentiation between objects and simple
> > > > values. If a parameter is passed by pointer ('*') or reference ('&')
> > > > then the function can modify it such that the caller will see the
> > > > changes. If neither of those markers is present then the function is
> > > > passed a copy of the value and any changes that the function makes to
> > > > that copy will not be visible to the caller.
> >
> > > > In addition, if a parameter is tagged as 'const' that means that the
> > > > method is promising not modify it, even it has been passed by pointer
> > > > or reference.
> >
> > > > So, if you are calling an API method from Python and one of its
> > > > parameters takes an object type, such as MDagPath, the following
> > > > markups mean that the caller's copy of the object will not be changed
> > > > by the method:
> >
> > > >    MDagPath
> > > >    const MDagPath*
> > > >    const MDagPath&
> >
> > > > while the following mean that the caller's copy of the object can be
> > > > changed by the method:
> >
> > > >    MDagPath*
> > > >    MDagPath&
> >
> > > > In terms of the syntax you use in Python, you always just pass the
> > > > object without doing anything special. E.g:
> >
> > > >    somePath = om.MDagPath()
> > > >    om.MDagPath.getAPathTo(someNode, somePath)
> >
> > > > If the markup indicates that the method can change the object that
> you
> > > > pass to it and you don't want it to change your copy of the object,
> > > > then you would need to pass the method a separate copy of the
> object:.
> > > > In the example below 'tempPath' will be modified by the call to
> > > > getAPathTo() but 'pathToKeep' will remain unchanged:
> >
> > > >    tempPath = om.MDagPath(pathToKeep)
> > > >    om.MDagPath.getAPathTo(someNode, tempPath)
> >
> > > > For simple types we run into a bit of a problem because Python does
> > > > not provide any way for a function to modify a simple type which is
> > > > passed to it such that the caller sees the change. For example,
> > > > MFnMesh has a getUV() method which is declared as follows:
> >
> > > >    MStatus getUV (int uvId, float &u, float &v, const MString
> > > > *uvSet=NULL) const;
> >
> > > > The intent is that you pass the id of the UV you want in the 'uvId'
> > > > parameter and get back its U and V coordinates in the 'u' and 'v'
> > > > parameters. Unfortunately there is no direct way to do that in
> Python,
> > > > so the Maya API provides the MScriptUtil class to get around that.
> > > > E.g:
> >
> > > >    uptr = om.MScriptUtil().asFloatPtr()
> > > >    vptr = om.MScriptUtil().asFloatPtr()
> >
> > > >    meshFn.getUV(13, uptr, vptr)
> >
> > > >    u = om.MScriptUtil.getFloat(uptr)
> > > >    v = om.MScriptUtil.getFloat(vptr)
> >
> > > > Finally, if 'const' appears at the end of the method declaration that
> > > > means that the method promises not to change any of the object's
> > > > member variables. For example, MFnMesh's numVertices() method is
> > > > declared as follows:
> >
> > > >    int numVertices (MStatus *ReturnStatus=NULL) const
> >
> > > > This means that if you call numVertices() you can be assured that the
> > > > MFnMesh object will not be changed by call.
> >
> > > > --
> > > > -deane
> >
> > > --
> > > Jason Osipa, Manager
> > > Osipa Entertainment, LLCwww.osipaentertainment.com
> > > 415.374.9651
> >
> >
> >
>

--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to