-
Notifications
You must be signed in to change notification settings - Fork 9
HOWTO: Automate BlendNet with Addon
In this document I will describe how to automate BlendNet using Addon.
To simplify the example it will use local
provider, so it's a good idea to check
HOWTO: Setup provider: Your own render farm (local) documentation. But overall
if you want to use Addon - probably because it can simplify the automation of the
cloud providers, and it's probably a good idea.
The working example of such automation was prepared as CI for BlendNet project and the best way to understand it - dig into the logic of CircleCI config file, in the Addon test script and in the Blender python script.
Also there is Windows-based CI was prepared, so you can check the same config file
(blendnet_test_win
job), prepare script
and the Addon test script
First of all you need to locate your blend project file and open it in Blender with
BlendNet addon to locate the required functions to run. Blender interface is really
helpful to find the required API calls, that usually begins with bpy
module name.
If you see some button or property - just point your cursor on it and Blender will
show description, where you can find Python: ...
line with the actual path to the
property starting with bpy
. Also It's really useful to find the Scripting
workspace, which will help by auto-completion. But from here it's better to check
the Blender documentation of the Python API itself.
Also you can check the addon files (main one and some additional ones) - which can help you to find the required operations and properties.
Next step will be to actually prepare the python script with all the found calls:
So this way you can locate how to enable the BlendNet addon:
import bpy
bpy.ops.preferences.addon_enable(module='blendnet') # 'blendnet' here is the addon directory, where the files is placed
You need to choose the provider (to simplify the example local
is used here):
prefs = bpy.context.preferences.addons['blendnet'].preferences
prefs.resource_provider = 'local'
prefs.manager_address = '172.17.0.2' # IP or DN of the running Manager
prefs.manager_ca_path = '/home/user/blendnet-manager/ca.crt' # Full path to the CA certificate
prefs.manager_user = 'None'
prefs.manager_password = 'None'
Different providers will use different configuration options, so check your one.
Set any required parameters for your scene (maybe you have some specific workflow):
scene = bpy.context.scene
scene.render.engine = 'CYCLES' # Basically not needed, but in case project forgot to set the engine
scene.cycles.samples = 23 # Here I set the samples, because Addon uses this params to create task
scene.cycles.aa_samples = 23
scene.frame_current = 5 # Set the frame you want to render
You can use operations poll which needs the Manager to be created:
for retry in range(1, 10):
if bpy.ops.blendnet.agentcreate.poll(): # The poll() is class function, so run it directly
break
time.sleep(5)
In cloud providers you will probably need to run the manager first by using
blendnet.togglemanager
, but not sure it will work - noone tested it from scripts.
Local provider wants you to connect the agents (if they are not connected during the Manager setup), so you can connect them via UI:
bpy.ops.blendnet.agentcreate(
'EXEC_DEFAULT',
agent_name='agent-test-1',
agent_address='172.17.0.3',
agent_port=prefs.agent_port,
agent_user='None',
agent_password='None',
)
Now when everything is ready - you can run the main command to send task to the Manager:
check = bpy.ops.blendnet.runtask()
if 'CANCELLED' in check:
print('Unable to send task')
It was modifyed to be properly run from the script, it will automatically
generate the task name and will check that everything is fine here and return
{'FINISHED'}
, otherwise will return {'CANCELLED'}
as a regular operation.
The best way is to use Manager API, or you can simple wait for the compose result:
for retry in range(1, 50):
if os.path.isfile(scene.render.frame_path()):
break
time.sleep(5)
So when everything is put together, just save your python script and run the next (or quite similar) command:
$ blender -b -noaudio your_project.blend -P your_script.py
And that's it - if you prepared the script properly, it will generate the result compose file.