Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonNordon4 committed Aug 6, 2024
1 parent c950a1d commit ebec89b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 61 deletions.
Binary file removed .git.zip
Binary file not shown.
49 changes: 0 additions & 49 deletions generate_addon.py

This file was deleted.

Binary file added images/addon_manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 75 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
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 <[email protected]>"
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.
1 change: 0 additions & 1 deletion template/readme.md

This file was deleted.

4 changes: 3 additions & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ebec89b

Please sign in to comment.