-
Developing blender addons can be a serious pain, especially when the code base is large.
-
Blenders internal text-editor is quite lacking and although there are some powerful addons out there to improve the experience, sometimes you just want to work in an IDE that you love.
-
There is no obvious way to link up your IDE to blender that allows a fast workflow
- This document showcases a blender-pycharm workflow that I have personally stumbled upon that may or may not ease your troubles.
-
Obviously you should have both blender and Pycharm installed on your machine
-
Find a suitable folder where you can put all your addon development work. This folder will have a special format that will allows us to link it to blender.
-
Once you've made the folder, add three sub-folders into it - addons, modules and startup.
-
Next we will link this folder to blender. i.e Blender will always know how to find this folder
-
Now we are going to setup PyCharm. Hold on to your socks
-
First of we want to create some pre-definitions for pycharm , so that it won't bother us with loads of errors when developing addons for blender
-
Create another folder somewhere you like and download the pypredef_gen.py file that is in this repo into that folder.
-
Now we are going to run this script, but we will do it with blender.
-
Find the path to your Blender executable.
Something like : - 'C:\program files\blender\blender.exe', or - '/usr/bin/blender'
-
Run this command: path/to/blender/executable -b -P "path/to/pypredef_gen.py"
replace 'path/to/blender/executable' with path from step 9 replace 'path/to/pypredef_gen.py' with path to that file
-
Step 10 will create some folders like this:
-
Now that we have pre-definitions, we can go over the steps you will have to take to develop blender addons with pycharm
-
Create a new pycharm project - this will be your addon.
-
Now this is important. You will want to create this project in the first folder that we created, under addons. This is where you will develop all your addons.
i.e: if your first-folder was called 'blender-addons', your project should be under : "blender-addons/addons/"
-
-
To set the pre-definitions for the project:
NOTE: You will have to do this for all your blender-addon projects
-
Now we will finalize the setup and smoothen the workflow.
-- First up is -> How to run the addon.
a) If you set up the first folder properly, anytime you create a new addon project as in step 13, The addon will automatically be imported to blender.
- thats the magic of the first folder.
b) If you open blender, go to the user preferences under addons, you can enable it. It will remain enabled for the entire development.
c) To keep refreshing the addon while you develop, you will need to keep restarting blender. Luckily we can create a run configuration in pycharm for exactly this.
d) In your pycharm project root folder, create a new script called start_blender.py
e) Add the following 2 lines:
import os os.system("path/to/blender/executable")
f) Right-click on the file in the project tree and navigate to "Create 'start_blender.py'"
g) Now anytime you run the project , it will open blender which will reload your addon.
h) For some more goodies, you may want to start blender with some given settings every time e.g a layout.
Create a start.blend file with all your settings and save it in the root of your project Now modify your start_blender.py: import os os.system("path/to/blender/executable start.blend") Now everytime you run blender, it will open the .blend file with your settings.
-
Finally make your cool addon.
This is certainly alot of work to do, which is why its not for everyone.
If you are working with a huge multiple file/ multiple package addon, you should be able to appreciate the value of this workflow like I have.
- If your blender has slow startup time - "Your screwed"
- All blender output is delayed by pycharm until the program exits
- No debugging - obviously.