1

I want to create an addon that have some presets to make it settings more easy to edit and remember global properties.

I would like how to make an preset menu to acess global properties and define its initial settings when the addon is installed for first time.

It can simplify and give more fexibility for my addon, I'm still using an enumProp and too much IFs for this method and with presets I belive it can be collapsed in a single block.

This is the update function of my code, as can see it is very long and inflexible. complete version can be found in :https://github.com/jeacom25b/BlenderSolidLightsInToolsTab/blob/master/Solid_Ligths_Protoshader.py

def studio_update(self, context):
    if context.scene.solid_lights_studio_enable == False:
        return None

    lights = context.user_preferences.system.solid_lights
    scene = context.scene
    f_dcol = scene.solid_lights_studio_front_diffcol
    f_scol = scene.solid_lights_studio_front_speccol
    b_dcol = scene.solid_lights_studio_back_diffcol
    b_scol = scene.solid_lights_studio_back_speccol
    h_shift = scene.solid_lights_studio_back_hueshift

    b_dcol_hp = Vector((b_dcol[0] + (h_shift[0] - 0.5) * 0.5,
                        b_dcol[1] + (h_shift[1] - 0.5) * 0.5,
                        b_dcol[2] + (h_shift[2] - 0.5) * 0.5))

    b_dcol_hm = Vector((b_dcol[0] - (h_shift[0] - 0.5) * 0.5,
                        b_dcol[1] - (h_shift[1] - 0.5) * 0.5,
                        b_dcol[2] - (h_shift[2] - 0.5) * 0.5))

    f_dcol_hp = Vector((f_dcol[0] * 0.7 + (h_shift[0] - 0.5),
                        f_dcol[1] * 0.7 + (h_shift[1] - 0.5),
                        f_dcol[2] * 0.7 + (h_shift[2] - 0.5)))

    f_dcol_hm = Vector((f_dcol[0] * 0.7 - (h_shift[0] - 0.5),
                        f_dcol[1] * 0.7 - (h_shift[1] - 0.5),
                        f_dcol[2] * 0.7 - (h_shift[2] - 0.5)))

    if context.scene.solid_lights_studio_type == '2K1F':
        dir = context.scene.solid_lights_studio_direction
        back_dir = Vector((-dir.x, -dir.y, -dir.z + 1))
        fill_dir = Vector((dir.x, dir.y, dir.z + 0.5))
        lights[0].direction = dir
        lights[1].direction = fill_dir
        lights[2].direction = back_dir
        lights[0].diffuse_color = f_dcol
        lights[0].specular_color = Vector((f_scol[0] / 2,
                                           f_scol[1] / 2,
                                           f_scol[2] / 2,))
        lights[1].diffuse_color = Vector((
            b_dcol_hp[0] * 0.25 + f_dcol[0] * 0.25,
            b_dcol_hp[1] * 0.25 + f_dcol[1] * 0.25,
            b_dcol_hp[2] * 0.25 + f_dcol[2] * 0.25))
        lights[1].specular_color = Vector((b_scol[0] / 5,
                                           b_scol[1] / 5,
                                           b_scol[2] / 5))
        lights[2].diffuse_color = b_dcol_hm
        lights[2].specular_color = b_scol

    if context.scene.solid_lights_studio_type == '1K2FW':

        dir = context.scene.solid_lights_studio_direction
        rotation_euler1 = Euler((0, 0, 1), "XYZ")
        rotation_euler2 = Euler((0, 0, -1), "XYZ")
        back_dir1 = Vector((-dir.x * 2, -dir.y * 2, -dir.z + 0.9))
        back_dir1.rotate(rotation_euler1)
        back_dir2 = Vector((-dir.x * 2, -dir.y * 2, -dir.z + 0.9))
        back_dir2.rotate(rotation_euler2)
        lights[0].direction = dir
        lights[1].direction = back_dir1
        lights[2].direction = back_dir2
        lights[0].diffuse_color = f_dcol
        lights[0].specular_color = f_scol
        lights[1].diffuse_color = b_dcol_hp
        lights[1].specular_color = b_scol
        lights[2].diffuse_color = b_dcol_hm
        lights[2].specular_color = b_scol

    if context.scene.solid_lights_studio_type == '1K2FM':

        dir = context.scene.solid_lights_studio_direction
        rotation_euler1 = Euler((0, 0, 1), "XYZ")
        rotation_euler2 = Euler((0, 0, -1), "XYZ")
        back_dir1 = Vector((-dir.x * 2, -dir.y * 2, -dir.z + 0.5))
        back_dir1.rotate(rotation_euler1)
        back_dir2 = Vector((-dir.x * 2, -dir.y * 2, -dir.z + 0.5))
        back_dir2.rotate(rotation_euler2)
        lights[0].direction = dir
        lights[1].direction = back_dir1
        lights[2].direction = back_dir2
        lights[0].diffuse_color = Vector((f_dcol[0] * 1.2,
                                          f_dcol[1] * 1.2,
                                          f_dcol[2] * 1.2))
        lights[0].specular_color = Vector((f_scol[0] * 2,
                                           f_scol[1] * 2,
                                           f_scol[2] * 2))
        lights[1].diffuse_color = b_dcol_hp
        lights[1].specular_color = Vector((f_scol[0] * 2,
                                           f_scol[1] * 2,
                                           f_scol[2] * 2))
        lights[2].diffuse_color = b_dcol_hm
        lights[2].specular_color = Vector((f_scol[0] * 2,
                                           f_scol[1] * 2,
                                           f_scol[2] * 2))

    if context.scene.solid_lights_studio_type == '1K2F':

        dir = context.scene.solid_lights_studio_direction
        rotation_euler1 = Euler((0, 0, 1.69296), "XYZ")
        rotation_euler2 = Euler((0, 0, -1.69296), "XYZ")
        back_dir1 = Vector((dir.x * 2, dir.y * 2, 0.5))
        back_dir1.rotate(rotation_euler1)
        back_dir2 = Vector((dir.x * 2, dir.y * 2, 0.5))
        back_dir2.rotate(rotation_euler2)
        lights[0].direction = dir
        lights[1].direction = back_dir1
        lights[2].direction = back_dir2
        lights[0].diffuse_color = f_dcol
        lights[0].specular_color = f_scol
        lights[1].diffuse_color = b_dcol_hp
        lights[1].specular_color = b_scol
        lights[2].diffuse_color = b_dcol_hm
        lights[2].specular_color = b_scol

    if context.scene.solid_lights_studio_type == '2K1FR':

        dir = context.scene.solid_lights_studio_direction
        dir = context.scene.solid_lights_studio_direction
        rotation_euler1 = Euler((0, 0, 0.5), "XYZ")
        rotation_euler2 = Euler((0, 0, -0.5), "XYZ")
        front_dir1 = Vector((dir.x * 1.3, dir.y * 1.3, dir.z))
        front_dir1.rotate(rotation_euler1)
        front_dir2 = Vector((dir.x * 1.3, dir.y * 1.3, dir.z))
        front_dir2.rotate(rotation_euler2)
        back_dir = Vector((-dir.x, -dir.y, -dir.z + 1))
        lights[0].direction = front_dir1
        lights[1].direction = front_dir2
        lights[2].direction = back_dir
        lights[0].diffuse_color = f_dcol_hm
        lights[0].specular_color = f_scol
        lights[1].diffuse_color = f_dcol_hp
        lights[1].specular_color = b_scol
        lights[2].diffuse_color = b_dcol
        lights[2].specular_color = b_scol

    return None

How can I make this?

  • In order to store OpenGL light settings? See my comment below you last question: http://blender.stackexchange.com/questions/74766/how-to-acess-and-change-solid-opengl-lights-settings-via-python#comment130920_74766 Can you share what you've done so far? (probably the reason for the downvote) – p2or Mar 07 '17 at 11:58
  • @poor Thanks for the alert, I edited the question. – StackOverflowToxicityVictim Mar 07 '17 at 20:58
  • This answer has an example of how to make a custom menu, use the properties set callback to do something when the user selects another item. – sambler Mar 08 '17 at 01:27

1 Answers1

1

Blender has a preset system you can use: see the API documentation

batFINGER
  • 84,216
  • 10
  • 108
  • 233
ideasman42
  • 47,387
  • 10
  • 141
  • 223