Class naming conventions in Blender 2.8 Python API

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:

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:

If class name or identifier doesn’t meet the conventions, Blender signals with error:

‘Oscurart Files Tools’ doesn’t contain ‘_PT_’ with prefix & suffix

5 1 vote
Article Rating
Subscribe
Notify of
guest

8 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Geara
Geara
2 years ago

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.

Last edited 2 years ago by Geara
Nikita
Editor
2 years ago
Reply to  Geara

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).

Rombout Versluijs
Rombout Versluijs
2 years ago

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?!

Rombout Versluijs
Rombout Versluijs
2 years ago

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

Rombout Versluijs
Rombout Versluijs
2 years ago

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

Last edited 2 years ago by Rombout Versluijs
Rombout Versluijs
Rombout Versluijs
2 years ago

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

Nikita
Editor
2 years ago

Name conversation for operators is different than for menus/panels/etc. Operators required “.” others – no.

Rombout Versluijs
Rombout Versluijs
2 years ago
Reply to  Nikita

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