Don’t learn Blender Scripting.

Learn how to program instead.

I need to come clean about that title: this is not and anti-Blender rant, you definitely should learn the Blender API if you are so inclined, or need it for skill building or work.

So why did I start with that title, then? Well, because I need your attention, specially the attention of the programming newbies.

Now, I gotta make one thing clear: this post is long and is aimed at those who want to take up coding for serious production. If you don’t like to read long posts, or are not thinking about hacking Blender for production environments, then you can browse away now.

“This post is for warriors. You’re not a warrior, bye!”

A bit of back story.

My name is Jonathan Acosta, I’m a self-taught Web developer. I’ve been the developer behind Blend Swap for the last 5 years.

I started out as a total newb to the craft of coding for the Web. I’ve gained a lot of experience by sheer trial and error. But with every mess up and headache has come great learning and refinement of my hacking skills.

I wrote my first “Hello world!” program in Javascript, back in 2006, while following a simple W3C tutorial on basic website programming. Back then I had to force myself to learn how to read code documentation and API references, it was a constant struggle and I really didn’t have a big goal in mind, other than learning how to program. the next year I tried some Processing, and even wrote some tools for it, which unfortunately are now extinct because of my lack of time for maintenance.

My time with Processing lead me to programming other things later in life, and eventually led me to having my own personal business as a freelance Web developer. It is a job that I enjoy a lot and I hope to keep doing for many years to come. The Web is always changing and putting new challenges in your way, and takes the boredom out of the equation. Plus telling computer what to do feels great. ;)

Now, I gotta be clear: I’m NOT an expert in everything there is to know about writing code, but I do have some insights about software development and I’d like to contribute some words of advice for the newcomers.

So, you wanna script the crap out of Blender?

Many of us will reach the point when Blender won’t be able to do exactly what we want it to do. Many have already gone through that, and now those moments are landmarks for the birth of new, incredible Blender addons, like the epic Retopo Flow and Muscle Tools. These plugins stand out from the rest because they implement functionality that Blender lacks completely, and also because of the very professional user experience you get when using them.

These tools didn’t simply arise from the developers waking up one Saturday morning and simply saying “I’m going to script this awesome new feature for Blender, even though I don’t know anything about coding.”

No. The creators of these and other great tools have honed their skills to the point they are able to get almost anything done with the Blender API. These skills are built on top of one another, in increasing level of complexity and power, from the very basics of what programming is, to very advanced topics like writing your own clever algorithms, classes and libraries.

They needed good working knowledge of the basics of programming principles, the language they’re working on, and the API their software is based upon, in this case Blender’s API.

If you wanna play in the same field, you’ll have to build those same skills, because otherwise you won’t be able to program amazing things, or maintain and fix your code, much less change or customize somebody else’s.

So here are some recommendations for the newbies about how to write great code, from your first “Hello world!” program, to your amazing brand new addon.

1 — Forget about Blender (for now), learn how to program first.

Do you know what a control structure is? A class? An instance? An object? An array? No?, then you should NOT be learning how to script for Blender right now. Instead you should be learning the very basics about programming, what it is and what you can accomplish with it.

Programming is both very easy and very hard, at the same time.

The basics of programming are simple enough that you’ll have a good understanding of them in a month or so. But implementing your desired functionality is sometimes difficult, very difficult; and even more so if you don’t know the basics about writing your own types, functions and classes; instantiating those classes into objects, and using them to accomplish your goals through logic operations, iteration, error handling and debugging.

Did that last paragraph sound like an obscure witchcraft incantation to you? Then you should be learning how to program right now. Believe me, I didn’t say anything obscure up there.

Why am I advising you to learn programming first?

Well, just as a rhetorical exaggeration, I’ve lost the count of how many times I’ve seen users asking this on the Blend Swap Questions section:

How do I learn scripting in Blender?”

I’ve also received PMs about the same topic.

My answer to those questions about how to script for Blender has always been the same:

Learn programming first. THEN learn the Blender API.

Why? Because you won’t be able to adapt your code to changing conditions if you don’t know how to use logical operations with if-else statements; you won’t be able to batch process a bunch of mesh objects if you don’t know how to use a for or while loop; your scripts may become huge, unmanageable, spaghetti-like jumbles of code if you don’t know anything about encapsulation, modularity and single-responsibility code.

What happens when the code you copy-pasted from an old scripting tutorial doesn’t work anymore? Can you effectively read the Blender API documentation in order to fix it on your own? Can you enhance, fix and extend somebody else’s code? Can you add new features to it?

If you learn the basics of programming you will be ready for anything that may come in the future, you’ll be able to change, optimize and even completely re-write entire scripts with better implementation and clever algorithms that otherwise you will never know how to write.

This is a fairly common knowledge hole in the Blender community, but very particularly for BGE-based game developers, they want to make the next gaming big hit, but they mostly have no basic knowledge of programming to achieve that goal, and if there’s one field in 3D that requires you to know programming, that is game development.

Of course there are no culprits to this hole in our knowledge as a community; no one is to blame. Most people have never had the need to know how to code because a great deal of tasks can completed in Blender with mouse actions and keystrokes. Others, I’m sure, are intimidated by just the thought of having to learn how to program.

Also, and as far as I know — and compared to all other Blender education topics out there — , Blender API educational courses and tuts are very scarce; there’s close to zero quality content about programming for Blender[*], while the rest of the program has been extensively covered by awesome education sites like Blender Guru and CG Cookie.

