I've been playing around with DriverTarget data_path in a script. The data path, from the target.id object for the x location could be either "location.x" or "location[0]"

Is there a way of determining the name of the axes in different vector classes, like Vector ("xyz"), Quaternion("wxyz"), Color("rgb") ... or "hsv" and so on.

Currently I'm just hardcoding a lookup table.

  • $\begingroup$ not sure if I understand the question right. Do you want to feed object.location[0] somewhere into a function and get "location.x" returned? $\endgroup$
    – aliasguru
    Aug 4, 2016 at 11:33
  • $\begingroup$ yeah I'll put some sample code in to clarify. Basically yeah.. how do I know that x is index 0 of obj.location. $\endgroup$
    – batFINGER
    Aug 4, 2016 at 12:50
  • $\begingroup$ d=[1.0, 2.0, 3.0] / v=Vector(d) / for c in "xyz": print(d.index( getattr(v,c))) ? $\endgroup$
    – lemon
    Aug 4, 2016 at 14:42
  • $\begingroup$ I still need to know it's "xyz" would fail for color.r = color(0) would need to be "rgb" and quaternion.w = q(0) from "wxyz". If I hard code in the lookup table its just "rgb".index("r") ... but how do I know its "rgb"? at the moment I check that it's a Color class and then assoc that with "rgb"... is there a way of getting "rbg" from the class? $\endgroup$
    – batFINGER
    Aug 4, 2016 at 14:51
  • $\begingroup$ if you look at mathutils_Vector.c line 2330 that seems to be an indication that there is no information from Python (of course this is just an hypothesis...)... Same thing for color, line 805 $\endgroup$
    – lemon
    Aug 4, 2016 at 15:09

1 Answer 1


Guess you've tried this already, so forgive me if it doesn't suit your needs. It's also using hardcoding via a dictionary, the test runs based on the type of the property and the axis to test on:

import bpy
from mathutils import Vector, Color, Euler, Quaternion

classMap = {

def returnIndex(_driverProp, _axis):
    dictVal = classMap[type(_driverProp)]

print (returnIndex(bpy.context.object.rotation_quaternion, 'y'))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .