我正在尝试将某些对象从搅拌器导出为专有格式。我希望我写的脚本能够从文件下拉菜单和命令行中将搅拌机中的对象导出。我在ubuntu 12.04 LTS上使用搅拌机2.66。下面是我目前正在尝试运行的文件。如何让Blender导出脚本从命令行运行?
# Required Blender information.
bl_info = {
"name": "My Exporter",
"author": "",
"version": (1, 0),
"blender": (2, 65, 0),
"location": "File > Export > Test (.tst)",
"description": "",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"
}
# Import the Blender required namespaces.
import bpy
from bpy_extras.io_utils import ExportHelper
# The main exporter class.
class MyExporter(bpy.types.Operator, ExportHelper):
bl_idname = "test.tst";
bl_label = "My Exporter";
bl_options = {'PRESET'};
filename_ext = ".tst";
object_count = 0;
def __init__(self):
pass
def execute(self, context):
print("Execute was called.");
# Parse all the objects in the scene.
return {'FINISHED'};
def export_object(self, gameObject):
if (gameObject.type != "MESH"):
print("Object was not of type mesh.");
else:
object_count += 1;
return;
# Define a function to create the menu option for exporting.
def create_menu(self, context):
self.layout.operator(MyExporter.bl_idname,text="test (.tst)");
# Define the Blender required registration functions.
def register():
"""
Handles the registration of the Blender Addon.
"""
bpy.utils.register_module(__name__);
bpy.types.INFO_MT_file_export.append(create_menu);
def unregister():
"""
Handles the unregistering of this Blender Addon.
"""
bpy.utils.unregister_module(__name__);
bpy.types.INFO_MT_file_export.remove(create_menu);
# Handle running the script from Blender's text editor.
if (__name__ == "__main__"):
print("Registering.");
register();
print("Executing.");
# I have tried with these lines uncommented to force it to run
# the execute function, but I get an error saying:
# exporter = MyExporter();
# TypeError: bpy_struct.__new__(type): expected a single argument
#exporter = MyExporter();
#exporter.execute(bpy.context.scene);
我曾尝试下面的命令:
blender model.blend --background --python myexporter.py
从中我得到以下的输出:
Note: No (valid) '~/.config/blender/2.66/config/startup.blend' found,
fall back to built-in default.
Read new prefs: ~/.config/blender/2.66/config/userpref.blend
found bundled python: ~/blender/2.66/python
read blend: ~/model.blend
Registering.
Executing.
Blender quit
从MyExporter类执行功能似乎永远不会被调用。我甚至尝试过直接调用execute函数,但是,如果你阅读了该区域的注释,我似乎也错过了那里的一些东西。
当脚本作为加载项添加到搅拌器时,一切正常。它完美地调用执行。所以至少我有一半工作。
非常感谢您提供的任何帮助。如果我犯了一个愚蠢的错误,我很抱歉,我在写这个脚本的同时学习了python。
Hi @Jason Smith,这真的是一个伟大的工作,我们希望将这个脚本放在搅拌机中,我们该如何运行它? –
嗯,我是从命令行运行的,因为标题说明了,所以我使用了类似这样的东西: 搅拌器 --background --python Exporter.py –
如果您想从blender中作为add - 这也是可能的。为此,我把你介绍到这里。 http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions/Python/Add-Ons –