[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34495] trunk/blender/release/scripts/ templates: update to background_job template to use --factory-startup option.

Campbell Barton ideasman42 at gmail.com
Wed Jan 26 08:54:28 CET 2011


Revision: 34495
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34495
Author:   campbellbarton
Date:     2011-01-26 07:54:27 +0000 (Wed, 26 Jan 2011)
Log Message:
-----------
update to background_job template to use --factory-startup option.
make all templates pep8 compliant.

Modified Paths:
--------------
    trunk/blender/release/scripts/templates/addon_add_object.py
    trunk/blender/release/scripts/templates/background_job.py
    trunk/blender/release/scripts/templates/builtin_keyingset.py
    trunk/blender/release/scripts/templates/gamelogic.py
    trunk/blender/release/scripts/templates/gamelogic_basic.py
    trunk/blender/release/scripts/templates/gamelogic_module.py
    trunk/blender/release/scripts/templates/operator_export.py
    trunk/blender/release/scripts/templates/operator_modal.py
    trunk/blender/release/scripts/templates/operator_modal_draw.py
    trunk/blender/release/scripts/templates/operator_modal_view3d.py
    trunk/blender/release/scripts/templates/operator_simple.py
    trunk/blender/release/scripts/templates/operator_uv.py
    trunk/blender/release/scripts/templates/panel_simple.py

Modified: trunk/blender/release/scripts/templates/addon_add_object.py
===================================================================
--- trunk/blender/release/scripts/templates/addon_add_object.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/addon_add_object.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -22,12 +22,14 @@
     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 @@
     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 @@
         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)
 

Modified: trunk/blender/release/scripts/templates/background_job.py
===================================================================
--- trunk/blender/release/scripts/templates/background_job.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/background_job.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -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 @@
     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 @@
 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 @@
     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 @@
         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)
 

Modified: trunk/blender/release/scripts/templates/builtin_keyingset.py
===================================================================
--- trunk/blender/release/scripts/templates/builtin_keyingset.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/builtin_keyingset.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -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)

Modified: trunk/blender/release/scripts/templates/gamelogic.py
===================================================================
--- trunk/blender/release/scripts/templates/gamelogic.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/gamelogic.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -9,6 +9,7 @@
 # for functions like getWindowWidth(), getWindowHeight()
 # import Rasterizer
 
+
 def main():
     cont = bge.logic.getCurrentController()
 
@@ -18,7 +19,6 @@
     # 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 @@
     # 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
     """

Modified: trunk/blender/release/scripts/templates/gamelogic_basic.py
===================================================================
--- trunk/blender/release/scripts/templates/gamelogic_basic.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/gamelogic_basic.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -1,5 +1,6 @@
 import bge
 
+
 def main():
 
     cont = bge.logic.getCurrentController()

Modified: trunk/blender/release/scripts/templates/gamelogic_module.py
===================================================================
--- trunk/blender/release/scripts/templates/gamelogic_module.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/gamelogic_module.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -12,6 +12,7 @@
 # inside the function if you intend to use the module
 # with multiple objects.
 
+
 def main(cont):
     own = cont.owner
 

Modified: trunk/blender/release/scripts/templates/operator_export.py
===================================================================
--- trunk/blender/release/scripts/templates/operator_export.py	2011-01-26 07:34:17 UTC (rev 34494)
+++ trunk/blender/release/scripts/templates/operator_export.py	2011-01-26 07:54:27 UTC (rev 34495)
@@ -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 @@
 
 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 @@
 
     # 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",

Modified: trunk/blender/release/scripts/templates/operator_modal.py

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list