1

When a custom property is updated, this function is triggered and changes the boolean value of all the 10 others. It's a long and dirty code... is there better way to do it ?

def swap(prop):
    s = bpy.context.scene
    if prop == 'meshes':
        v = not s.meshes
        s.meshes = not v
        s.lights = v
        s.cameras = v
        s.nurbs = v
        s.lattices = v
        s.empties = v
        s.texts = v
        s.bones = v
        s.surfaces = v
        s.metaballs = v
        s.fields = v
    elif prop == 'lights':
        v = not s.lights
        s.meshes = v
        s.lights = not v
        s.cameras = v
        s.nurbs = v
        s.lattices = v
        s.empties = v
        s.texts = v
        s.bones = v
        s.surfaces = v
        s.metaballs = v
        s.fields = v
    elif prop == 'cameras':
        v = not s.cameras
        s.meshes = v
        s.lights = v
        s.cameras = not v
        s.nurbs = v
        ... and so on (11 times)
Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Nikos_VSE
  • 419
  • 4
  • 14
  • 3
    Have a look at this set up for custom properties. http://blender.stackexchange.com/a/39624/15543 – batFINGER Jan 21 '17 at 10:14
  • Wow, that's super smart ! With Zeffii's answer I already saved 100+ lines. With yours, I save 100 more ! What a treat ! – Nikos_VSE Jan 21 '17 at 12:33

1 Answers1

3

something like this

def swap(prop):
    s = bpy.context.scene
    v = not getattr(s, prop)

    attributes = 'meshes lights cameras nurbs lattices empties texts bones surfaces metaballs fields'.split(' ')
    for attribute in attributes:
        setattr(s, attribute, not v if prop == attribute else v)

but achieving pythonic code is a quest for a different stack exchange site, like stack overflow

zeffii
  • 39,634
  • 9
  • 103
  • 186