Basically:

Imagined through the lens of a language like C++, Python always passes
simple types (integer, decimal, etc.) by value—you are passing actual
numeric data. Some places in the API, however, require that simple types be
passed by reference (that is, passing an address to some numeric data rather
than passing the numeric data itself). In such cases, there is no automatic
way for the SWIG layer to translate a simple type into a *reference* to a
simple type. An MScriptUtil object is thus basically a way of wrapping a
simple numeric value (like an integer or decimal) in a complex object so it
can be passed by reference.

In your example, u is an object containing a simple integer value (0 or 20
or whatever you give it when you construct it). The sole function of u is
thus to pass its contents by reference (u.asIntPtr()) or to obtain the value
when something else has changed it (u.asInt()).

On Thu, May 13, 2010 at 1:11 PM, Brandon Harris <[email protected]>wrote:

> OK, I believe that by changing some of this I have actually crippled
> some functionality. So is there more information on exactly what
> u=om.MScriptUtil()
> u.createFromInt(0)
> actually does and if I use 20 instead of 0 what happens?
> Forgive my ignorance. Just an odd class that I'm not sure on what it's
> doing so not 100% on how I'm to use it properly
>
>
>
> On May 11, 12:20 pm, Brandon Harris <[email protected]> wrote:
> > Alright. That did seem to be the issue. big thanks for the help!
> >
> > Brandon L. Harris
> >
> > On May 11, 10:21 am, Paul Molodowitch <[email protected]> wrote:
> >
> >
> >
> > > Yup... the only thing I would add is that you need to allocate space
> for
> > > whatever you're going to be storing - the default constructor allocates
> NO
> > > space (not even enough for a single int).
> >
> > > The easiest way to allocate space here would be to use the
> createFromInt
> > > method:
> >
> > > u=om.MScriptUtil()
> > > u.createFromInt(0) # Can be any value, just want to make sure space is
> > > allocated
> >
> > > You can use the createFromInt / createFromDouble methods to allocate
> enough
> > > space for up to 4 values; if you need more, I suggest using the
> > > (undocumented) createFromList method.
> >
> > > I love MScriptUtil - it lives at the lovely intersection of confusing
> > > implementation, poor documentation, and high expectation of crashes
> when
> > > used incorrectly...
> >
> > > - Paul
> >
> > > On Tue, May 11, 2010 at 12:37 AM, Viktoras <[email protected]>
> wrote:
> > > > On 2010.05.11 06:48, Brandon Harris wrote:
> >
> > > >>         u = openMaya.MScriptUtil().asIntPtr()
> > > >>         v = openMaya.MScriptUtil().asIntPtr()
> > > >>         compItr.getIndex(u,v)
> > > >>         compList.append([(pathName + ".cv[%s][%s]")%
> > > >>
> (openMaya.MScriptUtil().getInt(u),openMaya.MScriptUtil().getInt(v))])
> >
> > > > this was never intended to be a correct usage of MScriptUtil, you
> should
> > > > not save instances of "asPtr" return values.
> > > > instead, you save instance of MScriptUtil, e.g.
> >
> > > > u=om.MScriptUtil()
> >
> > > > then pass asPtr value to functions
> >
> > > > compItr.getIndex(u.asIntPtr(),v.asIntPtr())
> >
> > > > then retreive the value with
> >
> > > > om.MScriptUtil.getInt(u.asIntPtr())
> >
> > > > --
> > > > Viktoras
> > > >www.neglostyti.com
> >
> > > > --
> > > >http://groups.google.com/group/python_inside_maya
> >
> > > --http://groups.google.com/group/python_inside_maya
> >
> > --http://groups.google.com/group/python_inside_maya
>
> --
> http://groups.google.com/group/python_inside_maya
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to