Skip to content

Instantly share code, notes, and snippets.

@ChemiKhazi
Last active July 6, 2019 15:36
Show Gist options
  • Save ChemiKhazi/4e7a3d7bd0322bb377fc76489f6fd834 to your computer and use it in GitHub Desktop.
Save ChemiKhazi/4e7a3d7bd0322bb377fc76489f6fd834 to your computer and use it in GitHub Desktop.
Blender Add On External IDE Dev Tips

Developing Blender Add Ons with external IDEs

This are small tips on developing Blender add ons using external IDEs like PyCharm.

Location, Location, Location

Developing in Blender's user scripts folders is the easiest way I've found to dev with external IDEs.

Specifically, using the addons_contrib folder.

This folder location depends on your OS, under windows it is in:

%AppData%\Blender Foundation\Blender\<blender_version>\scripts\addons_contrib

You can create a folder that is under version control for your script in the addons_contrib folder.

Your script can be a single python script or a multi file module this way.

Go into Blender's user preferences to enable your add ons, under the testing level.

IDE Setup

You don't have to do anything special, just open the project in the addons_contrib folder.

Hot script reload

Scripts can be hot reloaded in Blender by pressing F8.

If your script is a module, you may have to do something to make hot reload work.

Module reload setup

To make hot reload work, your module should use importlib in the root __init__.py

Below is the code snippet for how Sprytile imports for hot reloading.

# Put Sprytile directory is sys.path so modules can be loaded
import os
import sys
import inspect
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

locals_list = locals()
# check if bpy has been put in locals list yet,
# module reload will have bpy in the list
if "bpy" in locals_list:
	# bring in reload library
    from importlib import reload
	# reload using function
    reload(addon_updater_ops)
    reload(sprytile_gui)
    reload(sprytile_modal)
    reload(sprytile_panel)
    reload(sprytile_utils)
    reload(sprytile_uv)
    reload(tool_build)
    reload(tool_paint)
    reload(tool_fill)
    reload(tool_set_normal)
else:
    from . import sprytile_gui, sprytile_modal, sprytile_panel, sprytile_utils, sprytile_uv
    from sprytile_tools import *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment