importNotes() always adds cards to default deck

I am rewriting my addon for importing mind maps into anki. My class inherits from the Noteimporter class and uses its importNotes() method. Everything works fine already except that no matter what I do, the cards always get added to the default deck (did = 1). I already call col.decks.select() to select the preferred deck and I also tried adding the did to the ForeignNotes which are used as input for importNotes() but for some reason the notes still get imported to the default deck every time.col.decks.selected() does return the preferred did in the moment the cards are created (in after_note_updates()).

Does anyone know what else I can do to set the deck that I want to import my cards to?

This is covered in https://addon-docs.ankiweb.net/#/getting-started?id=the-collection

1 Like

Thank you for the link! I added the code from the guide to my importer but sadly it did not change anything. The cards are still imported to the default deck.

I temporarily solved the problem by manually moving all imported cards to the desired deck afterwards but I would still be very interested in finding the cause.

1 Like

I’ve updated the code there to add a .save() call that may have been required - please try it again.

1 Like

Thank you very much! This was the solution :slight_smile:

Hi, last year I used this solution for one of my anki add-on and it solved my problem too, but since version 2.1.45 this does not work anymore. I’m not sure what changes were made to anki. When I check the database for the new anki versions all new cards are assigned “did” = 1, which is the default deck. Below is the current code.

    did = mw.col.decks.id(deck)
    mw.col.decks.select(did)

    model = mw.col.models.byName(modelName)

    if not model:
        model = mw.col.models.new(modelName)
        mw.col.models.add(model)

        template = mw.col.models.newTemplate("Default")
        mw.col.models.addTemplate(model, template)

    deck = mw.col.decks.get(did)
    deck['mid'] = model['id']
    mw.col.decks.save(deck)

    model['did'] = did
    mw.col.models.save(model)
...
...
..

You can use the following for now; it will likely be improved when the importing code gets an overhaul.

        mw.col.set_aux_notetype_config(
            notetype_id, "lastDeck", deck_id
        )
1 Like

Thanks, it worked.