3
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

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:

  1. bl_idname = "load.pointCloud" is an invalid name, only lower-case characters are allowed. Bad naming will make the operator registration fail.

  2. 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()
$\endgroup$
5
  • $\begingroup$ I actually changed the operator name & description in the above sample to narrow down the context. Edited it in the question. The rest of the code is identical. I will escape the backslashes, but the code currently works when called from the spacebar. So none of these are the issues that are causing the problem. $\endgroup$
    – ApoorvaJ
    Commented Mar 2, 2014 at 14:38
  • $\begingroup$ Escaped the backslashes (and edited the question). Still does not work. $\endgroup$
    – ApoorvaJ
    Commented Mar 2, 2014 at 15:17
  • $\begingroup$ Tested with 2.69 and works fine for me, no matter if invoked from panel, via py console or text editor. Consider to provide a complete test .blend. $\endgroup$
    – CodeManX
    Commented Mar 2, 2014 at 15:46
  • $\begingroup$ I couldn't get back to the code for a while. Sorry for the delay, @CoDEmanX. The LoadPointCloud_Button was initially being invoked by the panel of an Operator. The problem got fixed when I changed the caller to a Panel instead. I don't know if I should close the question, because I'm not sure of the exact reason behind the weird behavior. $\endgroup$
    – ApoorvaJ
    Commented Mar 12, 2014 at 12:46
  • $\begingroup$ @ApoorvaJ I'm running into a similar problem. Could you explain your workaround in a little more detail? $\endgroup$
    – Justin
    Commented Jun 17, 2016 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .