如何在搅拌机中为对象添加位置约束?

how to add location constraints for an object in blender?

我想做到这一点,这样我的程序就会停止 运行,并且如果对象进入搅拌器中平面的负 z 部分,打印对象就会越界。 对象名称是 Cube.031。我将 sudo 编码我想做的事情我只是不确定如何为它做语法。

 if(Cube.031.zLocation < 0)
        print(object is out of bounds)
        end

如果你懂一些编程,learning python不会花很长时间。

对于 blender 的特定信息,几乎所有内容都可以通过 bpy 模块访问,API reference is online

您可以在 bpy.data.objects[] 中按名称引用对象。还有其他列表可用,例如 bpy.context.selected_objects[]bpy.context.visible_objects[].

对象 location 是一个包含三个值 (x,y,z) 的数组,您可以通过 location.zlocation[2].[=22= 访问 z 位置]

import bpy

obj = bpy.data.objects['Cube.031']

if obj.location.z < 0:
    print('object is out of bounds')

如果您想遍历所有选定的对象

for obj in bpy.context.selected_objects:
    if obj.location.z < 0:
        print('object {} is out of bounds'.format(obj.name))

请注意,v2.80 即将发布,并且对 API, if you are just starting with blender you may want to start with 2.80. You will also find blender.stackexchange 有一些更改,可以更好地寻求 blender 特定帮助。