Creating table of contents in writer using a macro/python

Hi,
I am unable to record (a macro of) creation of a ToC, which I need automated.
I am using an RTF format which is why I cannot use python’s unoTools library.
Any ideas?