See if the examples found in this thread help:
If not I can share some code I’ve used to do something similar.