- background job style cleanup.

- assert if material assignment is called with lib. (so the callers can be corrected).
- correct example docs
This commit is contained in:
Campbell Barton 2011-04-10 15:24:05 +00:00
parent 1c11e40cb7
commit dbd3009108
4 changed files with 39 additions and 30 deletions

@ -106,7 +106,7 @@ test_pep8:
# run some checks on our cmakefiles.
test_cmake:
python build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
@echo "written: test_cmake_consistency.txt"
@echo "written: test_cmake_consistency.log"
clean:
cd $(BUILD_DIR) ; make clean

@ -22,6 +22,6 @@ bpy.types.Material.my_settings = \
# test the new settings work
material = bpy.data.materials[0]
material.my_settings.val_int = 5
material.my_settings.val_float = 3.0
material.my_settings.my_int = 5
material.my_settings.my_float = 3.0
material.my_settings.my_string = "Foo"

@ -1,12 +1,18 @@
# 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.
# 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 scripts.
#
# Example usage for this test.
# blender --background --factory-startup --python $HOME/background_job.py -- --text="Hello World" --render="/tmp/hello" --save="/tmp/hello.blend"
# 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.
# '--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.
@ -14,7 +20,7 @@
import bpy
def example_function(body_text, save_path, render_path):
def example_function(text, save_path, render_path):
scene = bpy.context.scene
@ -27,15 +33,15 @@ def example_function(body_text, save_path, render_path):
# Text Object
txt_ob = bpy.data.objects.new(name="MyText", object_data=txt_data)
scene.objects.link(txt_ob) # add the data to the scene as an object
txt_data.body = body_text # set the body text to the command line arg given
txt_data.align = 'CENTER' # center text
scene.objects.link(txt_ob) # add the data to the scene as an object
txt_data.body = text # the body text to the command line arg given
txt_data.align = 'CENTER' # center text
# Camera
cam_data = bpy.data.cameras.new("MyCam") # create new camera data
cam_data = bpy.data.cameras.new("MyCam")
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
scene.objects.link(cam_ob) # instance the camera object in the scene
scene.camera = cam_ob # set the active camera
cam_ob.location = 0.0, 0.0, 10.0
# Lamp
@ -65,14 +71,12 @@ def example_function(body_text, save_path, render_path):
bpy.ops.render.render(write_still=True)
import sys # to get command line args
import argparse # to parse options for us and print a nice help message
def main():
import sys # to get command line args
import argparse # to parse options for us and print a nice help message
# get the args passed to blender after "--", all of which are ignored by blender specifically
# so python may receive its own arguments
# get the args passed to blender after "--", all of which are ignored by
# blender so scripts may receive their own arguments
argv = sys.argv
if "--" not in argv:
@ -81,31 +85,35 @@ def main():
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 --background --python " + __file__ + " -- [options]"
usage_text = \
"Run blender in background mode with this script:"
" blender --background --python " + __file__ + " -- [options]"
parser = argparse.ArgumentParser(description=usage_text)
# Example background utility, add some text and renders or saves it (with options)
# Example utility, add some text and renders or saves it (with options)
# Possible types are: string, int, long, choice, float and complex.
parser.add_argument("-t", "--text", dest="body_text", help="This text will be used to render an image", type=str, required=True)
parser.add_argument("-t", "--text", dest="text", type=str, required=True,
help="This text will be used to render an image")
parser.add_argument("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE')
parser.add_argument("-r", "--render", dest="render_path", help="Render an image to the specified path", metavar='FILE')
parser.add_argument("-s", "--save", dest="save_path", metavar='FILE',
help="Save the generated file to the specified path")
parser.add_argument("-r", "--render", dest="render_path", metavar='FILE',
help="Render an image to the specified path")
options = parser.parse_args(argv) # In this example we wont use the args
args = parser.parse_args(argv) # In this example we wont use the args
if not argv:
parser.print_help()
return
if not options.body_text:
if not args.text:
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)
example_function(args.text, args.save_path, args.render_path)
print("batch job finished, exiting")

@ -688,6 +688,7 @@ void assign_material(Object *ob, Material *ma, int act)
if(act<1) act= 1;
/* prevent crashing when using accidentally */
BLI_assert(ob->id.lib != NULL);
if(ob->id.lib) return;
/* test arraylens */