3
$\begingroup$

I have been looking at some add-ons written by other users, and noticed that on startup, every object in the scene has custom properties defined automatically, even if the addon is never actually used. How do I go about adding this functionality to my own add-on?

$\endgroup$

1 Answer 1

4
$\begingroup$

Register the property per data type you want (Object, Camera, Light...) in register().

def register():
    
    # Object property
    bpy.types.Object.your_object_property = bpy.props.IntProperty()
    
    # Scene property
    bpy.types.Scene.your_scene_property = bpy.props.IntProperty()
    
    # Camera property
    bpy.types.Camera.your_camera_property = bpy.props.IntProperty()
    
    # Light property
    bpy.types.Light.your_light_property = bpy.props.IntProperty()
    
    #...

def unregister():
    del bpy.types.Object.your_object_property
    del bpy.types.Scene.your_scene_property
    del bpy.types.Light.your_light_property
    del bpy.types.Camera.your_camera_property

    
if __name__ == "__main__":
    register()

Don't forget to remove each property when unregister() is getting called.

$\endgroup$
1
  • $\begingroup$ Yep that's exactly what I was looking for. Thank you! @Cod3R $\endgroup$ Jan 11, 2022 at 14:54

You must log in to answer this question.

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