Use a pointer property with a poll.
To distinguish a regular material from one for a gp object there is the handy attribute Material.is_grease_pencil
Similarly to https://blender.stackexchange.com/a/159155/15543 and using a poll method https://blender.stackexchange.com/a/101303/15543
Will narrow down the selection based and offer the same choices as the regular material drop down.
import bpy
from bpy.props import PointerProperty
def poll_material(self, material):
return not material.is_grease_pencil
class TEST_PT_layout_panel(bpy.types.Panel):
bl_label = "Prop Panels"
bl_category = "Test Panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
scene = context.scene
layout = self.layout
col = layout.column()
col.prop_search(scene, "prop", bpy.data, "materials")
#or
col.prop(scene, "prop")
def register():
bpy.types.Scene.prop = PointerProperty(
type=bpy.types.Material,
poll=poll_material,
)
bpy.utils.register_class(TEST_PT_layout_panel)
def unregister():
bpy.utils.unregister_class(TEST_PT_layout_panel)
del bpy.types.Scene.prop
if __name__ == "__main__":
register()
Kinda related:
How to populate UIList with all material slot in scene? 2.8