Blender-从python脚本打开并解析.blend文件 [英] Blender - Open and parse a .blend file from python script
问题描述
我想从python脚本中打开一个.blend文件并进行解析(获取对象,动画和材质). 到目前为止,我已经阅读了有关如何从Blender API中执行此操作的文档(将脚本作为Blender附加组件运行),但是我想从命令行运行此脚本而无需打开Blender.
I would like to open a .blend file from a python script and parse it (get objects, animations and materials). The documentation I have read so far about how to do this from blender API (running the script as a blender add-on), but I would like to run this script from the command line without opening blender.
感谢您能给我的所有帮助.
I appreciate all the help you can give me.
推荐答案
我意识到我不需要打开二进制Blender文件并对其进行解析即可使用这些对象. Blender有自己的python安装程序,因此我将python脚本放入了 path_to_blender/version/scripts/addons 文件夹中,可以在命令行中如下执行该命令:
I realized I don't need to open the binary blender file and parse it in order to use the objects. Blender has its own python installation, so I put a python script inside the folder path_to_blender/version/scripts/addons , I can execute it in the command line as follows:
blender.exe --background --python ./version/scripts/addons/superScript.py
接下来,如果您有一个要从脚本中读取的.blend文件,请将其放在background参数后面,如下所示:
Next, if you have a .blend file you want to read from your script, put it after the background parameter as follows:
blender.exe --background myFile.blend --python ./version/scripts/addons/superScript.py
在您的python脚本中执行以下操作:
And inside your python script do the following:
import bpy
import os
for ob in bpy.context.scene.objects:
print("object name: ", ob.data.name)
在此示例中,我将.blend文件中的场景内的所有对象打印
In this example I'm printing all the objects inside the scene in the .blend file
这篇关于Blender-从python脚本打开并解析.blend文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!