简体   繁体   中英

how to add location constraints for an object in blender?

I want to make it so that my program will stop running and print object is out of bounds if an object goes say into the negative z part of the plane in blender. the objects name is Cube.031. I will sudo code what I want to do I just am not sure about sure how to do the syntax for it.

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

If you know some programming, learning python won't take long.

For the blender specific info, almost everything is accessed through the bpy module, the API reference is online .

You can refer to an object by name in bpy.data.objects[] . There are also other lists available, like bpy.context.selected_objects[] and bpy.context.visible_objects[] .

An objects location is an array of three values (x,y,z), you can either access the z location as location.z or location[2] .

import bpy

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

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

If you wanted to go through all selected objects

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

Note that v2.80 is due for release soon and has some changes to the API , if you are just starting with blender you may want to start with 2.80. You will also find blender.stackexchange a better place to ask for blender specific help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM