简体   繁体   中英

Object Location Change on Blender Python

I was following an animation example with Python in Blender 2.69, by typing a line by line.

obj = bpy.context.object
obj.location[2] = 0.0
obj.keyframe_insert(data_path="location", frame=10.0, index=2)
obj.location[2] = 1.0
obj.keyframe_insert(data_path="location", frame=20.0, index=2)

But I have encountered an error on the 3rd line, which is saying

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'location'

I am confused because I just followed a simple example.

Why is it saying the object has no attribute 'location'?

I'll be appreciated for your help, thanks.

You'll find that the error would be reported after the second line because the variable obj has not been set. Most likely this would be from a small typo.

You can verify this by looking at the type of the variable in the python console. When getting the error you will see -

>>> type(obj)
<class 'NoneType'>

While if it had been set correctly you will get -

>>> type(obj)
<class 'bpy_types.Object'>

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