using divide maya api


#1

hello i am trying to use divide for an MFloatPoint and MFloatVector

i have used subtract successfully:

diff_list.append(om.MFloatPoint(p2)-om.MFloatVector(p1))

but how can you successfully use divide?:

ratio=om.MFloatPoint(p1) / om.MFloatVector(p2)

it gives this back, im not sure what i need to do:
in method ‘MFloatPoint___div__’, argument 2 of type ‘float’ #

could someone let me know how this works?

thanks,
Sam


#2

The div function on an MFloatPoint expects only a scalar argument. For example:

import maya.api.OpenMaya as om

p = om.MFloatPoint(1.0,1.0,1.0)
p = p / 2
print p

If you really want to divide MFloatPoint by another MFloatPoint you’ll need to do it manually. That division operation is also ambiguous, but I’m assuming that you want it to behave in the same manner as the subtraction operation. So to do that you could write it like this:

import maya.api.OpenMaya as om

p1 = om.MFloatPoint(1.0,1.0,1.0)
p2 = om.MFloatPoint(2.0,2.0,2.0)

p3 = om.MFloatPoint(p1.x/p2.x, p1.y/p2.y, p1.z/p2.z)
print p3