Since blender 2.79 this is possible using the poll
parameter of the bpy.props.PointerProperty
.
import bpy
class OBJECT_PT_HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
scene = context.scene
layout.prop(scene, "mychosenObject")
def scene_mychosenobject_poll(self, object):
return object.type == 'CURVE'
def register():
bpy.utils.register_class(OBJECT_PT_HelloWorldPanel)
bpy.types.Scene.mychosenObject = bpy.props.PointerProperty(
type=bpy.types.Object,
poll=scene_mychosenobject_poll
)
def unregister():
bpy.utils.unregister_class(OBJECT_PT_HelloWorldPanel)
del bpy.types.Scene.mychosenObject
if __name__ == "__main__":
register()
See the documentation
bpy.props.PointerProperty(type=None, name="", description="", options={'ANIMATABLE'}, poll=None, update=None)
Returns a new pointer property definition.
Parameters:
- type (
class
) – A subclass of bpy.types.PropertyGroup or bpy.types.ID.
- name (
string
) – Name used in the user interface.
- description (
string
) – Text used for the tooltip and api documentation.
- options (
set
) – Enumerator in [‘HIDDEN’, ‘SKIP_SAVE’, ‘ANIMATABLE’, ‘LIBRARY_EDITABLE’, ‘PROPORTIONAL’,’TEXTEDIT_UPDATE’].
- poll (
function
) – function to be called to determine whether an item is valid for this property. The function must take 2 values (self,object) and return Bool.
- update (
function
) – Function to be called when this value is modified, This function must take 2 values (self, context) and return None. Warning there are no safety checks to avoid infinite recursion.