How to script target fields/buttons for panels?

Hi everyone!

I’m currently trying to write an addon for Blender but I’m stuck on a (probably) simple problem. The mock-up image below (hopefully) illustrates, what I’m trying to do:

Basically, I want to be able to select 2 objects from the scene via the ‘target 1’ and ‘target 2’ fields, just like you would select a target in the ‘shrinkwrap modifier’, the ‘inverse kinematic contraint’ and so on.

Then I want to run a function by pressing the big activation button, which does something with the stored variables ‘target 1’ and ‘target 2’.

Does someone know how to program this in Python? I already know the basics of scripting panels but I have not been able to find a good reference or tutorials on how to solve my problem.

Any help or recommendations would be very appreciated.


I think the CollectionProperty can do the target thing, or use layout.prop_search instead.

See here:
Object selection box in addon