Color parm in python

   1956   3   0
User Avatar
Member
24 posts
Joined: 10月 2014
Offline
Hi,

I'm using Python to output a description of a scene to a game specific format.
Almost everything works fine, except Vector3 and Vector4 values.

For instance, I need to output a color value as a float array. To iterate all of a node's parameters, I'm using:

for p in n.parms():

But when iterating, my “ColorFactor” parameter appears as for distinct float values, like in this printout:

ColorFactorr = 1
ColorFactorg = 0
ColorFactorb = 0
ColorFactora = 1

Instead of what I expected…
ColorFactor = (1,0,0,1)

Before I come up with a complicated solution (like iterating twice, the first time only to manually group related parameters), its there a simple way to ‘group’ each vector component into a single tuple or something like that?

Thanks!
Edited by Ethernaut - 2018年5月5日 23:06:43
User Avatar
Member
8520 posts
Joined: 7月 2007
Offline
use n.parmTuples() instead of n.parms()
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
24 posts
Joined: 10月 2014
Offline
Great, that's exactly what I needed!

One wrinkle is that my parameters are in folders, and for some reason parmTuple doesn't have the containingFolder() function, so I had to change the code to use:

for t in n.parmTuplesInFolder(("FolderName",)):

Took me a while because of the weird “trailing comma” tuple syntax for the folder name… at least weird for someone not familiar with Python like me! It fails if you just pass a single folder name without the trailing comma.

Works now though.
Thanks!
Edited by Ethernaut - 2018年5月6日 02:47:29
User Avatar
Member
8520 posts
Joined: 7月 2007
Offline
That's true for Python tuples in general, just to distinguish whether (1) is a tuple or just a number in parentheses, so single element tuples have comma (1,)

But you can easily use single element list instead, they don't need comma

So in your case
["FolderName"]
Edited by tamte - 2018年5月6日 03:15:04
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links