show enum in a panel

Hello to all.
In my script I am using a Panel and some Operators and my idea is to show in the Panel an enum with the elements of a list of objects of the scene.
How can I do? :confused::confused::confused::confused:
Thanks in advance.

You want to add an EnumProperty to your operator, and then in the draw method for the operator, use a .prop method of a layout to display the property. Something like this:


import bpy
from bpy.props import *

class MyOperator(bpy.types.Operator):
    bl_idname = "..."
    bl_label = "..."

    subdiv_kind = EnumProperty(name="Subdivision Method",
        description="Method for approximating curves with lines",
        items=[ \
          ('UNIFORM', "Uniform",
              "All curves bisected 'smoothness' times"),
          ('ADAPTIVE', "Adaptive",
              "Curves subdivided until flat enough, as" \
              " determined by 'smoothness'"),
          ('EVEN', "Even",
              "Curves subdivided until segments have a common length," \
              " determined by 'smoothness'"),
          ],
        default='ADAPTIVE')

    def draw(self, context):
        layout = self.layout
        box = layout.box()
        box.label("Import Options")
        box.prop(self, "subdiv_kind")


@howardt- could you explain or point me to a resource which explains how the draw method of a function is utilized. I understand everything below the “def draw(…” line, and I understand how that works with a panel, but I am not clear how it works for an operator.

If I then have a panel with row.operator() and I specify an operator with a draw method…will that then pull the draw method from the function?

@ycastrog…I know this isn’t exactly what you are looking for, but because I could never figure out how to accomplish what you are trying to, I settled for this… (see the posts by martingu)

http://www.blender.org/forum/viewtopic.php?t=19090&sid=c5b5491e1c4b6a703db76087deb08e1d

patmo141 - sorry, I didn’t read your original post carefully enough. My answer was about how to get an enum property for an operator by itself. If an operator has a draw method, then when you run the operator, the draw stuff appears in the Toolbar. I don’t know enough about this myself to answer what happens when you put an operator in a panel (though maybe “it just works”).
Some resources you may find useful:
http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook
http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Introduction_New

If I then have a panel with row.operator() and I specify an operator with a draw method…will that then pull the draw method from the function?

the operators draw method will show up in the toolshelf but the button for the operator will be in the space and region you defined in the panel-class!

niko
.