SHARE
TWEET

CoDEmanX - invoke_search_popup.py (dynamic enum property)

a guest Jun 1st, 2013 415 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import bpy
  2.  
  3. class SimpleOperator(bpy.types.Operator):
  4.     """Tooltip"""
  5.     bl_idname = "object.simple_operator"
  6.     bl_label = "Simple Object Operator"
  7.     bl_options = {'REGISTER', 'UNDO'}
  8.     bl_property = "enumprop"
  9.    
  10.     def item_cb(self, context):
  11.         return [(mat.name, mat.name, '') for mat in self.mats]
  12.    
  13.     mats = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)
  14.     enumprop = bpy.props.EnumProperty(items=item_cb)#(('1','One',''),('2','Two','')))
  15.  
  16.     @classmethod
  17.     def poll(cls, context):
  18.         return (context.active_object is not None and
  19.                 context.active_object.type == 'MESH')    
  20.  
  21.     def execute(self, context):
  22.         self.report({'INFO'}, self.enumprop)
  23.         return {'FINISHED'}
  24.  
  25.     def invoke(self, context, event):
  26.         self.mats.clear()
  27.         for i in range(1, 7):
  28.             self.mats.add().name = "Material %i" % i
  29.         context.window_manager.invoke_search_popup(self)
  30.         return {'FINISHED'}
  31.  
  32.  
  33. def register():
  34.     bpy.utils.register_class(SimpleOperator)
  35.  
  36.  
  37. def unregister():
  38.     bpy.utils.unregister_class(SimpleOperator)
  39.  
  40.  
  41. if __name__ == "__main__":
  42.     register()
  43.  
  44.     # test call
  45.     bpy.ops.object.simple_operator('INVOKE_DEFAULT')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top