I'm doing a scritp with several functions. All of them have been tested and work fine if you execute them from a py file. The problem is when I put them on an operator and call them when pressing the button they stop working. It seems as if blender is not able to get the current active object to do whatever I'm telling it to do. Because is work related I can't really share the code but one of the parts where it crashes looks like:
ob=bpy.context.active_object for i in range(0,len(bpy.context.object.data.polygons)): ob.data.polygons.select=True bpy.ops.object.mode_set(mode='EDIT')
The loop is longer, but the error comes up in that line. Menawhile, executing the same function from a py file works fine.
The error is
AttribueError: 'NoneType' object has no attribute 'data