How to generate an image when you push a Blender Python script
In this tutorial we will show you how to generate an image based on a
Python script using the great
Blender
3D application.
This will allow you to automatically have an up-to-date image
available for your users just by pushing your Python script.
Go to
My repositories / Create
and create a private repository named
blendergraph.
Go to
Settings / Webhooks / Add
to add a webhook. This is the way your code will be run and will
generate the image when you push into your repository.
Set repository filter to
blendergraph, add a description,
select
Push as the trigger event, select
fedora-32-x86_64 as
the environment, add
blender to the packages section and set the first command
to be
make; then press
Add button.
Now, this hook will be executed at your next push.
Clone the main
blendergraph repository:
git clone https://rocketgit.com/user/catalinux/blendergraph
cd blendergraph
And change the origin remote to yours:
git remote remove origin
git remote add origin https://rocketgit.com/blendergraph
Look around in the repository, especially in the
Makefile and
rocketgit/artifacts files.
You will see that the Makefile is generating .png and .blend files from
the .py files.
The artifacts file collects all .png and .blend files and uploads them in
a directory with the name of the push branched file (we are using
@@refname_short@@ variable.
We are ready to do our first push:
git push origin main
After few minutes, if you check your
Artifacts
area of your repository, you should see the folder
main and,
inside it, the .png and .blend files, with the correct content type.
You can click the .png file and look at it.
If the artifacts are not there, check your webhook and see the last output.
It allows you to debug what went wrong.
As an exercise, change something in the .py file, commit and push.
You will see after few minutes your newly generated image.