hi, Justin 
  thanks for your reply and your code , after I got someone's help , it is 
about the parameter pointer issues between C++ and Python, which needs 
MscriptUtil() to solve , the blow code works finally .


import maya.OpenMaya as om

mColor=om.MColor(123,222,122)

uti0=om.MScriptUtil()
uti0.createFromDouble(0.0,0.0,0.0)
ptr_0=uti0.asFloatPtr()

mColor.get(ptr_0)

print uti0.getFloatArrayItem(ptr_0,1)
print uti0.getFloatArrayItem(ptr_0,2)
print uti0.getFloatArrayItem(ptr_0,3)


On Tuesday, 27 December 2022 at 21:39:47 UTC+8 hwee li wrote:

> test
>
> On Tuesday, 27 December 2022 at 11:13:52 UTC+8 justin...@gmail.com wrote:
>
>> Working with Maya arrays and wrappers between Python and C++ is not 
>> always intuitive. Would it be easier to just grab the value as needed?
>>
>> import maya.OpenMaya as omi
>>
>> col = omi.MColor(1.0, 0.5, 0.25)
>> # tuple
>> rgb = col.r, col.g, col.b
>> # If you need MFloatArray
>> arr = omi.MFloatArray(3)
>> arr[0], arr[1], arr[2] = rgb
>>
>>
>>
>> On Mon, Dec 26, 2022 at 10:46 PM hwee li <internet...@gmail.com> wrote:
>>
>>> hi, can I know how to get the Out value from maya.OpenMaya API correctly 
>>> ?
>>>
>>> for example, I read the Maya document about MColor object, it has a 
>>> function get() which can output color value to an array. 
>>> MColor.Get() 
>>> <https://download.autodesk.com/us/maya/2011help/API/class_m_color.html#5c0286da6e453c2b492610ef59a12d80>
>>>
>>> but in python, when I tried to create an array like 
>>> *array=[0.0,0.0,0.0] *
>>> or use maya api 
>>> *array= MFloatArray(3)*
>>>
>>> then run the get function from a MColor object 
>>>
>>> *colorObject.get(array)* 
>>>
>>> maya will give me an error `
>>> "in method 'MColor_get', argument 2 of type 'float [3]"` 
>>> it seems that the array object I created is not the correct type for 
>>> output value to write in, anyone know how to fix this, I know there is a 
>>> better way in API 2.0 , but I hope to figure out how to solve this kind of 
>>> output value type for API1.0 in python .
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to python_inside_m...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/python_inside_maya/5d08ac61-058d-4575-b55f-f63fb20eaf40n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/python_inside_maya/5d08ac61-058d-4575-b55f-f63fb20eaf40n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/adc2584e-d59f-400b-8119-368b42b38e90n%40googlegroups.com.

Reply via email to