Quick Mpoint Question

i started workin with python yesterday, and i am absolutely amazed by the EXTREME flexibility that it has, yes i have fallen in love!!

focus isam focus! back to the point, i am trying to set a an MPoint to specific numbers i got from a file, but the initializing is workin if i set the number manually, like
point = OpenMaya.MPoint(0,0,0,1)

but if i try to set it up tthru a variable,

point = OpenMaya.MPoint(coordinates)
(coordinates is an array of size 4)

i get this error,

# Error: in method 'new_MPoint', argument 1 of type 'float const [4]'
# Traceback (most recent call last):
# File "", line 1, in
# File "C:\engserv\rbuild\208\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 5278, in __init__
# TypeError: in method 'new_MPoint', argument 1 of type 'float const [4]' #

i know its sth really easy, but i wish i cld get some help here

thnx folks

QUOTE(isam @ 11/08/07, 09:45 AM) [snapback]276186[/snapback]
point = OpenMaya.MPoint(coordinates)
(coordinates is an array of size 4)

i get this error,
# Error: in method 'new_MPoint', argument 1 of type 'float const [4]'
# Traceback (most recent call last):
# File "", line 1, in
# File "C:\engserv\rbuild\208\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 5278, in __init__
# TypeError: in method 'new_MPoint', argument 1 of type 'float const [4]' #

Yeah, you can't exactly do this ... the constructor is expecting individual floats. Fortunately, you can "explode" the array. I personally don't see this in a lot of Python code (possibly for a good reason - I'm not sure), but here you go:

c = [ 1.1, 2.2, 3.3, 4.4 ]
p2 = maya.OpenMaya.MPoint( *c )

Cheers!

thanks 4 the response, but this doens t work either, the problem seems to be coming fro mthe variable, as if i set the c to

c = [ coordinates[0], coordinates[1], coordinates[2], coordinates[3]]

i seem to be getting the same error as before

# Error: in method 'new_MPoint', argument 1 of type 'double'
# Traceback (most recent call last):
# File "", line 1, in
# File "C:\engserv\rbuild\208\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 5278, in __init__
# TypeError: in method 'new_MPoint', argument 1 of type 'double' #

your apparently trying to pass in worng types (such as int or string whan you need double)? This happens sometimes between non/strongly typed interfaces.

If you just domp your data it dont get cast as far as i know but im not sure. i never use the * because it contains a slight caveat.

yup that was it, was passin it as a string instead of a float! thnx m8