Use Vector type data with Python?

Use Vector type data with Python?

Anonymous
Not applicable
445 Views
2 Replies
Message 1 of 3

Use Vector type data with Python?

Anonymous
Not applicable
Hi,

Pretty new user here...
I was wondering if there is a way to this :


def assignColor(colorR,colorG,colorB):
cmds.setAttr('material.outColor',colorR,colorG,colorB,type="double3")
assignColor(0.2,0.4,0.5)


like this,


def assignColor(vectorRGB):
cmds.setAttr('material.outColor',vectorRGB,type="double3")
assignColor(0.2,0.4,0.5) #this is not working, ... how to declare this kind of data ????


Thx for any help.
grunt
0 Likes
446 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hi Sam,

I never touched Python in Maya so far and it's still very high on my agenda but I use it a lot in motionbuilder.

Your little function here can't handle your vector variable because you did not use it as a vector variable, just the name indicates that you want it to be one. 😉

Let me explain:

assignColor(0.2,0.4,0.5) // you give the function three numbers

def assignColor(vectorRGB): // but you just can handle one! because you only have the vectorRGB variable

In this case if you try to print vectorRGB for evaluation in your function, it would either give you the first value 0.2 or nothing. As you try to give three single values to the function, it can't handle it with only one variable at hand.

Solution:

In motionbuilder you can use a vector variable by declaration as followed:

FBVector3D(0.2,0.4,0.5) // these are your values, which are stored as a vector variable

To get access to the values you just have to ask by index like with arrays, e.g. FBVector3D, FBVector3D, FBVector3D.

In terms of motionbuilder syntax your script snippet would look like this:

def assignColor(vectorRGB):
cmds.setAttr('material.outColor',vectorRGB,vectorRGB,vectorRGB,type="double3")
assignColor(FBVector3D(0.2,0.4,0.5))


Get it? 😉



Cheers,

Chris
0 Likes
Message 3 of 3

Anonymous
Not applicable
hey thanks for the tip.
Yes it's working great.
Sam
0 Likes