Why col.models.setCurrent(another_model) doesn't work?

hello,

I’m doing some scripting, now I want to change the current model to make new note.

but col.models.setCurrent(another_model) seems not work, can you help me fix it out?

thanks!

    elsa = Elsa()
    math_model = elsa.col.models.byName('math')
    elsa.col.models.setCurrent(math_model)
    elsa.col.conf['curModel'] = math_model['id']
    print(elsa.col.models.current()['name'])

it turns out that the current model doesn’t change.

Two caveats: I’m just an Anki user and I have no idea what’s Elsa.

In Anki after models.setCurrent you might need models.save(mymodel), check the rest of the source code of Anki or e.g. add-ons like this one.

1 Like

The “current model” may be relative to the deck or the collection depending on the user’s options - see the code of current() to see what it’s doing.

thanks for the guiding, now i understood.

thanks for your reply, it’s a good way to find solutions.

BTW, how to set the current model for a deck?

Have a look at modelchooser.py

1 Like

thx!!