Properly naming things in Python

Over the years I’ve found that programming, being somewhat rigid by nature, can sometimes be less confusing (at least for myself) if I understand fully what parts of a line of code are set in stone, and what parts are names that were created by the author of the code.

For example:

bpy.utils.register_class(myClass)

“myClass” is a portion of the code that I know can be changed, as long as the desired name is within the rules of class naming. “register_class” clearly is not, as that is critical to the function of a given script.

Is there an exhaustive list of naming conventions and what is up-to-the-user vs. what is integral to python in blender?

The code that spurred this question is from an add-on tutorial:

class MYADDON_MT_PIE_template(Menu):

the naming convention for class names makes sense to me, but I know that pie menus are new-ish to Blender. is the “PIE” portion of the above name critical, or was that just the convention of the tutorial author? the separator is “MT_” and then according to what I am reading about naming, everything after that can be “mixed case”. Is “PIE” required?

There are other naming issues I’m seeing, and for the purpose of teaching myself and perhaps helping others, I am interested in learning a bit more.

Thanks.

Hi man,
hope this help you somehow

Well, blender is a big software made of little pieces of codes,
Every piece “Define” a class or a function or a variable…
"These piece are meant to be used with a customizable part " called arguments.

So if you go to this site, you should find all the defined parts of blender that you can use
for example the math functions https://docs.blender.org/api/current/mathutils.html
if you scroll down a bit you can find ----- rotate_axis (axis, angle )

So, someone have written a piece of code called rotate_axis
that need 2 arguments or variables, these are the part that the user is called to fill.
BUT
you can also define your own class and function !
And i have read that you can also override the things in blender
So
i think there isnt really this kind of “user part” and “blender part”

There also some behaviour set in blendder that you can ignore :
for example Blender panels hide and show buttons and property based on the Context of selection and Mode … but a lot of them are only hided, and you can use them too
even if they “were not meant to be used like this”

How properly name classes and operators and panels and stuff is a bit tricky,
Here in this site you can find a good quick info https://b3d.interplanety.org/en/class-naming-conventions-in-blender-2-8-python-api/
As you can see he will not talk about the “idname naming”
That part too have restriction but i dont remember where i can find it
You can use uppercase and lower case in the definition
but the idname must be all lowercase, and the first part before the “.” is not custom,
that must be an existing " mode ? type ? region?" i forgot how is called.

Note that the template “simple operator” in blender dont have the OP but dont give you any error , i am not sure when is needed and when is not.
I always put them to not be bored…

About menu and piemenu,
i discovered that you can call a menu like a pie, and viceversa .


I think is the “display operator” that we are calling to show the menu.
so just adding and removing the _pie will call or not the menu in that style
Layout could be a mess but if you leave it clean it works fine.

1 Like

Thank you! This answers a number of questions for me. I appreciate it.