optparse module is deprecated, use new argparse module in background job template.
correction to example in doc too.
This commit is contained in:
@@ -14,7 +14,7 @@ print(bpy.data.scenes.keys())
|
|||||||
if "Cube" in bpy.data.meshes:
|
if "Cube" in bpy.data.meshes:
|
||||||
mesh = bpy.data.meshes["Cube"]
|
mesh = bpy.data.meshes["Cube"]
|
||||||
print("removing mesh", mesh)
|
print("removing mesh", mesh)
|
||||||
bpy.data.meshes.unlink(mesh)
|
bpy.data.meshes.remove(mesh)
|
||||||
|
|
||||||
|
|
||||||
# write images into a file next to the blend
|
# write images into a file next to the blend
|
||||||
@@ -22,6 +22,6 @@ import os
|
|||||||
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')
|
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')
|
||||||
|
|
||||||
for image in bpy.data.images:
|
for image in bpy.data.images:
|
||||||
file.write("%s %dx%d\n" % (image.filepath, image.size[0], image.size[1]))
|
file.write("%s %d x %d\n" % (image.filepath, image.size[0], image.size[1]))
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
|
@@ -66,7 +66,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 argparse # to parse options for us and print a nice help message
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -84,16 +84,18 @@ def main():
|
|||||||
usage_text = "Run blender in background mode with this script:"
|
usage_text = "Run blender in background mode with this script:"
|
||||||
usage_text += " blender --background --python " + __file__ + " -- [options]"
|
usage_text += " blender --background --python " + __file__ + " -- [options]"
|
||||||
|
|
||||||
parser = optparse.OptionParser(usage=usage_text)
|
print(usage_text)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description=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_argument("-t", "--text", dest="body_text", help="This text will be used to render an image", type=str, required=True)
|
||||||
|
|
||||||
parser.add_option("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE')
|
parser.add_argument("-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')
|
parser.add_argument("-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 = parser.parse_args(argv) # In this example we wont use the args
|
||||||
|
|
||||||
if not argv:
|
if not argv:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
Reference in New Issue
Block a user