Help Automating Blender Rendering and Asset Sharing

Mar 2, 2020
44
74
I was looking into how to automate Rendering Blender Files using the CLI, and I came across this .
What I'd like to do is create a Location in Google Drive, Dropbox, or OneDrive, where User A can upload .blend files. (Input Folder)
The uploaded files would sync to User B's Computer then get detected by TheFolderSpy. (A Folder Monitoring Program)
TheFolderSpy would then execute a batch script which would pass the .blend file and Rendering parameters to the Blender CLI.
When the render is finished, the output files would be placed in a second Folder. (Output Folder)
The Output Folder would upload the files to the cloud, where User A could access them.

Here is the Render.bat code posted on reddit
Code:
TIMEOUT /T 10 /NOBREAK
d:
cd \data\blender\incoming\
if exist "render.tmp" (
    echo Instance Protection.
    exit /b 1
)
echo "instance protection">>render.tmp
"C:\Program Files\Blender Foundation\Blender\blender.exe" -b "%1" -P params.py -E CYCLES -o "D:\Data\Blender\Renders\%date:~10,4%.%date:~4,2%.%date:~7,2%.%time::=.%." -F PNG -f 0
del render.tmp
pause
Here is (I assume) the params.py code from the same post:
Code:
import bpy
bpy.context.user_preferences.system.compute_device_type = 'CUDA'
bpy.context.scene.cycles.device = 'GPU'
bpy.context.scene.cycles.use_square_samples = 0
bpy.context.scene.cycles.samples = 500
bpy.context.scene.render.tile_x = 250
bpy.context.scene.render.tile_y = 250
bpy.context.scene.render.resolution_percentage = 100
If someone could confirm what the above code does, I'd appreciate it. And I would appreciate it even more if you could explain what each line does.
 
  • Like
Reactions: Saki_Sliz

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
1,005
TIMEOUT /T 10 /NOBREAK just a delay for 10 seconds
d: Move to D Drive to work
cd \data\blender\incoming\ going to a specific location, the file must exist before this file runs
if exist "render.tmp" ( If this file exist
echo Instance Protection. not sure what this does
exit /b 1 or what this does
)
echo "instance protection">>render.tmp or what this does
"C:\Program Files\Blender Foundation\Blender\blender.exe" -b "%1" -P params.py -E CYCLES -o "D:\Data\Blender\Renders\%date:~10,4%.%date:~4,2%.%date:~7,2%.%time::=.%." -F PNG -f 0 command line telling blender to lead, using the param.py file, and some output settings such as naming and engine
del render.tmp delete temporary data
pause // press to continue, so you can see the output before closing the program





This is what I got
Test1.png

for some reason it does not like accessing the location, and I don't know why. I think it is not the bat spitting out the error, but rather the blender cli but I don't know enough about the blender cli or cli in general to really know more

the above image shows that I have tall the data paths, I have the files, and I am working in d drive only (I did modify the batch and py files to be better optimized but still no go).
 
  • Like
Reactions: AbsolutDegenerate
Mar 2, 2020
44
74
TIMEOUT /T 10 /NOBREAK just a delay for 10 seconds
d: Move to D Drive to work
cd \data\blender\incoming\ going to a specific location, the file must exist before this file runs
if exist "render.tmp" ( If this file exist
echo Instance Protection. not sure what this does
exit /b 1 or what this does
)
echo "instance protection">>render.tmp or what this does
"C:\Program Files\Blender Foundation\Blender\blender.exe" -b "%1" -P params.py -E CYCLES -o "D:\Data\Blender\Renders\%date:~10,4%.%date:~4,2%.%date:~7,2%.%time::=.%." -F PNG -f 0 command line telling blender to lead, using the param.py file, and some output settings such as naming and engine
del render.tmp delete temporary data
pause // press to continue, so you can see the output before closing the program





This is what I got
View attachment 579034

for some reason it does not like accessing the location, and I don't know why. I think it is not the bat spitting out the error, but rather the blender cli but I don't know enough about the blender cli or cli in general to really know more

the above image shows that I have tall the data paths, I have the files, and I am working in d drive only (I did modify the batch and py files to be better optimized but still no go).
Thanks for the explaination and for trying! The invalid filepath error is weird, because it looks right to me. I think you're right that the Blender CLI is throwing the error, and not the batch file.
...Maybe something to do with Windows UAC, or possibly some Blender setting needs to be changed (Think I recall needing to enable something to execute python in blender).

I'll poke around with it tomorrow and see if that changes anything. Let you know what the results are.
 
Mar 2, 2020
44
74
TIMEOUT /T 10 /NOBREAK just a delay for 10 seconds
d: Move to D Drive to work
cd \data\blender\incoming\ going to a specific location, the file must exist before this file runs
if exist "render.tmp" ( If this file exist
echo Instance Protection. not sure what this does
exit /b 1 or what this does
)
echo "instance protection">>render.tmp or what this does
"C:\Program Files\Blender Foundation\Blender\blender.exe" -b "%1" -P params.py -E CYCLES -o "D:\Data\Blender\Renders\%date:~10,4%.%date:~4,2%.%date:~7,2%.%time::=.%." -F PNG -f 0 command line telling blender to lead, using the param.py file, and some output settings such as naming and engine
del render.tmp delete temporary data
pause // press to continue, so you can see the output before closing the program





This is what I got
View attachment 579034

for some reason it does not like accessing the location, and I don't know why. I think it is not the bat spitting out the error, but rather the blender cli but I don't know enough about the blender cli or cli in general to really know more

