I try to get the active object by "bpy.context.scene.objects.active" in my operator, but I receive a error 'Context' object has no attribute 'objects', what's wrong?My scripts is as follow:
import bpy
from bpy.props import *
cube=bpy.data.objects["Cube"]
class HelloError(bpy.types.Operator):
bl_idname = "object.hello_error"
bl_label = "HelloError"
bl_options={'REGISTER','UNDO'}
my_property= BoolProperty(name="my_property", default=True)
def execute(self, context):
print("--------------------------------")
if self.my_property:
print("do something......")
#set the active object as a existed cube
bpy.context.scene.objects.active =cube
print("objects:",bpy.context.scene.objects)
print("cur_active:",bpy.context.scene.objects.active.name)
return {'FINISHED'}
def register():
bpy.utils.register_class(HelloError)
def unregister():
bpy.utils.unregister_class(HelloError)
if __name__ == "__main__":
register()
And the blender The file will be uploaded soon(It seems that the website"https://blend-exchange.giantcowfilms.com/"cannot be accessed now in my computer, i will upload the file once it is accessible)