update to background_job template to use --factory-startup option.

make all templates pep8 compliant.
This commit is contained in:
Campbell Barton 2011-01-26 07:54:27 +00:00
parent 7a23193811
commit 1f5cec709c
13 changed files with 57 additions and 42 deletions

@ -22,12 +22,14 @@ def add_object(self, context):
scale_x = self.scale.x
scale_y = self.scale.y
verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),
Vector(( 1 * scale_x, 1 * scale_y, 0)),
Vector(( 1 * scale_x, -1 * scale_y, 0)),
Vector((-1 * scale_x, -1 * scale_y, 0)),]
verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),
Vector((1 * scale_x, 1 * scale_y, 0)),
Vector((1 * scale_x, -1 * scale_y, 0)),
Vector((-1 * scale_x, -1 * scale_y, 0)),
]
edges = []
faces = [[0,1,2,3]]
faces = [[0, 1, 2, 3]]
mesh_data = bpy.data.meshes.new(name='New Object Mesh')
mesh_data.from_pydata(verts, edges, faces)
@ -42,14 +44,14 @@ class OBJECT_OT_add_object(bpy.types.Operator, AddObjectHelper):
bl_options = {'REGISTER', 'UNDO'}
scale = FloatVectorProperty(name='scale',
default=(1,1,1),
default=(1.0, 1.0, 1.0),
subtype='TRANSLATION',
description='scaling')
def execute(self, context):
add_object(self, context)
return {'FINISHED'}
@ -61,9 +63,11 @@ def add_object_button(self, context):
text="Add Object",
icon="PLUGIN")
def register():
bpy.types.INFO_MT_mesh_add.append(add_object_button)
def unregister():
bpy.types.INFO_MT_mesh_add.remove(add_object_button)

@ -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)

@ -1,28 +1,29 @@
import bpy
from keyingsets_utils import *
class BUILTIN_KSI_hello(bpy.types.KeyingSetInfo):
bl_label = "Hello World KeyingSet"
# poll - test for whether Keying Set can be used at all
def poll(ksi, context):
return (context.active_object) or (context.selected_objects)
# iterator - go over all relevant data, calling generate()
def iterator(ksi, context, ks):
for ob in context.selected_objects:
ksi.generate(context, ks, ob)
# generator - populate Keying Set with property paths to use
def generate(ksi, context, ks, data):
id_block = data.id_data
ks.paths.add(id_block, "location")
for i in range(5):
ks.paths.add(id_block, "layers", i, group_method='NAMED', group_name="5x Hello Layers")
ks.paths.add(id_block, "show_x_ray", group_method='NONE')
# manually register
# manually register
bpy.types.register(BUILTIN_KSI_hello)

@ -9,6 +9,7 @@ import bge
# for functions like getWindowWidth(), getWindowHeight()
# import Rasterizer
def main():
cont = bge.logic.getCurrentController()
@ -18,7 +19,6 @@ def main():
# for scripts that deal with spacial logic
own_pos = own.worldPosition
# Some example functions, remove to write your own script.
# check for a positive sensor, will run on any object without errors.
print('Logic info for KX_GameObject', own.name)
@ -52,14 +52,12 @@ def main():
# sens_key = cont.sensors['key_sensor']
# actu_motion = cont.actuators['motion']
# Loop through all other objects in the scene
sce = bge.logic.getCurrentScene()
print('Scene Objects:', sce.name)
for ob in sce.objects:
print(' ', ob.name, ob.worldPosition)
# Example where collision objects are checked for their properties
# adding to our objects "life" property
"""

@ -1,5 +1,6 @@
import bge
def main():
cont = bge.logic.getCurrentController()

@ -12,6 +12,7 @@ import bge
# inside the function if you intend to use the module
# with multiple objects.
def main(cont):
own = cont.owner

@ -1,5 +1,6 @@
import bpy
def write_some_data(context, filepath, use_some_setting):
print("running write_some_data...")
f = open(filepath, 'w')
@ -18,9 +19,9 @@ from bpy.props import *
class ExportSomeData(bpy.types.Operator, ExportHelper):
'''This appiers in the tooltip of the operator and in the generated docs.'''
bl_idname = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed
bl_idname = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed
bl_label = "Export Some Data"
# ExportHelper mixin class uses this
filename_ext = ".txt"
@ -28,7 +29,7 @@ class ExportSomeData(bpy.types.Operator, ExportHelper):
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
use_setting = BoolProperty(name="Example Boolean", description="Example Tooltip", default= True)
use_setting = BoolProperty(name="Example Boolean", description="Example Tooltip", default=True)
type = bpy.props.EnumProperty(items=(('OPT_A', "First Option", "Description one"), ('OPT_B', "Second Option", "Description two.")),
name="Example Enum",

@ -1,6 +1,7 @@
import bpy
from bpy.props import *
class ModalOperator(bpy.types.Operator):
'''Move an object with the mouse, example.'''
bl_idname = "object.modal_operator"

@ -2,10 +2,11 @@ import bpy
import bgl
import blf
def draw_callback_px(self, context):
print("mouse points", len(self.mouse_path))
font_id = 0 # XXX, need to find out how best to get this.
font_id = 0 # XXX, need to find out how best to get this.
# draw some text
blf.position(font_id, 15, 30, 0)

@ -2,6 +2,7 @@ import bpy
from mathutils import Vector
from bpy.props import FloatVectorProperty
class ViewOperator(bpy.types.Operator):
'''Translate the view using mouse events.'''
bl_idname = "view3d.modal_operator"
@ -9,7 +10,6 @@ class ViewOperator(bpy.types.Operator):
offset = FloatVectorProperty(name="Offset", size=3)
def execute(self, context):
v3d = context.space_data
rv3d = v3d.region_3d

@ -1,11 +1,13 @@
import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
class SimpleOperator(bpy.types.Operator):
''''''
'''Tooltip'''
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"

@ -1,5 +1,6 @@
import bpy
def main(context):
obj = context.active_object
mesh = obj.data
@ -8,7 +9,6 @@ def main(context):
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
else:
@ -22,7 +22,6 @@ def main(context):
# apply the location of the vertex as a UV
uvs[j][:] = mesh.vertices[v_idx].co.xy
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)

@ -1,5 +1,6 @@
import bpy
class OBJECT_PT_hello(bpy.types.Panel):
bl_label = "Hello World Panel"
bl_space_type = "PROPERTIES"