In Blender 2.8 API the requirements for the class and their identifiers naming are becoming tougher. The class name must match the following convention:
1 |
UPPER_CASE_{SEPARATOR}_mixed_case |
Where the {SEPARATOR} is two letters denoting the class belonging to a certain type (from which type the class is inherited):
- HT – Header
- MT – Menu
- OT – Operator
- PT – Panel
- UL – UI list
The class identifier “bl_idname” mast match the class name.
Examples of valid class names and identifiers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class MYADDON_OT_my_operator(bpy.types.Operator): bl_idname = 'myaddon.my_operator' ... class MYADDON_MT_my_menu(bpy.types.Menu): bl_idname = 'MYADDON_MT_my_menu' ... class MYADDON_HT_my_header(bpy.types.Header): bl_idname = 'MYADDON_HT_my_header' ... class MYADDON_PT_my_panel(bpy.types.Panel): bl_idname = 'MYADDON_PT_my_panel' ... |
If class name or identifier doesn’t meet the conventions, Blender signals with error:
‘Oscurart Files Tools’ doesn’t contain ‘_PT_’ with prefix & suffix
My class names have been completely haywire and I never saw any errors. Where would these be printed? E.g.
class WhateverOperator(bpy.types.Operator):
^ Works fine for me.
Class names convention is not a hard rule, Blender would not be crashed if you don’t use it
You can see all the errors in the system console. In the main menu select Window – Toggle System Console (windows) or run Blender from the terminal window (windows/linux).
I keep finding this inconsstent and its very very confusing. Here an example with Meny type. It returns this ‘enr_mt_notification’ doesn’t contain ‘_MT_’ with prefix & suffix
Yet when i do add a dot say enr.mt_notification, its show the same? Also some operator dont need it and others do, The template example dont have and dont show any issue?!
Here i adjust it to mt.mt_notification and still shows the error.
I also tried this enrich.enr_mt_notification
This name convention is driving me nuts
Checking for instance modal uvmesh template. there is NO _OT_ not in the class name nor the bl_idname, it runs fine
when i do this with this above sample, bam again this error
Heres that sample from blender. class name and id name are totally different. Why does this work without blender nagging about it. I find this so vague and frustrating
Got it working now without the warnings… this is why i find it confusing, its 2 way different implementations. Where as the operator does need a dot but not the prefix or suffix. its feels not consistent to me
Name conversation for operators is different than for menus/panels/etc. Operators required “.” others – no.
I got it to work, no more errors. It wasnt clear for me that the operators were still using the regular naming with the dot. Especially when the errors show “doesnt contain _OT_” prefix. I think i understand it now