Modifying card ordinals programatically


Quick question, is there a check hidden somewhere in the Anki code that checks for/corrects multiple cards with the same ordinal? Or syncs cards with notes as soon as you write to either? I am currently doing this:

for nid in nids:
  note = col.get_note(nid)
    if note.note_type().get('type', MODEL_STD) != MODEL_CLOZE: continue

    note_cards = {str(card.ord + 1): card for card in}
    i = 0

    def substitute(match):
        nonlocal i, cards
        i += 1
        card = note_cards[]
        card.ord = i - 1
        return rf'{{{{c{i}::'

    for fld in note.keys():
        note[fld] = re.sub(r'{{c(\d+)::', substitute, note[fld])



It seems to work but I just want to make sure that there aren’t edge cases where Anki “fixes” the cards while I am restructuring the cards and notes.

Any thoughts?

Aside from Check Database, it should leave them alone.

Perfect, thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.