-
Notifications
You must be signed in to change notification settings - Fork 229
Closed
Labels
Description
I like this add-on, and I want to share one concern.
issue
I've noticed you have a few very generic variable names registered directly into bpy.types.Scene.*
This increases the probability that your properties will interfere with other add-ons registering properties in Scene. It's nice to code a bit defensively here.
solution.
You can register a property collection / property group to keep all properties under your own namespace
See the docs, (tho I feel these are a bit rubbish)
import bpy
## some panel somewhere
def draw(self, context):
self.layout.prop(context.scene.my_prop_grp, 'custom_1')
class MyPropertyGroup(bpy.types.PropertyGroup):
custom_1 = bpy.props.FloatProperty(name="My Float")
custom_2 = bpy.props.IntProperty(name="My Int")
def register():
bpy.utils.register_class(MyPropertyGroup)
bpy.types.Scene.my_prop_grp = bpy.props.PointerProperty(type=MyPropertyGroup)
def unregister():
bpy.utils.unregister_class(MyPropertyGroup)
# deleting the group, removes automatically all children. :)
del bpy.types.Scene.my_prop_grp
or like this..
class SomeAddonProperties(bpy.types.PropertyGroup):
@classmethod
def register(cls):
Scn = bpy.types.Scene
Scn.some_addon_props = PointerProperty(
name="some addon's internal global properties",
description="some add-on uses these properties for shared properties between operators",
type=cls,
)
cls.custom_1 = bpy.props.FloatProperty(name="My Float")
cls.custom_2 = bpy.props.IntProperty(name="My Int")
@classmethod
def unregister(cls):
del bpy.types.Scene.some_addon_props
def register():
...
bpy.utils.register_class(SomeAddonProperties)
def unregister():
...
bpy.utils.unregister_class(SomeAddonProperties)