Learn to Code Blender Features in Python: Add-On Programming Tutorial

preview_player
Показать описание
Learn how to write a new feature for a Blender add-on in this intro to Python operators!

LINKS

Рекомендации по теме
Комментарии
Автор

Just fixed and re-uploaded the tutorial! Thanks for reporting the sync issue 😊
I've seen many beginners struggle to understand how to code a new feature for Blender. That's why in this tutorial I've decided to explain how operators work.
Operators are Blender's mechanism to add new features to the program. They're a base class that supports undoing, mapping to a button or a keyboard shortcut... Operators can seem a little daunting if you're not comfortable with code at first. They mostly revolve around 3 methods:

1. poll lets you control when an operator can or cannot run. You return true if you want your feature to be accessible from Blender, from the spacebar search menu, buttons... If you return False from this method, you won't be able to find or use the feature. The idea is you check for what the user is doing and return True or False based on the current context.
2. invoke is called by Blender when the user clicks a button or uses a keyboard shortcut to use your feature. This method tells you which key the user pressed and gives you access to the mouse position. It's optional, you typically use it to make some calculations and storing values before calling the next method, execute.
3. execute is called by Blender when you run your feature from code, but you can also run it after invoke. This is where you'll put the core of your feature.

There's more to learn and to say about operators. You can create interactive tools with the operators' fourth common method, modal. But that's beyond the scope of this tutorial.

If you have questions about the video or how Blender's Python API works in general, please ask!
If you want to improve your Python-fu, submit a patch, and I'll personally help you improve your code, explain the things you may struggle with... 🙂

Gdquest
Автор

You and your team must be the head of the Blender VSE department. Keep doing great work with Power Sqeuencer. Don't know the last situation but hope you are gonna figure out the multithread video rendering soon. .Thanks!

emrahciftci
Автор

Is there a way to add inputs to the operator?
Like for example I have a script that I made to a function that requires a int or float input.And I want that to be different depending on different button, for example:
I load the simple operator template, I replaced the "main" function with mine.And added my function to the execute function inside the new operator class.But when I run that new operator it asks for that function input.The only workaround is to hardcore that input in the execute function...like let's say my function is called my_function and to make the operator work is to have my_function(5).

But this means that for every button I make I have to make a new operator if I want the buttons to execute my_function(1), my_function(2), my_function(3) etc. Is there a way to avoid creating tons of operators for one simple input dependent function?

NikolaNevenov
Автор

Don't you have to register the operator in the __init__ file? or it's magic that your setup automatically does? :)

premiero
Автор

Nice vid! Btw, how can we link and use bpy module in an external IDE?

rddepartment
Автор

I can not understand, you work on Windows or Linux?)

romanryazh