How to create a Boolean Vector property that is “single selection”?

☐ x
☐ y
☑ z

class MyAddon(bpy.types.Operator):
...
axis =  bpy.props.BoolVectorProperty( subtype="XYZ" )
...


This operator is added to menu, now the BoolVectorProperty is multiple selection by default, how do I make it single selection? I want only one value to be True at one time.

I have tried getter and setter, but cannot make it right.

• Both seems not possible with a BoolVectorProp, (not easy at least). I'd suggest use an EnumProperty: gist.github.com/p2or/c40e33ca6f524198e120d9b48463d2f2 with expand=True to get this: i.stack.imgur.com/MDhY4.png – p2or Jul 19 '16 at 15:31
• Can you access user input(sorry, I don't know anything about bpy so I can only guess)? Try force setting it all to False and than applying True to the user selection. – Adrians Netlis Jul 19 '16 at 15:32
• Should be possible with an update function and saving the previous state of the bool vector, but as @poor said, it'll be easier to achieve this with an Enum. – TLousky Aug 21 '16 at 7:42

I managed to create a "single selection" boolean vector. It use getter and setters. An auxiliary variable is used to store the value of the property, otherwise setting the property inside the setter would recursively call setter which calls setter which calls setter...

AXIS_VALUE = [0,0,1]

class Foo(bpy.types.Operator):
#...
#...

def getter(self):
return AXIS_VALUE

def setter(self, value):
for i in range(3):
AXIS_VALUE[i] = {
(False, False) : False,
(False, True) : True,
(True, True) : False,
(True, False) : False,
}[AXIS_VALUE[i], value[i]]

axis = BoolVectorProperty(
subtype="XYZ",
default=(0,0,1),
get = getter,
set = setter
)
#...
#...

• Yuck, I'd avoid this. If I set blah.axis = (True, True, True), then it sets it to (True, True, False) and if set to all true again it gives me (False, False, True). (via the console, single UI press might be Ok-ish-ish) Would go with @poors enumprop suggestion. If the enumprop has 'X', 'Y' and 'Z' as values, the boolvector is simply [ep == axis for axis in "XYZ"] – batFINGER Jul 26 '16 at 7:39
• Yes it is confusing. But setting (True, True, True) does not happen in "single selection". – golopot Jul 26 '16 at 8:21