I’m working on an ‘Add Mesh’ addon, and I’d like to let the user select an existing mesh as a starting point for the newly created mesh. So I’m looking for something like the drop down list you also find in eg. the boolean modifier (where you select the 2nd object of the operation).
I’ve been looking around on the forums, and this is what I’ve come up with. It looks ok, but it doesn’t actually let me select the desired mesh. Selecting something in the drop down list has no effect. Also, the eyedropper tool is only available the first time the addon is used in the scene. The eyedropper actually seems to work, but it closes my addon panel (because I’m selecting something in the 3D view, I guess), which is quite annoying. When I open the addon again, the mesh I selected with the eyedropper is indeed selected/remembered.
This is what it looks like:

Below is the relevant part of the addon init.py file. It uses a PointerProperty on the Scene type, which was suggested in almost all proposed solutions I came across.
def filter_mesh_object(self, object):
return object.type == 'MESH'
class SelectMeshObjectProperties(bpy.types.PropertyGroup):
SelectedMesh: bpy.props.PointerProperty(name="Selected Mesh", type=bpy.types.Object, poll=filter_mesh_object)
def select_mesh_object_button(self, context):
self.layout.operator(Operator.OperatorSelectMeshObject.bl_idname, text="Select Mesh Object", icon='PLUGIN')
def register():
bpy.utils.register_class(SelectMeshObjectProperties)
bpy.utils.register_class(Operator.OperatorSelectMeshObject)
bpy.types.VIEW3D_MT_mesh_add.append(select_mesh_object_button)
bpy.types.Scene.SelectMeshObjectProperties = bpy.props.PointerProperty(type=SelectMeshObjectProperties)
Below is the relevant part of the Operator, ie the draw() method. For testing purposes, the addon prints the name of the selected mesh object (if any), so you’ll need to look in the console window to see the result.
class OperatorSelectMeshObject(Operator, AddObjectHelper):
"""Select Mesh Object"""
bl_idname = "mesh.select_mesh_object"
bl_label = "Select Mesh Object"
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
box = layout.box()
box.label(text="Select Mesh Object Properties")
col = box.column(align=True)
col.prop(context.scene.SelectMeshObjectProperties, "SelectedMesh")
I’ve attached both files for easy testing/modification. If anybody knows why this isn’t working as intended and what I can do to make it work properly, please let me know. Using Blender 2.92 on Win10, btw. TIA!
select_mesh_object.zip (1.4 KB)

