Triggering blender/python from outside the file?

Hi all,

I’m new to blender/python and am wondering if an idea that I have is possible before I start spending a lot of time on an animation and other “bells & whistles”.

The “bare bones” is this:

I want to trigger a blender animation to be created using external data and the resulting file stored on a server.

As en example picture a short animation of a car pulling into a driveway. I want to simply change the license plate (a text object), the color of the car, and a logo on the car based on data given to me by users and then have this new video (.MOV file I’m thinking now but have more research to do) stored on a server. So it’s the same basic animation with some properties being adjust each time around.

I can certainly find the information on adjusting blender object properties via python but I’m unsure on whether or not it’s possible to trigger a blender file (and what file type that should be) from outside the (previously) closed file AND if that blender file can then save resulting files that it creates.

It seems reasonable to me that this would be possible. :smiley:

I’m not asking that anyone type me up some code, merely suggestions on some search terms to look for and specific technologies (hopefully PHP) that might commonly be used in conjunction with blender/python.

Thanks.

Hello and welcome.

Yeah, this is actually very easy. You can render frames or animations from the command line, saving the output to the (appropriate) format of choice. Navigating to the blender folder in a command prompt and typing blender /? will show you the options you have available.

As for changing the colour, license plate and a decal - I’d just have these three objects texture mapped, using files such as car_colour.tga license_plate.tga and decal_tex.tga
You just run a script that copied the appropriate files from your library of colours and license plates and decals into the path specified in the blend file.

So, if for example I wanted a green car with the numberplate spi-434 and a donut king sticker on it that was to be rendered to a MOV for frames 1 to 500,

I would write either a batch file or a shell script that took the basic form:

(winXP)
C:
cd \folder_with_blend_file_in_it
copy colours\green.tga car_colour.tga
copy plates\spi_434.tga license_plate.tga
copy decals\donut_king.tga decal_tex.tga
\path_to_blender.exe_file\blender -b -o RenderedMovies\GreenSPI434DonKin.mov -f QUICKTIME

(Linux)
cd /home/folder_with_blend_file_in_it
cp colours/green.tga car_colour.tga
cp plates/spi_434.tga license_plate.tga
copy decals/donut_king.tga decal_tex.tga
/path_to_blender_executable_file/blender -b -o RenderedMovies/GreenSPI434DonKin.avi -f AVI

(I’d also make sure that the timeline went from 1 to 500

With a mac, quicktime’s obviously include, xp can have it added but I don’t think the linux versions of blender will output to quicktime, so you’d have to dump it then convert.

of course, you could just write three scripts allowing you to change the colour, decal or plates independently. It would just be a matter of writing something that would check the 3 library folders and give you a menu that allowed selection from the files found, doing away with the need to hard-code a script for every combination and permutation.

It would be great to have the numberplate created from ascii text in either a file or a command line parameter, though I’m afraid that’s beyond me my friend. Perhaps you could add a python script that was executed every frame, that read the contents of a text file, emptied the text-object used for the plate and then set it to whatever was read from the text file. You can possibly set a script up to only be called on the first frame, though if not, I’d make the script check which frame it was on first thing, and if the frame was not frame 1, I’d know the plate’s text had been set and that I could return from my function without going through the rigmarole of reading the plate data from the text file.

Oh wait! I just re-read your post and saw you mention PHP. Cool - you could create an image file for the number plate and the colour using PHP. You could allow the plate’s text to be typed into an input box and allow the colour to be chosen from a colour palette, ala gimp, PS or anything else of the sort.

I’d be interested to see how this turns out. Nice idea.

Thanks enhzflep!

I’ll have to re-read what you’ve posted a couple times as it’s new technology to me but I think I’m following it.

I think this is pretty much what I have planned. FWIW the “car in the driveway” example is not exactly what I’m working on but merely something I thought most could easily visualize but keeping with that example: I’d like to use PHP to update a database and then check the database via Python on frame 1 (or some “loading” phase of blender) of a blender file to load my 3 types of items (colors, strings, images).

If accomplished how I’d like the project will definitely become a public tool that a specific community will be able to use and I’ll definitely link to the results here.

However a major issue that I’m now aware of is that I need blender’s app installed on the server and not just a blender file on the server. I currently only have virtual hosting and don’t think this project merits going to a dedicated server that I can install blender on. For now it might have to be a one time thing hosted in combination with a home PC until I get a little more money and/or knowledge. :frowning:

Just to clarify, though all data is brought into the end animation as a result of user input only some of it is decided by the user. The color, for instance, is pre-assigned to the user as is the logo. And in this example the user is selecting the license plate from a list of available ones but is not able to enter any new text.

So the user picks a license plate from the available list on my webpage and then blender/python would use that license plate along with the user’s team color and logo to produce the final animation - which again is the same for each iteration except the variable data loaded at the start.

It’s a pleasure Jester.

Ah, cool - you don’t want to have arbitrary number-plates. That makes the whole idea rather more simple, and does away with the need for python all-together.

Unless, you want to use your PHP to write a text file that a python script in blender loads and uses to set and load the texture files. (Though, it would be 10x easier to simply copy the files you needed for any particular run into the same folder as the blend file. No python, no changing of the .blend file)

I mean, the textures for the cars will reference files on the hard-disk somewhere, right?
So, why change the file-path each time, when you can just change the file?

Wow time flies! I knew that I needed to get back to this thread but didn’t realize quite how long I let it go. :slight_smile:

Well right now I’ve been pulled away from Blender and all things fun to get some of the “grunt work” done on this project.

I’m getting a clearer overall picture of how blender will (or won’t) fit in to the whole thing and it appears I overlooked a major issue: I don’t have a dedicated server and was thinking that a blender file was going to be able to do what I need, not the blender application itself, which appears to be the case.

Thanks again for the help enhzflep. I’ve got to go back to the “grunt work” now but hope to be able to focus near 100% on blender in about 2 weeks. I really like the idea of just updating text files that blender points to. If I must run the application itself then it’s likely that I’ll be looking for a dedicated server soon as I’m really excited about the possibilities that blender opens for me.