Edit the fiels of note imported from file

I’m writing an add-on to edit the fields of note before saving it and generating the cards. I managed to do this for notes added through Add dialogue, using add_cards_will_add_note, but it seems not to work when the note is imported from file. What is the correct approach?

It may be possible if you wrap anki.collection.Collection.add_note.

def my_function(col: Collection, note: Note, did: DeckId):
    ...

anki.collection.Collection.add_note = anki.hooks.wrap(
    old=anki.collection.Collection.add_note,
    new=my_function,
    pos='before',
)

That hook/routine is not used when importing, and there is not a way to intercept the importing using the new standard importer. Your best bet would be to apply changes to the notes after importing completes.

Is there a specific hook for it or I’ll have to find a workaround?

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