# Blender 2.9 - Python - define addon properties

I checked Batex addon source code and other sources on internet

Is there no safer way to define properties?

I mean, what if an addon sets the same property in Scene for instance ?

bpy.types.Scene.apply_transform = BoolProperty(name="Apply transform",
default=True,
description="Applies scale and transform (Experimental)")


• I think this is a topic for devtalk.blender.org Apr 26 at 9:58
• This is not bad design, as in any programming language the potential namespace collisions have to be handled by the programmer, not by the language. Apr 26 at 11:03

This is definitely not a problem unique to Blender, nor even to Python. It's an old enough problem that it has been called by the name name collision for at least 30 years.

Wikipedia lists three of the well know methods of dealing with it. I'll enumerate others. None of them are perfect.

1. Renaming - the least desirable. When you find the name you are using collides you simply change it.

2. Prefixing - Try to find a unique prefix that you routinely use on your names, in the hopes of avoiding collisions. This is the oldest technique used for name collision among separate libraries in large systems.

3. Encapsulation - Wikipedia calls this 'namespaces', but namespaces are a language specific implementation of encapsulation. There are other ways to accomplish it, as mentioned in another answer.

Often these three approaches are intermixed. This answer describes an approach where one form of encapsulation (enclosure in an object that hides the names) is combined with one form of prefixing.

Here are approaches not mentioned in Wikipedia:

1. prefix registration - Prefixes are only a partial solution because prefixes can collide. To avoid this, there are situations where name collision is avoided by requiring prefixes to be registered on a first come first served basis. This is not widely used in programming, because it administratively difficult. It is routinely used in networking, where name collisions are far more likely.

2. Guid assignment A Globally Unique Identifier (GUID) solves the administrative problem of prefix registration by automating the generation of such IDs. Microsoft uses this approach in some of their products, for instance.

• Python should avoid these javascript-like nonsenses. I have been suggested to use addon preferences or property groups
– Phil
Apr 27 at 10:03
• @Phil neither of these things solve the problem. Add-on names can collide. Apr 27 at 13:50
• well I understand the issue, a hash could be generated randomly and blender would just deal with it...anyway I just want to avoid adding stuffs in blender "built in" data. thx
– Phil
Apr 28 at 15:40

I always try to use add-on name in such properties and pack them into property group

__init__.py

• I'm sure you're aware of it but in python, class names should be CamelCase by convention. It's not enforced but it made me double take how you could set a variable as a type in the PointerProperty Apr 26 at 11:06