Skip to content

Instantly share code, notes, and snippets.

@L0Lock
Last active June 9, 2023 06:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L0Lock/838a9d83066f0420ff930b137201f848 to your computer and use it in GitHub Desktop.
Save L0Lock/838a9d83066f0420ff930b137201f848 to your computer and use it in GitHub Desktop.
Sublime Text build environment for Blender Addons
{
"cmd": "build_addon.py",
"working_dir": "$project_path",
"windows" : {
"shell": true
}
}
import shutil
import os
from distutils import dir_util, file_util
# Target folder where to copy the addon's content.
# I use a custom directory to avoid having to reinstall addons at each new Blender version
# If you want to do the same, don't forget to add that path to Blender > Edit menu > Preferences > File Paths tab > Scripts
targetFolder="C:\\AppInstall\\Blender\\MyScripts\\addons\\"
# Input files and folders. See examples from lines 16 to 19
# Folders will be copied with their full content.
# Put them between '' marks, coma between elements, one per line.
# You can write in absolute and relative paths, I chose relative for simplicity.
inputFiles=['import_synkscetch_notes.py',
'example folder',
'example/sub/folder',
'example file'
]
for src in inputFiles:
print(f'Copying "{src}" to "{targetFolder}"')
if os.path.isdir(src):
dir_util.copy_tree(src, targetFolder, preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=1, verbose=1, dry_run=0)
elif os.path.isfile(src):
file_util.copy_file(src, targetFolder, preserve_mode=1, preserve_times=1, update=1, link=None, verbose=1, dry_run=0)
else:
print(f'"{src}" not found, skipping...')
pass
@L0Lock
Copy link
Author

L0Lock commented Sep 9, 2022

I personally work in my repository, but then need to copy my addon files to Blender's addons folder.
To make this quick, I set Sublime Project Folder according in my repository.

Then, thanks to this duo of build_addon.py file and custom Build System, I just have to hit ⎈ CtrlB to copy everything to Blender.

How to set up:

A - The build system

  1. Put Blender Addon.sublime-build in Sublime Text's build system folders.
    Or alternatively:

    1. In Sublime Text, go to Tools > Build System > New Build System
    2. Paste the content of Blender Addon.sublime-build and save it as "Blender Addon.sublime-build` in the folder already setup by Sublime Text.
  2. Sublime Text, go to Tools > Build System, choose Blender Addon.

B - The repository

  1. If not done already, open you repository folder in Sublime Text (i recommend you to save it as a project).

  2. In your addon repository base folder, put the build_addon.py file.

  3. Open it with Sublime Text to set up which files can be copy-pasted and where.
    The files and folder to copy are defined as in lines 16 to 19, follow the examples to make your own list of files/folder.
    The target folder where to paste your addon is on line 5.
    I use a custom directory to avoid having to reinstall addons at each new Blender version and have them all centralized in one place, easy to use.
    If you want to do the same, don't forget to add that path to Blender > Edit menu > Preferences > File Paths tab > Scripts:

    preferences

C - Usage

Anytime you work on an addon repository in Sublime Text, make sure you set the build system to Blender Addon.
Hit ⎈ CtrlB when you want to copy your stuff to Blender's addons folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment