Create drop down list of components in model with 'xxxx' in their name?

I want to let the user pick from a list of components or dynamic components to place in the model (in this case, a stage set). It could either be from an enumeration of existing components with a text filter to match a predefined text string, or it could look in a folder with exported (Saved As…) components, again filtered by either a text string in the file name, or picked from a list of containing sub-folder names. I can’t find an example even with a broad Google search.

I can’t quite see where to get started and would welcome a short snippet of code or pseudo-code to point me in the right direction.

I have done it in the past with a pre-coded list displayed in a sub-menu, but I’d like it to update automatically as components or component files are added, and perhaps even as a new types of component (saved in a newly named subfolder) are added.

Any ideas welcome. And thanks in advance.

If the files reside in a specific folder, you can use the UI Open Panel to only display those files that match a pattern. For example, I have these three files in folder A:

I pasted the following line into the Ruby Console:

UI.openpanel("Select SKP File", "~", "SKP Files|??123??.skp;||")

which gives this:

This may not be very elegant, but it’s simple and straightforward …

Thanks very much. I think that will be enough to get me started. Seems easier than trying to iterate through component entities.