My operator pool had issue with properties

I want to create addon that convert curve object to mesh object, so poll function is checking if the selected object is curve. The code is some kind like this:

    def poll(cls, context):
        # check if curve is selected
        obj = context.active_object
        return obj and obj.type == 'CURVE'

The problem using this pool is if I run the operator, the properties of the operator doesn’t show up in bottom left corner, like in picture below.


If I don’t use the poll, it will be showed up like this.


Maybe it’s because the context is immediately fails because of the pool. I really want to add few properties in my operator but I don’t want to accidentally convert already mesh object.

Anyone know how to get around this problem? :confused:

I think your use of “context” instead of “bpy.context” may be the issue. “context” in your poll function seems to be a global variable, that is assigned somewhere else in your script. That somewhere else is probably being executed when you (or blender on start up) run the script, and just has a different context.

It’s still doesn’t work. The context is default for poll function, I don’t think it effects anything. The issue is because the object is immediately become a mesh if I use the operator, so the context is automatically fails.

Do anyone know about this issue?

Does the operator have

bl_options = {‘REGISTER’, ‘UNDO’}

?

Yes, it was. What should I change this to?

No, it’s fine then, both are required to make the redo panel work. Also, the operator needs to be run from the 3D View context (e.g. spacebar menu), it will fail if you run the operator from Python console or Text Editor.

I already run the operator on 3d view, so, do you know about this problem?

Can you post the code so I can take a closer look?

This is the simplified code. If the poll is used, the union properties won’t show on Operator panel.

class ConvertCurveToMeshWithOptions(bpy.types.Operator):    """Nice Useful Tooltip"""
    bl_idname = "curve.convert_to_mesh_with_options"
    bl_label = "Convert to Mesh with Options"
    bl_description = "Convert curve to mesh object with options"
    bl_options = {'REGISTER', 'UNDO'}


    union = BoolProperty(
            name="Use Union",
            default=False,
            )


    @classmethod
    def poll(cls, context):
        if not context.mode == 'OBJECT':
            return False
        # check if curve is selected
        obj = bpy.context.active_object
        return obj and obj.type == 'CURVE'


    def execute(self, context):
        bpy.ops.object.convert(target='MESH')
        if self.union:
            print("do union boolean on converted curve")
        return {'FINISHED'}

What do you think?

You poll code look really messy. Try

    @classmethod
    def poll(cls, context):
        return context.object is not None and context.object.type == 'CURVE' and context.mode == 'OBJECT'

Oh my bad, I have change poll code to be like yours, but the problem is still the same.
Have you try the operator yet?

def draw(self, context):

def draw(cls, context):

you probably have self, context for both.

& why not have the properties show up only if a curve is selected.

something like this:

    def draw(self, context):
        if not obj.type == 'CURVE':
            self.layout.label("Please select a curve")
        else:
            layout = self.layout
            layout.operator("")   

I’m not so good with scripting but I hope I gave you an idea of what I mean.

Thanks for the idea. This actually can be the solution, but the operator still can be called from ‘space’ search menu. It’s still consider okay because the execute function still can check the context.

However, it’s still a lot to do than just a poll function that behaved correctly. I might think this was a bug, I think I need to report it.

If you add ‘INTERNAL’ to bl_options, the operator won’t be listed in the spacebar menu, but can still be added to a panel, executed and with Redo panel working.