I attribute this to the fact that 3D artists are precisely that, artists. Programming hasn’t been truly needed to produce art until recent years, but nowadays 3D industries like VFX, gaming and data visualization are growing exponentially and they all demand a good grasp of programming from those interested. Beyond this, there is a very clear trend for the future as well: programming will be an integral piece of every part of life, learning how to code will not only help you achieve your current goals, but it will also open better opportunities for you in the future.

2 — You should learn a programming language well.

So now you wanna learn programming. Awesome!

Don’t be intimidated by the task at hand. As I said before it’s easier than you think. But be warned, I also said it is harder than you think, at times, really freaking hard, and one of the contributing factors to having a difficult time learning how to program is the language you choose to learn.

A few years back I started learning C++. It was nearly impossible for me, because while it is tremendously powerful, it is also complex, full of weird syntax and counter intuitive features. I certainly do NOT recommend you trying to learn C++ as your first language; although, if you actually learn it, any other language will be way easier to write compared to it.

We are very lucky about the Blender developers’ choice for the scripting language it supports: Python 3. It is powerful and easy to learn, it comes wrapped up in every Blender installation and you have access to it right there in Blender’s console and text editor.

The logical conclusion is that, if you’re going to script for Blender, but you don’t know how to program, then you should be learning Python.

Now, getting started with Python can be a bit weird if you haven’t written a single line of code yet. So I’ll link you to this awesome online, in-browser Python course on Codecademy. You don’t have to install anything to your computer to follow along, just open the page, signup and complete the course; it will get you started with the basics of programming with Python, it will teach you the very basics: from the primitive data types and control structures; to lists and more complicated types; to loops, functions, classes and methods.

This advice also applies if you’re beginning with Web development and you want to develop your site in, say, CakePHP or Laravel, you should know how to program and also some PHP before you dive into the frameworks, same for Browsers, Node.js and Javascript; Unity and C#, Django and Python, Rails and Ruby.

3 — Whatever course you start, make sure you finish it.

This is an important part of learning how to program. Some topics will be difficult to different people depending on the experience they get out of a course. Eventually you will come to understand those difficult parts, but it is important to have them, at least, mentioned to you in courses and tutorials. Put another way: if you find a topic particularly difficult while learning how to program, don’t skip it, read it anyway, you’ll likely see that topic again in the future; as you’re repeatedly exposed to the concept you become more likely to finally understand what it does and how to use it.

For me, the part I had to go over and over again was Object Oriented Programming (OOP), writing classes was very hard for me at the start because I didn’t understand how the classes related to my code, and how I was supposed to use them; to me it was just a complex and mysterious thing I might never understand. Luckily I kept myself from ignoring it, I felt kept telling myself, maybe if I read it enough times somehow I’ll eventually understand it.

In the end this approach worked, I just needed to be exposed to the concept until the “ah-ha!” moment came to me. I’m still no absolute expert about OOP, but I have a good understanding of how to write and use a well structured class to make my code modular, easy to read and maintainable.

Finishing a course will also give you a great sense of accomplishment: you just went through something that was hard but you pushed your limits, and you came out victorious, you may still have some weak points to work on further, but now you’re not a total newb anymore. And that is something nobody else can do for you. Completing a course is particularly rewarding if the course offers a certificate, even if it’s a symbolic one.

4 — Finally, you should learn the API you need to learn.

For our purposes you wanna learn the Blender API, of course.

Once you’re comfortable writing code in Python it is time to apply your new knowledge to Blender, and to learn it’s extensive API (Application Programming Interface). APIs as the name suggests, are custom function and class interfaces with the environment you’re dealing with (in this case, Blender). An API contains custom classes, functions, objects and data that you can access to instruct the environment to do things for you. Web browsers have APIs too, so when you write Javascript for browsers you’re instructing the Browser to do things for you and your website user’s.

The Blender API facilitates access to the internal objects and data that make Blender tick; by having access to those objects and data you will be able to tell Blender what and how to do things for you, from very simple tasks to completely new features, tools and workflow enhancements.

So learn the Blender API, learn it well, but only after you know how to program. This will reduce your suffering, and your having to post to forums and get no answers because no one else knows how to program. Get familiar with reading documentation, you’ll keep doing it as long as you have to lay down some code.

Now, there’s another thing I have to make clear here: I’ve spent almost no time programming for/in Blender, I’ve seen many code examples and I’ve been able to even enhance other people’s code[**].

Of course, that’s not a big achievement with Blender scripting by any means, but then again, that was something I was able to achieve because I have good working knowledge of how to program and how to read code and documentation; in my opinion, that’s more valuable in programming than anything else.

That’s it! This can (and should) lead to more discussions coding and advice for newcomers; by all means, leave some comments with recommendations and critiques.

Was I too harsh communicating my thoughts? Good.

Do you regard me as a hypocrite for not really knowing the Blender API? That’s probably right, but I don’t care: the main goal of this piece is getting all programming newbies to up their level, so they suffer less when confronted with incomplete documentation, broken code, missing features, deprecated APIs, third party code that needs fixing, debugging nightmares and so on.

Thanks for reading, see you on Python heaven.


  • [*] I’m sure there’s some incredible course about the Blender API out there, if so please let me know.
  • [**] See the green area to the right specially in, line 79 through 89. My enhancement adds Linux clipboard support, Windows and Mac OS X were already implemented.