用Python控制Blender.osm

问题描述 投票:0回答:1

我安装了Blender和附加的Blender.osm,我正试图从Blender的Python脚本中以编程方式导入地形。

通过将鼠标悬停在附加组件GUI上,我获得以下信息:

enter image description here

enter image description here

enter image description here

我试着这样做:

import bpy import csv import math

bpy.data.scenes["Scene"].blander_osm.dataType = 'terrain'
bpy.ops.blender_osm.import_data(0,10,0,10)

但控制台显示一些错误:

File "/Applications/blender/blender.app/Contents/Resources/2.79/scripts/modules/bpy/ops.py", line 186, in __call__
C_dict, C_exec, C_undo = BPyOpsSubModOp._parse_args(args)
File "/Applications/blender/blender.app/Contents/Resources/2.79/scripts/modules/bpy/ops.py", line 143, in _parse_args
raise ValueError("1-3 args execution context is supported")

如果有帮助,这里是引发错误的行的源代码:

enter image description here

enter image description here

我猜我没有以正确的格式证明坐标,但无法弄清楚如何正确地做到这一点......使用这个附加组件导入地形的正确方法是什么?

python blender
1个回答
0
投票

您显示的代码来自基本运算符类,它对于blender中的每个运算符都是通用的。必须将特定于运算符的任何args作为命名参数传递。对于osm导入器,您将在插件中找到特定于操作员的代码。您应该在运算符的类定义的顶部找到行bl_idname="blender_osm.import_data"

对我来说,看起来大多数选项都会在调用之前设置,就像你在你展示的例子中所做的那样。我怀疑导入步骤是否接受位置作为参数,它将导入模型然后将其移动到位。

bpy.context.scene.blender_osm.dataType = 'terrain'
bpy.ops.blender_osm.import_data()
bpy.context.active_object.location = (0,10,0)

如果导入器未激活新对象,则可能需要在导入之前循环访问context.selected_objects或获取对象列表以查找新对象。

使用搅拌机python console应该是获取操作员可用参数的简单方法,使用控制台自动完成后,左括号将显示您可以使用的参数。

由于我没有osm插件,我将使用obj导出器作为示例 -

Example of operator args from auto complete

© www.soinside.com 2019 - 2024. All rights reserved.