2
$\begingroup$

☐ 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.

$\endgroup$
3
  • 6
    $\begingroup$ 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 $\endgroup$ – p2or Jul 19 '16 at 15:31
  • $\begingroup$ 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. $\endgroup$ – Adrians Netlis Jul 19 '16 at 15:32
  • 1
    $\begingroup$ 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. $\endgroup$ – TLousky Aug 21 '16 at 7:42
1
$\begingroup$

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
            )
    #...
    #...
$\endgroup$
2
  • 3
    $\begingroup$ 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"] $\endgroup$ – batFINGER Jul 26 '16 at 7:39
  • $\begingroup$ Yes it is confusing. But setting (True, True, True) does not happen in "single selection". $\endgroup$ – golopot Jul 26 '16 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.