Error: Object has no mesh data to be used for ray casting I'm writing an operator that casts rays from the center towards certain amounts of points and finds the faces rays hit. I'm facing this annoying error, when I change the property of the operator.

I've managed to strip the code down to minimal code to reproduce this, that works on default scene

Code:

import bpy
import bmesh
from bpy.props import *
from mathutils import *

class SomeOperator(bpy.types.Operator):
    bl_idname = "some_operator"
    bl_label = "Some operator"
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}

    prop = IntProperty(name="Prop",
        description="Prop",
        min=10,
        max=50,
        default=10)

    def execute(self, context):

        obj = context.active_object

        if bpy.context.mode != 'OBJECT':
            raise Exception("Please switch to object mode")

        cover = [Vector((0,0,1)), Vector((0,0,-1)), Vector((1,0,0)), Vector((-1,0,0))]

        for pt in cover:
            dummy1, dummy2, faceInd = obj.ray_cast(Vector((0.0, 0.0, 0.0)), pt)

            obj.data.polygons[faceInd].select = True

        return {'FINISHED'}


When you change the SomeProp value, the error occurs.
You need bpy.context.scene.update() just after execute() for it to work. It seems it needs to update some internal relationships. 

Full code (modified to work on 2.78):

import bpy
import bmesh
from bpy.props import *
from mathutils import *

class SomeOperator(bpy.types.Operator):
    bl_idname = "object.some_operator"
    bl_label = "Some operator"
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}

    prop = IntProperty(name="Prop",
        description="Prop",
        min=10,
        max=50,
        default=10)

    def execute(self, context):
        bpy.context.scene.update()
        obj = context.active_object

        if bpy.context.mode != 'OBJECT':
            raise Exception("Please switch to object mode")

        cover = [Vector((0,0,1)), Vector((0,0,-1)), Vector((1,0,0)), Vector((-1,0,0))]

        for pt in cover:
            dummy0, dummy1, dummy2, faceInd = obj.ray_cast(Vector((0.0, 0.0, 0.0)), pt)

            obj.data.polygons[faceInd].select = True

        return {'FINISHED'}

def register():
    bpy.utils.register_class(SomeOperator)


def unregister():
    bpy.utils.unregister_class(SomeOperator)


if __name__ == "__main__":
    register()

# test call
#bpy.ops.object.some_operator()