An MScriptUtil object shouldn't care, since it is a Python object. What
matters is what you tell SWIG it is, not how you construct it in Python. If
the API wants a reference to a double, but you pass a float ptr, it won't
like it. You'll notice, for instance, that there's only createFromInt():
there is no createFromShort(), createFromLong(), createFromUInt(), etc.
because they're all the same as far as Python is concerned. Likewise,
MScriptUtil.getInt(), MScriptUtil.getShort(), MScriptUtil.getBool(), etc.
all return an int, because Python doesn't discriminate. It really doesn't
even bother Python if you create from a decimal and request it as an int—it
will handle the conversion. For instance:

u = om.MScriptUtil()
u.createFromInt(5)
om.MScriptUtil.getInt(u.asIntPtr()) # this will return 5
om.MScriptUtil.getDouble(u.asDoublePtr()) # this will return 5.0
om.MScriptUtil.getDouble(u.asIntPtr()) # this will not work, since
MScriptUtil.getDouble requires an argument of type double &, while
u.asIntPtr() is of type int &

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

> But that also brings me back to the initial scripts.
>
> u=om.MScriptUtil()
> u.createFromInt(0)#correct usage?
> v=om.MScriptUtil()
> v.createFromInt(0)#correct usage?
> compItr.getIndex(u.asIntPtr(),v.asIntPtr())
> om.MScriptUtil.getInt(u.asIntPtr())
>
> OK so if I use createFromInt and just feed it an arbitrary value to
> allocate the space, is that correct? what do I have to consider when
> doing that? if the number may have a value like 20 instead of 2, do I
> need to do createFromInt(100) or something to give it adequate space?
>
> Brandon L. Harris
>
>
>
>
>
>
> On May 13, 1:36 pm, Brandon Harris <[email protected]> wrote:
> > OK so when I do this
> >
> > u=om.MScriptUtil()
> > u.createFromInt(0)
> >
> > the u.asInt is equal to 0.
> >
> > so when I do that I need to do
> >
> > u.createFromInt(Value That Will Be Used)
> >
> > On May 13, 1:28 pm, Adam Mechtley <[email protected]> wrote:
> >
> >
> >
> > > 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
> >
> > --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