Chris Conlan

Data Scientist

  • About
  • Blog
    • Business Management
    • Programming with Python
    • Programming with R
    • Automated Trading
    • 3D Technology and Virtual Reality
  • Books
    • Fast Python
    • Algorithmic Trading with Python
    • The Blender Python API
    • Automated Trading with R
  • Snippets
  • Opportunities

The Best Way to Develop Blender Python Add-ons

June 26, 2017 By Chris Conlan 7 Comments

When I began developing with Blender Python, I used the text editor that was built in to the Blender GUI. I did this for way too long without realizing how inefficient it was. After talking to a few veteran developers, I learned that the best way to develop Blender Python is outside of Blender.

Background

Most educational resources on Blender Python are fairly introductory, meaning they assume the audience comes from a position of zero experience. When we want to get people interested in Blender Python, we want ease-of-use and minimal setup time. This has led to the championing of Blender’s native text editor. While the text editor is convenient, it is not suitable for large-scale add-on development.

The text editor is in the top right of the Blender “Scripting” view.

For an in-depth discussion of why the Blender Text Editor is not suitable for large-scale development, see Chapter 7 of my book, The Blender Python API. In this article, we will discuss how to set up common lightweight text editors (Sublime Text, Atom, Notepad++) to develop Blender Python in its own filesystem. This is superior for a multitude of reasons, including portability, dependence safety, and organization.

Where Add-ons Live in Blender

Open your filesystem and navigate to Blender’s installation directory. For Blender 2.78c, the add-on files are found in blender-2.78c/2.78/scripts/addons/, where blender-2.78c is the name of the root directory of the Blender installation. In the addons/ directory, you will find every add-on that is installed on your version of Blender. Some are single scripts, some are flat directories, and some are complex multi-level directories.

To begin developing add-ons directly in Blender’s filesystem, simply open your favorite IDE, and open a project in blender-2.78c/2.78/scripts/addons/ or blender-2.78c/2.78/scripts/addons/my_fresh_new_addon/.

Creating a Loading a Minimal Add-on from the Filesystem

The first script you will need is __init__.py. Go ahead and create this file in your new add-on directory, and paste this into it:

bl_info = {
	"name": "My Add-on Sandbox",
	"author": "Chris Conlan",
	"version": (1, 0, 0),
	"blender": (2, 78, 0),
	"location": "View3D",
	"description": "In-filesystem Add-on Development Sandbox",
	"category": "Development",
}

def register():
	pass

def unregister():
	pass

From there, open Blender and navigate to add-on tab in the user preferences (File -> User Preferences -> Add-ons). Hit “Refresh” or press F8 to have Blender scan the addons/ directory and load all valid add-ons. You should see your new add-on in the Development tab.

The New Workflow

Go ahead and check off the box next to your add-on in the user preferences window. This will load your add-on and notify you of any compile errors in the console.

Excellent! Now we have a workflow. The F8 key refreshes and re-compiles (if necessary) the list of add-ons, and the active add-ons. Now, when you change your add-on in your IDE, save it, swap to Blender, and hit F8 to view your changes. If your add-on fails to compile for any reason, the console will let you know.

Summary

While I love seeing all the cool tutorials out there on the Blender Python API, I do not want developers to feel discouraged by Blender’s text editor. The development process is much easier and cleaner when developing outside the Blender GUI.

The information in this article is important, but not altogether useful for those that are not familiar with the Blender Python API already. I encourage those interested to check out my new book, The Blender Python API for more information.

Filed Under: 3D Technology and Virtual Reality, Programming with Python

Comments

  1. Brian Korsedal says

    March 29, 2018 at 4:52 am

    Hi,

    I’m an artist and programmer. Your book sounds interesting. I live in the Philippines, so getting a hard copy is going to be difficult and expensive. Could I paypal you some $’s and you email me a pdf?

    Reply
    • Chris Conlan says

      April 2, 2018 at 7:43 pm

      Hi Brian,

      You can purchase the eBook as a PDF here:
      https://www.springer.com/us/book/9781484221778

      Best,
      Chris

      Reply
  2. Todd Vance says

    April 17, 2018 at 2:38 pm

    TL; DR: where is the bmesh module?

    I have the book Blender Python API and am working through it now. I wanted to use something better than Blender’s built-in text editor so I am trying to get things like autocomplete, etc. to work in Eclipse.

    I was able to get Eclipse /Pydev to recognize the bpy module by doing:

    Windows->Preferences->Interpreters->Python Interpreters->Libraries and adding the path:

    C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules

    which contains the bpy module.

    However I cannot get eclipse to recognize the bmesh module. The only directory I can find in the Blender installation named “bmesh” is in:

    C:\Program Files\Blender Foundation\Blender\2.79\scripts\startup\bl_operators

    which I added to the libraries in Eclipse, but that does not seem to be it.

    Any ideas?

    TIA.

    Todd

    Reply
    • Chris Conlan says

      April 18, 2018 at 7:39 pm

      Hi Todd,

      Thanks for checking out the book!

      I struggled with this as well, but I ultimately settled by living without autocomplete in my IDE. This has the added benefit of not displaying defunct and/or “private” methods of Blender’s API in the autocomplete dialogues.

      My suspicion is that bmesh is an aliased module and would not play well with Eclipse’s autocomplete tools.

      For exploring the API and accessing autocomplete, I recommend using the Blender terminal at the base of the development window.

      Best,
      Chris

      Reply
  3. Ron says

    November 30, 2019 at 12:19 pm

    Hi Chris,
    I’m contemplating buying your Blender Python API book, but got to wondering how much of what’s covered has changed since 2.80 (and now, 2.81) got boots on the ground. Could you please give me some idea?

    Reply
    • Chris Conlan says

      December 7, 2019 at 7:04 pm

      You should be mostly good. The topics covered in my book are some of the most core features of Blender, so I don’t imagine much changed across a few minor versions.

      Reply
  4. Glen says

    December 3, 2020 at 9:25 pm

    Can you please help me make a line tool for Blender? Like in CAD programs. I’m just a beginner but wanna make a free extension everyone can use if they like.

    Reply

Leave a Reply Cancel reply

Latest Release: 3D Modeling

The Blender Python API by Chris Conlan

Available for purchase at Amazon.com.

Featured: Business Management

Alteryx for Good Teams Up with University of Virginia to Support New Class: STAT 4559

Programming topics by programming language in open-source repos of big companies

The Best Language for XYZ: Answered Empirically

Gilmer Claire UVA Biology Department

TPM for Biologists: My Experience with a UVA Bio Lab

Topics

  • 3D Technology and Virtual Reality (8)
  • Automated Trading (9)
  • Business Management (9)
  • Chris Conlan Blog (5)
  • Computer Vision (2)
  • Programming with Python (16)
  • Programming with R (6)
  • Snippets (8)
  • Email
  • LinkedIn
  • RSS
  • YouTube

Copyright © 2021 · Enterprise Pro Theme On Log in