diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 10:54:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 10:54:27 +0300 |
commit | 1f5cec709c8f79ff706eca4399583696853a3aec (patch) | |
tree | a5b8283383b7151c506ecccea3cfc7a39d90b24b /release/scripts/templates/background_job.py | |
parent | 7a231938119f97bde0f78bd939a55274806cf1f5 (diff) |
update to background_job template to use --factory-startup option.
make all templates pep8 compliant.
Diffstat (limited to 'release/scripts/templates/background_job.py')
-rw-r--r-- | release/scripts/templates/background_job.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/release/scripts/templates/background_job.py b/release/scripts/templates/background_job.py index bf29de63830..f199ee5ad50 100644 --- a/release/scripts/templates/background_job.py +++ b/release/scripts/templates/background_job.py @@ -1,16 +1,21 @@ # This script is an example of how you can run blender from the command line (in background mode with no interface) # to automate tasks, in this example it creates a text object, camera and light, then renders and/or saves it. # This example also shows how you can parse command line options to python scripts. -# +# # Example usage for this test. -# blender -b -P $HOME/background_job.py -- --text="Hello World" --render="/tmp/hello" --save="/tmp/hello.blend" -# -# Notice all python args are after the "--" argument. +# blender --background --factory-startup --python $HOME/background_job.py -- --text="Hello World" --render="/tmp/hello" --save="/tmp/hello.blend" +# +# Notice: +# '--factory-startup' is used to avoid the user default settings from interfearing with automated scene generation. +# '--' causes blender to ignore all following arguments so python can use them. +# +# See blender --help for details. import bpy + def example_function(body_text, save_path, render_path): - + scene = bpy.context.scene # Clear existing objects. @@ -31,7 +36,7 @@ def example_function(body_text, save_path, render_path): cam_ob = bpy.data.objects.new(name="MyCam", object_data=cam_data) scene.objects.link(cam_ob) # add the camera data to the scene (creating a new object) scene.camera = cam_ob # set the active camera - cam_ob.location = 0.0, 0.0, 10.0 + cam_ob.location = 0.0, 0.0, 10.0 # Lamp lamp_data = bpy.data.lamps.new("MyLamp", 'POINT') @@ -63,23 +68,23 @@ def example_function(body_text, save_path, render_path): import sys # to get command line args import optparse # to parse options for us and print a nice help message + def main(): - + # get the args passed to blender after "--", all of which are ignored by blender specifically # so python may receive its own arguments argv = sys.argv if "--" not in argv: - argv = [] # as if no args are passed - else: - argv = argv[argv.index("--") + 1:] # get all args after "--" - + argv = [] # as if no args are passed + else: + argv = argv[argv.index("--") + 1:] # get all args after "--" + # When --help or no args are given, print this help usage_text = "Run blender in background mode with this script:" usage_text += " blender -b -P " + __file__ + " -- [options]" - + parser = optparse.OptionParser(usage=usage_text) - # Example background utility, add some text and renders or saves it (with options) # Possible types are: string, int, long, choice, float and complex. @@ -88,8 +93,8 @@ def main(): parser.add_option("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE') parser.add_option("-r", "--render", dest="render_path", help="Render an image to the specified path", metavar='FILE') - options, args = parser.parse_args(argv) # In this example we wont use the args - + options, args = parser.parse_args(argv) # In this example we wont use the args + if not argv: parser.print_help() return @@ -98,7 +103,7 @@ def main(): print("Error: --text=\"some string\" argument not given, aborting.") parser.print_help() return - + # Run the example function example_function(options.body_text, options.save_path, options.render_path) |