PDA

View Full Version : [API] getScale() method in Python


Narann
03-30-2009, 11:30 AM
Hi all, I have a prob and I con't solve it... :shrug:

I need help...

Here is my code:
if obj.hasFn(OpenMaya.MFn.kTransform):
fn = OpenMaya.MFnTransform(obj)
S = (0.0, 0.0, 0.0)
print fn.getScale(S)
And the error is:
// Error: line 1: in method 'MFnTransform_getScale', argument 2 of type 'double [3]'
# Traceback (most recent call last):
# File "C:/Plugins/04_fonctionSetCmd.py", line 23, in doIt
# self.outputTransform(obj)
# File "C:/04_fonctionSetCmd.py", line 40, in outputTransform
# print fn.getScale(S)
# File "C:\engserv\rbuild\195\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 3217, in getScale
# TypeError: in method 'MFnTransform_getScale', argument 2 of type 'double [3]' //
It's a question of type... I know there is a MScriptUtil class and I've try it but it doesn't help me... I'm a "codeur du dimanche" (as we said in France) so if you have a sugestion, don't hesitate... ;)

Thanks in advance and have a good day!

Narann
03-31-2009, 08:50 AM
I've found the solution: Thanks to Adam Mechtley (http://www.6ixsetstudios.com/)!

if obj.hasFn(OpenMaya.MFn.kTransform):
fn = OpenMaya.MFnTransform(obj)

# First create an array and a pointer to it
scaleDoubleArray = OpenMaya.MScriptUtil()
scaleDoubleArray.createFromList( [0.0, 0.0, 0.0], 3 )
scaleDoubleArrayPtr = scaleDoubleArray.asDoublePtr()

# Now get the scale
fn.getScale( scaleDoubleArrayPtr )

# Each of these is a decimal number reading from the pointer's reference
x_scale = OpenMaya.MScriptUtil().getDoubleArrayItem( scaleDoubleArrayPtr, 0 )
y_scale = OpenMaya.MScriptUtil().getDoubleArrayItem( scaleDoubleArrayPtr, 1 )
z_scale = OpenMaya.MScriptUtil().getDoubleArrayItem( scaleDoubleArrayPtr, 2 )

# Print the scale out nicely
print ("Scale: (%f, %f, %f)" % (x_scale, y_scale, z_scale))
And his own explaination (better than mine ;) ):
The problem is that your variable S is a tuple. What the function requires is a pointer to a double3 array. Because Python does not really have the concept of pointers, you must use the MScriptUtils class.
So the problem is solve. I hope it will help someone.

Have a good day!

Dorian :wavey:

cbamber85
03-31-2009, 03:50 PM
Thanks! That's answered my question.

Narann
03-31-2009, 04:17 PM
Glad it can help you. ^^

CGTalk Moderation
03-31-2009, 04:17 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.