2
$\begingroup$

For example, when the custom addon is loaded, the value of bpy.context.scene.world.use_sky_paper is expected to be True, where its default value is False in blender.

Setting it in UI (the draw function) will cause an error, while writing an operator to set it will need users to toggle it explicitly. Can I have the behavior that the default value is True when blender is first opened. Thanks.

$\endgroup$
  • 1
    $\begingroup$ Something like blender.stackexchange.com/a/23230/15543 .... setting up an onload handler to set world.use_sky_paper = True ?? $\endgroup$ – batFINGER Jun 1 '17 at 14:21
  • $\begingroup$ @batFINGER while the thought was to enable it when the addon is enabled, a persistent on file load handler would be a better idea. $\endgroup$ – sambler Jun 1 '17 at 14:29
  • $\begingroup$ Actually both would need to be setup, the load_post handler doesn't alter the existing file. $\endgroup$ – sambler Jun 1 '17 at 14:35
3
$\begingroup$

A way of automate it could be to use an Application Handler, I think one of the scene update handlers would be the best fit. As you only want to alter the value once I would have the handler remove itself once it has done it's task.

As batFinger pointed out, it would also be useful to setup a persistent handler that will set the value when another file is loaded.

bl_info = {"name": "Set property", "version": (1, 0), "location": "blender",
    "description": "Test a way of setting a default property.",
    "warning": "Only testing", "category": "Test",
    }

import bpy
from bpy.app.handlers import persistent

@persistent
def setIt(scene):
    scene.world.use_sky_paper = True
    bpy.app.handlers.scene_update_pre.remove(setIt)

def register():
    bpy.app.handlers.scene_update_pre.append(setIt)
    bpy.app.handlers.load_post.append(setIt)

def unregister():
    bpy.app.handlers.load_post.remove(setIt)

if __name__ == "__main__":
    register()
$\endgroup$

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.