How to programmatically add editable closedpath to Figure?

I’m looking for a way to add shape of closedpath to figure programmatically and it is also editable as in the attachment.

I would like to thank you in advance if you can help give the tips.