Operator doesn't work when invoked from Panel, but works when invoked using the spacebar I have defined an operator, which is called from a button in another operator's panel. The called operator is supposed to import a ply file into the scene.

This is the relevant code:

class LoadPointCloud_Button(bpy.types.Operator):
    bl_idname = "load.pointcloud"
    bl_label = "Load Point Cloud"
    bl_options = {'UNDO'}
    bl_description = "Load the point cloud"

    def execute(self, context):
        bpy.ops.import_mesh.ply(filepath="C:\\sfmoutput\\pmvs\\models\\option-0000.ply")
        return{'FINISHED'}


The ply mesh is imported successfully when invoked by pressing the spacebar and typing "Load Point Cloud". When invoked from the panel button, nothing happens.

The System Console window says that the import was successful in both cases.


  Successfully imported 'C:\sfmoutput\pmvs\models\option-0000.ply'
  in 0.554 sec


But in the latter case, nothing happens.

I tried various things including manually setting the active scene, but nothing seems to work. I couldn't find similar example code either. What's the solution to this?
There are two issues with your code, and I presume your button doesn't actually call this code, but an older version of your operator:


bl_idname = "load.pointCloud" is an invalid name, only lower-case characters are allowed. Bad naming will make the operator registration fail.
The path to your .ply file contains backslashes, but you didn't escape them. You can use a raw string (r"C:\path\to\file.ext") to avoid lots of \\.




class LoadPointCloud_Button(bpy.types.Operator):
    bl_idname = "load.pointcloud"
    bl_label = "Load Point Cloud"
    bl_description = "Load the point cloud"
    bl_options = {'UNDO'}

    def execute(self, context):
        bpy.ops.import_mesh.ply(filepath=r"C:\sfmoutput\pmvs\models\option-0000.ply")
        return {'FINISHED'}

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

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

if __name__ == "__main__":
    register()