diff --git a/.git.zip b/.git.zip deleted file mode 100644 index 0e5b892..0000000 Binary files a/.git.zip and /dev/null differ diff --git a/generate_addon.py b/generate_addon.py deleted file mode 100644 index 8d55712..0000000 --- a/generate_addon.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -import shutil - -addon_name = "test_addon" -source_dir = './template/' -dest_dir = f'./{addon_name}/' - -# Automatically determine the capitalized replacement without spaces -addon_name_capitalized = ''.join(word.capitalize() for word in addon_name.split('_')) - -search_replace_pairs = { - "template": addon_name, - "Template": addon_name_capitalized -} - -def replace_in_file(file_path, search_replace_pairs): - with open(file_path, 'r') as file: - content = file.read() - for search, replace in search_replace_pairs.items(): - content = content.replace(search, replace) - with open(file_path, 'w') as file: - file.write(content) - -def process_directory(source_dir, dest_dir, search_replace_pairs): - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - - for root, dirs, files in os.walk(source_dir): - relative_path = os.path.relpath(root, source_dir) - dest_path = os.path.join(dest_dir, relative_path) - - if not os.path.exists(dest_path): - os.makedirs(dest_path) - - for file in files: - src_file = os.path.join(root, file) - dest_file = os.path.join(dest_path, file) - shutil.copy2(src_file, dest_file) - replace_in_file(dest_file, search_replace_pairs) - -def generate_files(): - process_directory(source_dir, dest_dir, search_replace_pairs) - - # Process the entry.py file at the same level as this script - entry_file = 'entry.py' - if os.path.exists(entry_file): - replace_in_file(entry_file, search_replace_pairs) - -generate_files() diff --git a/images/addon_manager.png b/images/addon_manager.png new file mode 100644 index 0000000..5c5f4f0 Binary files /dev/null and b/images/addon_manager.png differ diff --git a/readme.md b/readme.md index 0a2a1cc..3278091 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,79 @@ -https://simonnordon4.github.io/blender-extensions/index.json +# Use Github as a Blender Extension Repository -blender --command extension server-generate --repo-dir=E:\repos\blender-extensions\ --html +## Setting up the Repo. -Compress-Archive -Path ".\hello-world" -DestinationPath "hello-world.zip" -Force +1. Create a new repository on Github. +2. Turn it into a github page. Settings -> Pages -> Source -> Main -1. Create a new directory for the extension. -2. Compres the directory into a zip file. -3. Run blender extension command. -4. Upload the zip file to the server. -5. Ensure repo is public and a website page. +## Creating the Addon. -References: - https://docs.blender.org/manual/en/latest/advanced/extensions/creating_repository/static_repository.html \ No newline at end of file +1. Create a new directory for the addon. +2. add a ```blender_manifest.toml``` file with this code: +```toml +schema_version = "1.0.0" +id = "id_of_your_addon" +version = "1.0.0" +name = "Name of your addon" +tagline = "This is a very cool Add On" +maintainer = "Your Name " +type = "add-on" +tags = ["Object"] +blender_version_min = "4.2.0" +license = [ + "SPDX:GPL-2.0-or-later", +] +``` +3. Add a ```__init__.py``` file with this code: +```python +def register(): + print("Hello World") +def unregister(): + print("Goodbye World") +``` +4. Zip your addon subdirectory. +```bash +Compress-Archive -Path ".\id_of_your_addon" -DestinationPath "id_of_your_addon.zip" -Force +``` +5. Use Blender command line to generate the extension. +```bash +blender --command extension server-generate --repo-dir={REPO_DIR} --html +``` + +6. Push your changes. + +7. Get the github page url to your index.json, it will look something like this: +```html +https://{GITHUB_USER_NAME}.github.io/{REPO_NAME}/index.json +``` + +8. Add the url to the Blender preferences -> Get Extensions -> Repositories -> Add -> Paste the url. + +## Theory + +The new blender extensions allows you to create a static repository, allowing blender to download and update addons from a url. + +https://docs.blender.org/manual/en/latest/advanced/extensions/creating_repository/static_repository.html + +Github allows us to create a webpage from our repository, by doing this, we can give Blender the url our github page, and it will be able to download and update our addons as we push changes. + +The index.json is a catalog of all addons in the repository (there can be multiple). It does this by pointing to the zip files of each of the addons. + +In order for the zip files to be recognized as addons, they need to have a ```blender_manifest.toml``` file, which contains metadata about the addon, and a ```__init__.py``` file, which is the entry point of the addon. + +I wont go into how addons work, all you need to know is that when an addon is enabled, the register function is called, and when it is disabled, the unregister function is called. This is the starting point for every addon. + +## Using this repo to get started. + +This repository contains additional files that make it easier to get started creating addons. + +By running ```ui.py``` you will get a window that allows you to create a new addon, as well as building your extensions. + +![Image of custom ui](/images/addon_manager.png) + +```Create Addon from Template``` will create a new subdirectory with the necessary files to get started. + +```Zip Addons``` will zip all valid subdirectories in a zip file. + +```Build Blender Extensions``` Will run the blender command to generate the index.json + +```entry.py``` is an optional script that allows you to run an addons code from an attached blender instance without installing the addon. This is useful when actively developing an addons and making changes quickly. \ No newline at end of file diff --git a/template/readme.md b/template/readme.md deleted file mode 100644 index 523aba9..0000000 --- a/template/readme.md +++ /dev/null @@ -1 +0,0 @@ -Compress-Archive -Path ".\template" -DestinationPath "template.zip" -Force \ No newline at end of file diff --git a/ui.py b/ui.py index ce29716..21c58bf 100644 --- a/ui.py +++ b/ui.py @@ -65,15 +65,17 @@ def create_addon_from_template(): def zip_addon(): base_dir = os.getcwd() # Directory where your add-ons are located + ignored_dirs = {"template", ".git", "images"} for item in os.listdir(base_dir): item_path = os.path.join(base_dir, item) - if os.path.isdir(item_path) and item != "template": + if os.path.isdir(item_path) and item not in ignored_dirs: zip_name = os.path.join(base_dir, f"{item}.zip") if os.path.exists(zip_name): os.remove(zip_name) # Remove the existing zip file if it exists with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf: for root, dirs, files in os.walk(item_path): + dirs[:] = [d for d in dirs if d not in ignored_dirs] # Filter out ignored directories for file in files: file_path = os.path.join(root, file) arcname = os.path.relpath(file_path, base_dir)