2

Blender Wiki notes the following about bl_idname convention.

BlenderWikiAddon

"For headers, menus and panels, the bl_idname is expected to match the class name (automatic if none is specified).

Valid Examples:

class OBJECT_OT_fancy_tool (and bl_idname = "object.fancy_tool")
class MyFancyTool (and bl_idname = "MYADDON_MT_MyFancyTool")

" In other Blender Python documentation I noted also: PythonDocumentationPanel

class HelloWorldPanel(bpy.types.Panel): bl_idname = "OBJECT_PT_hello_world"

and

class PanelOne(View3DPanel, bpy.types.Panel): bl_idname = "VIEW3D_PT_test_1"

I struggle to grasp how all these are valid as the demand is "expected to match the class name".

Can you shade light on the convention or refer me to the right source, so I know how and when to use Upper, Lower, Mix case?

donbonbon
  • 107
  • 1
  • 14
  • 1
    https://blender.stackexchange.com/questions/124095/what-do-new-bpy-class-naming-conventions-in-blender-2-80-actually-mean – batFINGER Feb 24 '21 at 10:45
  • Also this is the same but more direct: https://b3d.interplanety.org/en/class-naming-conventions-in-blender-2-8-python-api/ – Psyonic Feb 24 '21 at 10:47
  • the document states UPPER_CASE_{SEPARATOR}_mixed_case. Below in the valid exemples it shows: bl_idname = 'myaddon.my_operator' and bl_idname = 'MYADDON_MT_my_menu'... But how the lower case example is also valid? – donbonbon Feb 24 '21 at 14:34
  • @Psyonic the document states UPPER_CASE_{SEPARATOR}_mixed_case. Below in the valid exemples it shows: bl_idname = 'myaddon.my_operator' and bl_idname = 'MYADDON_MT_my_menu'... But how the lower case example is also valid? – donbonbon Feb 24 '21 at 19:01
  • I don't know why, you'll have to ask the developers, maybe @batFINGER knows, but the operators use 'lowercase.my_operator' and the rest use 'UPPERCASE_XX_my_name' (note the dot verses underscore) From what I've used, anything will work, Blender will complain but not break, it's just for convention so we're all talking the same language for projects with multiple people working on them. – Psyonic Feb 25 '21 at 07:21
  • 1
    Having a hard time to understand your question. MyFancyTool as well as MyFancyPanel is valid because of PEP8: https://www.python.org/dev/peps/pep-0008/#class-names However, the recommended way is the one you've already found in the release notes, CUSTOM_PT_myPanel or CUSTOM_OT_myOperator for the class name. When it comes to operators, the most important thing to note is that they can be called using bpy.ops.* ... bpy.ops + namespace + your name to classify whether it is an operator for meshes, lights, cameras or whatnot, bpy.ops.namespace.my_fancy_tool(). Does this help? – brockmann Feb 25 '21 at 15:32
  • Best practice (and blender convention) prefers class names to be camel case HelloWorldPanel When a class is registered, it is known to blender via its bl_idname (in template example case) bpy.types.OBJECT_PT_hello Can leave out the bl_idname and it registers as bpy.types.HelloWorldPanel (with the warning) which is undesirable, particularly if for instance it was named "Panel" (wont reg, but imagine the hassles if it did) Hence for panels and menus my suggestion is stick to using a bl_idname with the convention, rather than the alternate of class naming via convention. – batFINGER Feb 26 '21 at 02:47

0 Answers0