UNSOLVED Delete marker with python


I have a Python Generator with an integer UserData. My code functions by adding markers based on the integer from my user data. Adding markers is working as expected. However deleting markers does not. I can't find anything in the API that deletes markers from the timeline. How would I do this? The only other option would be to delete all markers with command data. My code:

def GetMarkers(doc=c4d.documents.GetActiveDocument(), sort=True):
    markers = []
    thisMarker = c4d.documents.GetFirstMarker(doc)
    while thisMarker is not None:
        thisMarker = thisMarker.GetNext()
    return markers

def main():  
    #Get a list of markers
    markers = GetMarkers(doc)
    print len(markers)
    #check if my user data integer is greater/less than the number of markers 
    if len(markers) < op[c4d.ID_USERDATA,1]:
        c4d.documents.AddMarker(doc, None, c4d.BaseTime(len(markers)), 'name')
        print 'add Marker'
    elif len(markers) > op[c4d.ID_USERDATA,1]:
        #Removing or del from Markers list doesnt work...   
        print 'delete Marker'
    #Here I loop through the list and set the name,time, length, color etc. if needed
    for i in range(0, len(markers)):

Hi @gsmetzer please read and apply for your next topics:

Regarding your issue.
a Marker is a BaseList2D, which is also a GeListNode. So you can call GeListNode.Remove

However, note that you are in a generator and a generator is not supposed to change the scene structure (aka add a new object to it (and a marker is a new object). For more information see Threading Information. The correct way to do it would be to create a CommandData plugin.


Thank you @m_adam


worked in the Python Generator without crashing. I hope it isn't stupid to try this. I do plan on converting it to a plugin. Thanks, you can solve this question.