- 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

View File

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

View File

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

View File

@@ -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) # This script is an example of how you can run blender from the command line
# to automate tasks, in this example it creates a text object, camera and light, then renders and/or saves it. # (in background mode with no interface) to automate tasks, in this example it
# This example also shows how you can parse command line options to python scripts. # 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. # 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: # 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. # '--' causes blender to ignore all following arguments so python can use them.
# #
# See blender --help for details. # See blender --help for details.
@@ -14,7 +20,7 @@
import bpy import bpy
def example_function(body_text, save_path, render_path): def example_function(text, save_path, render_path):
scene = bpy.context.scene scene = bpy.context.scene
@@ -27,15 +33,15 @@ def example_function(body_text, save_path, render_path):
# Text Object # Text Object
txt_ob = bpy.data.objects.new(name="MyText", object_data=txt_data) 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 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.body = text # the body text to the command line arg given
txt_data.align = 'CENTER' # center text txt_data.align = 'CENTER' # center text
# Camera # 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) 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.objects.link(cam_ob) # instance the camera object in the scene
scene.camera = cam_ob # set the active camera 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
@@ -65,14 +71,12 @@ def example_function(body_text, save_path, render_path):
bpy.ops.render.render(write_still=True) 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(): 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 # get the args passed to blender after "--", all of which are ignored by
# so python may receive its own arguments # blender so scripts may receive their own arguments
argv = sys.argv argv = sys.argv
if "--" not in argv: if "--" not in argv:
@@ -81,31 +85,35 @@ def main():
argv = argv[argv.index("--") + 1:] # get all args after "--" argv = argv[argv.index("--") + 1:] # get all args after "--"
# When --help or no args are given, print this help # When --help or no args are given, print this help
usage_text = "Run blender in background mode with this script:" usage_text = \
usage_text += " blender --background --python " + __file__ + " -- [options]" "Run blender in background mode with this script:"
" blender --background --python " + __file__ + " -- [options]"
parser = argparse.ArgumentParser(description=usage_text) 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. # 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("-s", "--save", dest="save_path", metavar='FILE',
parser.add_argument("-r", "--render", dest="render_path", help="Render an image to the specified 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: if not argv:
parser.print_help() parser.print_help()
return return
if not options.body_text: if not args.text:
print("Error: --text=\"some string\" argument not given, aborting.") print("Error: --text=\"some string\" argument not given, aborting.")
parser.print_help() parser.print_help()
return return
# Run the example function # 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") print("batch job finished, exiting")

View File

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