1
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ In order to store OpenGL light settings? See my comment below you last question: blender.stackexchange.com/questions/74766/… Can you share what you've done so far? (probably the reason for the downvote) $\endgroup$
    – p2or
    Mar 7, 2017 at 11:58
  • $\begingroup$ @poor Thanks for the alert, I edited the question. $\endgroup$ Mar 7, 2017 at 20:58
  • $\begingroup$ 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. $\endgroup$
    – sambler
    Mar 8, 2017 at 1:27

1 Answer 1

1
$\begingroup$

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

$\endgroup$

You must log in to answer this question.

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