MayaApi python issue

Hi guys,

I’m trying to get data from fluid shape and stuck on getColors() method.


oFlu = _mapiGetObject( fluidName ) # returns MObject
fnFlu = OpenMayaFX.MFnFluid( oFlu )
        
ptrR = OpenMaya.MScriptUtil().asFloatPtr()
ptrG = OpenMaya.MScriptUtil().asFloatPtr()
ptrB = OpenMaya.MScriptUtil().asFloatPtr()  
        
fnFlu.getColors( ptrR, ptrG, ptrB )

This always returns

Error: TypeError: in method ‘MFnFluid_getColors’, argument 2 of type ‘float *&’

I tried others ways for to produce ‘float *&’, like:

 
import ctypes as ct
ptrR = ct.POINTER(ct.c_float)()

but still does nothing. Could you tell me is this correct way or Maya’s python api just has a bug? Thanks

Maybe try initializing the script util object before you create the pointer.


rParam = maya.OpenMaya.MScriptUtil()
rParam.createFromDouble(0.0)
rPtr = rParam.asFloatPtr()

gParam = maya.OpenMaya.MScriptUtil()
gParam.createFromDouble(0.0)
gPtr = gParam.asFloatPtr()

bParam = maya.OpenMaya.MScriptUtil()
bParam.createFromDouble(0.0)
bPtr = bParam.asFloatPtr()

fnFlu.getColors( rPtr, gPtr, bPtr )

maya.OpenMaya.MScriptUtil(rPtr).asFloat()
maya.OpenMaya.MScriptUtil(gPtr).asFloat()
maya.OpenMaya.MScriptUtil(bPtr).asFloat()

But I’ve only used that code in places that work asking for a float &, never a float*&.

You maybe on the right track with ctypes, but you need to create a float array pointer, not just a single float pointer. Also I would recommend initializing it with some values before you pass it to Maya.

Good luck,

Keir

You maybe on the right track with ctypes, but you need to create a float array pointer, not just a single float pointer. Also I would recommend initializing it with some values before you pass it to Maya.

Keir, thank you for an advice. I suppose, it must be exactly float *&, because this method returns pointers to internal storage color data of fluid container.

according information from help:

This method returns pointers to the storage for the color data in the fluid.

If you modify the data via the pointers returned, you must call the “updateGrid” call or you will not see your changes.

This post isveryinformative.*Thank you!