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

@ -25,7 +25,9 @@ def add_object(self, context):
verts = [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)), 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 = [] edges = []
faces = [[0, 1, 2, 3]] faces = [[0, 1, 2, 3]]
@ -42,7 +44,7 @@ class OBJECT_OT_add_object(bpy.types.Operator, AddObjectHelper):
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
scale = FloatVectorProperty(name='scale', scale = FloatVectorProperty(name='scale',
default=(1,1,1), default=(1.0, 1.0, 1.0),
subtype='TRANSLATION', subtype='TRANSLATION',
description='scaling') description='scaling')
@ -61,9 +63,11 @@ def add_object_button(self, context):
text="Add Object", text="Add Object",
icon="PLUGIN") icon="PLUGIN")
def register(): def register():
bpy.types.INFO_MT_mesh_add.append(add_object_button) bpy.types.INFO_MT_mesh_add.append(add_object_button)
def unregister(): def unregister():
bpy.types.INFO_MT_mesh_add.remove(add_object_button) bpy.types.INFO_MT_mesh_add.remove(add_object_button)

@ -3,12 +3,17 @@
# This example also shows how you can parse command line options to python scripts. # This example also shows how you can parse command line options to python scripts.
# #
# Example usage for this test. # Example usage for this test.
# blender -b -P $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 all python args are after the "--" argument. # 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 import bpy
def example_function(body_text, save_path, render_path): def example_function(body_text, save_path, render_path):
scene = bpy.context.scene scene = bpy.context.scene
@ -63,6 +68,7 @@ def example_function(body_text, save_path, render_path):
import sys # to get command line args import sys # to get command line args
import optparse # to parse options for us and print a nice help message import optparse # to parse options for us and print a nice help message
def main(): def main():
# 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 blender specifically
@ -80,7 +86,6 @@ def main():
parser = optparse.OptionParser(usage=usage_text) parser = optparse.OptionParser(usage=usage_text)
# Example background utility, add some text and renders or saves it (with options) # Example background 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_option("-t", "--text", dest="body_text", help="This text will be used to render an image", type="string") parser.add_option("-t", "--text", dest="body_text", help="This text will be used to render an image", type="string")

@ -1,6 +1,7 @@
import bpy import bpy
from keyingsets_utils import * from keyingsets_utils import *
class BUILTIN_KSI_hello(bpy.types.KeyingSetInfo): class BUILTIN_KSI_hello(bpy.types.KeyingSetInfo):
bl_label = "Hello World KeyingSet" bl_label = "Hello World KeyingSet"

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

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

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

@ -1,5 +1,6 @@
import bpy import bpy
def write_some_data(context, filepath, use_some_setting): def write_some_data(context, filepath, use_some_setting):
print("running write_some_data...") print("running write_some_data...")
f = open(filepath, 'w') f = open(filepath, 'w')

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

@ -2,6 +2,7 @@ import bpy
import bgl import bgl
import blf import blf
def draw_callback_px(self, context): def draw_callback_px(self, context):
print("mouse points", len(self.mouse_path)) print("mouse points", len(self.mouse_path))

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

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

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

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