Useful utils for deploying blender addons
Utility for auto-incrementing Blender addon version
- -path - path to
__init__.py
in the root of addon folder - -index - version (0,0,0) index to increment: 0 or 1 or 2 etc. Default: last index
- -encoding - file encoding (UTF-8, SYSTEM). Default: UTF-8
__init__.py
bl_info = {
"name": "My Script",
"version": (1, 0, 0)
}
- Command:
BlenderAddonAutoIncrement.exe -path Path\To\__init__.py
- Result:
bl_info = {
"name": "My Script",
"version": (1, 0, 1)
}
- Command:
BlenderAddonAutoIncrement.exe -path Path\To\__init__.py -index 0
- Result:
bl_info = {
"name": "My Script",
"version": (2, 0, 0)
}
Utility for deploying addon source as a valid Blender addon zip package
- Copies addon src folder to temporary directory, ignoring python cache files etc.
WARNING!!! Copy algorithm is based on robocopy mirror folder command. Be sure that you've filled target directory correctly!
- Packs temporary addon folder as Blender addon zip package
- Gives version number name prefix
- -addonDir - path to addon directory
- -addonName - addon name. Default: name of 'addonDir'
- -tempDir - temporary directory for creating zip content. Default: User Temp Dir
- -targetZipDir - path to output zip dir
- -targetZipName - addon zip literal name or variable: AUTO_GENERATE (Default)
- -copyParams - params for using in robocopy. Default:
/MIR /XD .git .svn __pycache* /XF *.log *.md /R:3 /W:3
- -onBeforeZipCMD - path to batch script that will be executed before packing temp folder into zip file
- Command:
BlenderAddonZip.exe -addonDir C:\blender\blender-addons\magic_uv -targetZipDir c:\addons\build
- Result:
c:\addons\build\magic_uv_6_5_0.zip
- Command:
BlenderAddonZip.exe -addonDir C:\GitHub\MyAddon\Src -addonName MyAddon -targetZipDir C:\GitHub\MyAddon\Build
- Result:
C:\GitHub\MyAddon\Build\MyAddon_1_0_0.zip
WARNING! Check target folder because it is based on robocopy mirror function
- Command:
BlenderAddonZip.exe -addonDir C:\GitHub\MyAddon\Src -copyParams "/MIR /XD .git .svn __pycache* ico /XF *.log *.md *.dll /R:3 /W:3" -targetZipDir C:\GitHub\MyAddon\Build
- Result:
Folders:
.git
,.svn
,__pycache*
,ico
and files*.log
,*.md
,*.dll
are excluded
C:\GitHub\MyAddon\Build\MyAddon_1_0_0.zip
Suppose that you want to change file content in temporary folder before it will be packed into zip folder. In this case you may create batch script and pass its path as parameter -onBeforeZipCMD.
- Command:
BlenderAddonZip.exe -addonDir C:\blender\blender-addons\magic_uv -targetZipDir c:\addons\build -onBeforeZipCMD c:\Scripts\beforeZipCMD.script
- Example: c:\Scripts\beforeZipCMD.script
First parameter in batch script is the path to temporary folder!
echo 'Before Zip %1'
set _dir=%~1
powershell -Command "(gc -Path '%_dir%/vlog.py') -replace 'ENABLE_DEBUG = True', 'ENABLE_DEBUG = False' | sc -Path '%_dir%/vlog.py'"
This command will replace text ENABLE_DEBUG = True
by ENABLE_DEBUG = False
in the file Path\To\AddonTempDir\vlog.py
Expected: after hit build command Shift+Ctrl+B
:
- increment addon version number
- pack as zip in build folder
- put BlenderAddonAutoIncrement.exe, BlenderAddonZip.exe to any system path location or use full path to them
- create tasks.json in .vscode folder
{
"version": "2.0.0",
"tasks": [
{
"label": "Increment Build",
"command": "BlenderAddonAutoIncrement.exe",
"args": [
"-path",
"${workspaceFolder}/Src/__init__.py"
],
"type": "shell"
},
{
"label": "Deploy Build",
"command": "BlenderAddonZip.exe",
"args": [
"-addonDir",
"${workspaceFolder}/Src",
"-addonName",
"MyAddon",
"-targetZipDir",
"${workspaceFolder}/Build"
],
"type": "shell"
},
{
"label": "Build",
"dependsOrder": "sequence",
"dependsOn": [
"Increment Build",
"Deploy Build"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}