Skip to main content
deleted 6 characters in body
Source Link
scurest
  • 10.6k
  • 15
  • 31

You can just append to the list, but since the items list is set only once, the list will be static and not respond to new or deleted objects. You can get a dynamic list by giving a callback as items but there's a known bug with that (there's a warning about it in the docs).

Instead I think you should use a PointerProperty. You can use the poll argument to filter the list to only certain objects. For example

def poll_is_camera(self, objectobj):
    return objectobj.type == 'CAMERA'


class Enums(bpy.types.PropertyGroup):

    camera_enum : bpy.props.PointerProperty(
        name= "", 
        description= "None", 
        type= bpy.types.Object,
        poll= poll_is_camera,
    )

    # etc

This will give you a dropdown of all camera objects for free.

You can just append to the list, but since the items list is set only once, the list will be static and not respond to new or deleted objects. You can get a dynamic list by giving a callback as items but there's a known bug with that (there's a warning about it in the docs).

Instead I think you should use a PointerProperty. You can use the poll argument to filter the list to only certain objects. For example

def poll_is_camera(self, object):
    return object.type == 'CAMERA'


class Enums(bpy.types.PropertyGroup):

    camera_enum : bpy.props.PointerProperty(
        name= "", 
        description= "None", 
        type= bpy.types.Object,
        poll= poll_is_camera,
    )

    # etc

This will give you a dropdown of all camera objects for free.

You can just append to the list, but since the items list is set only once, the list will be static and not respond to new or deleted objects. You can get a dynamic list by giving a callback as items but there's a known bug with that (there's a warning about it in the docs).

Instead I think you should use a PointerProperty. You can use the poll argument to filter the list to only certain objects. For example

def poll_is_camera(self, obj):
    return obj.type == 'CAMERA'


class Enums(bpy.types.PropertyGroup):

    camera_enum : bpy.props.PointerProperty(
        name= "", 
        description= "None", 
        type= bpy.types.Object,
        poll= poll_is_camera,
    )

    # etc

This will give you a dropdown of all camera objects for free.

Source Link
scurest
  • 10.6k
  • 15
  • 31

You can just append to the list, but since the items list is set only once, the list will be static and not respond to new or deleted objects. You can get a dynamic list by giving a callback as items but there's a known bug with that (there's a warning about it in the docs).

Instead I think you should use a PointerProperty. You can use the poll argument to filter the list to only certain objects. For example

def poll_is_camera(self, object):
    return object.type == 'CAMERA'


class Enums(bpy.types.PropertyGroup):

    camera_enum : bpy.props.PointerProperty(
        name= "", 
        description= "None", 
        type= bpy.types.Object,
        poll= poll_is_camera,
    )

    # etc

This will give you a dropdown of all camera objects for free.