Hi Marcus,

Somehow I missed cmdx!! Will totally take a look!
I looked at API 2.0 but as, for some obscure reasons, it still does not
include MfnIkJoint (it's been 5years now since its release, and still not
in the 2021 preview), this is a no go for me and I don't like switching api
within the same function...

Thanks for the tips!



On Wed, Mar 25, 2020 at 6:28 PM Marcus Ottosson <konstrukt...@gmail.com>
wrote:

> This is why god created API 2.0…
>
> from maya.api import OpenMaya as om
>
> sl = om.MSelectionList()
> sl.add('joint1')
> node = sl.getDependNode(0)
> joint = om.MFnTransform(node)
> print(joint.scale())
>
> And why I created cmdx <https://github.com/mottosso/cmdx>...
>
> import cmdx
> joint = cmdx.encode("joint1")
> joint["scale"] = [1, 2, 3]
>
>
> On Wed, 25 Mar 2020 at 14:39, Nicolas Chaverou <
> nicolas.chave...@golaem.com> wrote:
>
>> Ok, inspecting the API with the good old dir command, I figured a
>> MScriptUtil_setFloat3ArrayItem entry
>> Which led me here:
>> https://download.autodesk.com/us/maya/2011help/API/class_m_script_util.html
>>
>> Problem solved.
>> Here's the fixed code for reference:
>>
>> import maya.OpenMaya as om
>> selList = om.MSelectionList()
>> selList.add('joint1')
>> oNode = om.MObject()
>> selList.getDependNode(0, oNode)
>> joint = om.MFnTransform(oNode)
>>
>> # create reference array
>> util = maya.OpenMaya.MScriptUtil()
>> util.createFromDouble(0.0, 0.0, 0.0)
>> ptr = util.asDoublePtr()
>> joint.getScale(ptr)
>>
>> scale = [util.getDoubleArrayItem(ptr, 0), util.getDoubleArrayItem(ptr,
>> 1), util.getDoubleArrayItem(ptr, 2)]
>> print(scale)
>>
>> As the documentation mentions:
>>
>> *This class is admittedly cumbersome to use but it provides a way of
>> building parameters and accessing return values for methods which would not
>> normally be accessible from Python. *
>>
>> Cumbersome is the right word indeed.
>> Will probably hide this with some binding functions in my module
>>
>> N.
>>
>> On Wed, Mar 25, 2020 at 3:19 PM Nicolas Chaverou <
>> nicolas.chave...@golaem.com> wrote:
>>
>>> Hey guys,
>>>
>>> That's probably a silly question but I've been wondering this for a
>>> while and always figured something else, but now i'm kinda stucked. Using
>>> Maya 2018 / Windows
>>>
>>> How do get/set small arrays within the Python API ?
>>> For example, MfnTransform has the following function prototype:
>>> MStatus
>>> <https://download.autodesk.com/us/maya/2009help/API/class_m_status.html>
>>>   getScale
>>> <https://download.autodesk.com/us/maya/2009help/API/class_m_fn_transform.html#a142c550cb690c8e1f4a3a15a75fa627>
>>> (double scale[3]) const
>>>
>>> And when calling it from the Python API returns the same prototype:
>>>
>>> in method 'MFnTransform_getScale', argument 2 of type 'double [3]' //
>>>
>>>
>>> According to SWIG documentation
>>> <http://www.swig.org/Doc1.3/Python.html#Python_nn62> (which Autodesk
>>> used for its Python bindings), one should use tuples to do it (but it has
>>> to be implemented on the API side)
>>>
>>> Here is what I tried:
>>>
>>>
>>> import maya.OpenMaya as om
>>>
>>> selList = om.MSelectionList()
>>> selList.add('joint1')
>>> oNode = om.MObject()
>>> selList.getDependNode(0, oNode)
>>> joint = om.MFnTransform(oNode)
>>> scale = (0, 0, 0)
>>> joint.getScale(scale)
>>>
>>> But I always get the following error:
>>>
>>> # TypeError: in method 'MFnTransform_getScale', argument 2 of type
>>> 'double [3]' //
>>>
>>> Tried with [], [0, 0, 0], om.MFloatArray(), None... but was never able
>>> to query that property correctly. What's the supposed way of making this
>>> work ? Or does it just nit work at all and I'm obliged to use PyMel for
>>> those ?
>>>
>>> Any insights appreciated
>>> N.
>>>
>> --
>> 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/CAFS5DCZtXtL8yiTgS_X5oj_3gvGuzsExhe_YtKjf4k6rNEvS5g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAFS5DCZtXtL8yiTgS_X5oj_3gvGuzsExhe_YtKjf4k6rNEvS5g%40mail.gmail.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/CAFRtmOCg5naTCfapu%3D9Re5%3DZrAt3feZMLc%3DY9RVe_m7dSpKsbg%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCg5naTCfapu%3D9Re5%3DZrAt3feZMLc%3DY9RVe_m7dSpKsbg%40mail.gmail.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/CAFS5DCZP9TMoroJcVY1wTygHz4NpvFn4HD0TqY_7z6GHJGMdpw%40mail.gmail.com.

Reply via email to