the above image shows that I have tall the data paths, I have the files, and I am working in d drive only (I did modify the batch and py files to be better optimized but still no go).
Eureka, I think I've got it!
I took the unmodified params.py file and placed it in the blender program folder. (Same location as blender.exe)
I modified the Batch Script slightly for my filesystem and changed the "-f 0"argument to "-a" (render frame 0->Render all frames
Obviously, modifications will be needed based on system, GPU, etc., but IT WORKS!
Code:
TIMEOUT /T 10 /NOBREAK
F:
cd \Projects\Blender
if exist "render.tmp" (
    echo Instance Protection.
    exit /b 1
)
echo "instance protection">>render.tmp
"C:\Program Files\Blender Foundation\Blender 2.82\blender.exe" -b "%1" -P params.py -E CYCLES -o "F:\Projects\Blender\Renders\%date:~10,4%.%date:~4,2%.%date:~7,2%.%time::=.%." -F PNG -a
del render.tmp
pause
Results on the left, slapdash GIF on the right (sped up and made with Instagiffer)
AutoRenderResult.png CameraSwivel.gif

All that's left to do is test it with the Folder Monitor Program (which seems like no problem), and then I think I'll write up a How-To
 
  • Like
Reactions: Saki_Sliz and Cul

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
1,005
I was still having the same issue, turns out for me that the "%1" wasn't working, because I was just clicking on the script rather than running the thing through cmd and passing it a file name for my blend file. feel like an idiot when I haven't done cmd for 5 years. with a file name I can get it working now.

just to clarify
if exist "render.tmp" (
echo Instance Protection.
exit /b 1
)

this looks for a file, called render.tmp, if it finds it, the batch file warns you by saying instance protection and then exits, it stops, it does not render, this is to prevent multiple instances of blender rendering the same file (could be bad if multple blenders are viewing the same file and trying to use the same graphics card and trying to output to the same images).

after that
echo "instance protection">>render.tmp
this makes the temporary file, typing the phrase "instance protection" inside of it.
after rendering, and before the pause, this temporary file is deleted so that you will be good to go next time.

I would be interested in this folder monitoring program you are working on, to see how you are going to handle things.

I haven't gotten google drive or one drive to work right with my computer, is it suppose to automatically sync? It sounds like you are relying on said folder to automatically download what you place in the shared google drive, and for your foldermonitor to be looking, not at the google drive online, but at the google drive synced folder that downloads a copy to the local computer, and with that the script will work as it is now.

I assume the next step after all is said and done is, the next step would be to modify the param.py file to tel blender to try and do network rendering so that you can have multiple computers render all together. I've wanted to play around with multiple computers, but I have to save up another 1.2k for me to upgrade to the current CPU/ram generation, and get my old 970 back from a friend, and with that I can bulid a second computer.
 
  • Like
Reactions: AbsolutDegenerate
Mar 2, 2020
44
74
I was still having the same issue, turns out for me that the "%1" wasn't working, because I was just clicking on the script rather than running the thing through cmd and passing it a file name for my blend file. feel like an idiot when I haven't done cmd for 5 years. with a file name I can get it working now.

just to clarify
if exist "render.tmp" (
echo Instance Protection.
exit /b 1
)

this looks for a file, called render.tmp, if it finds it, the batch file warns you by saying instance protection and then exits, it stops, it does not render, this is to prevent multiple instances of blender rendering the same file (could be bad if multple blenders are viewing the same file and trying to use the same graphics card and trying to output to the same images).

after that
echo "instance protection">>render.tmp
this makes the temporary file, typing the phrase "instance protection" inside of it.
after rendering, and before the pause, this temporary file is deleted so that you will be good to go next time.

I would be interested in this folder monitoring program you are working on, to see how you are going to handle things.

I haven't gotten google drive or one drive to work right with my computer, is it suppose to automatically sync? It sounds like you are relying on said folder to automatically download what you place in the shared google drive, and for your foldermonitor to be looking, not at the google drive online, but at the google drive synced folder that downloads a copy to the local computer, and with that the script will work as it is now.

I assume the next step after all is said and done is, the next step would be to modify the param.py file to tel blender to try and do network rendering so that you can have multiple computers render all together. I've wanted to play around with multiple computers, but I have to save up another 1.2k for me to upgrade to the current CPU/ram generation, and get my old 970 back from a friend, and with that I can bulid a second computer.
I too have many passionate feelings about the command prompt, many of which can be expressed as four letter words.
The folder monitoring program I'm using already exists, You can [it's a 60kb portable app] (Don't reinvent the wheel, as they say)

I know that with Google Drive, in order to sync Files/Folders, you need to install , I don't use OneDrive, but there may be some software that need to be installed for it to work properly.

On Distributed Rendering/Renderfarms: Absolutely the next step, and probably a order of magnitude above what I'm capable of. I found a site called , which I think has a plugin that does exactly that, however it's only functional in 2.79a/b, and not 2.82 AFAIK. So I haven't had a chance to play around with it. Definitely a good idea, I have an older gaming laptop collecting dust that would make for an excellent slave.

PS. the 970 is a great workhorse, hope you can get it back soon
 

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
1,005
Have you heard of sheep it? its a free blender render farm, but it is free because everyone host their own computer to render. You can't really do nsfw because the program will show preview of the art/render, and it is possible to steal/copy the blender file. To do nsfw renders, you have to join a private friend group who are willing to render stuff for you, but I haven't found anyone so I haven't really used it.
 
  • Like
Reactions: AbsolutDegenerate
Mar 2, 2020
44
74
First I'm hearing about , but it sounds like a good idea, works with all versions of blender, distributed rendering.
With people you trust I imagine it would be a great help.
Wonder if people on here would be willing to start a private farm. Couldn't hurt unless you've got an asset thief.