I am writing an exporter plugin. Before exporting, the existing modifiers should be applied to the objects (like subdivision surface, etc.). However, modifiers like Armature should not get applied.
The old version of the plugin copies the whole scene, applies the modifiers to the objects, and then removes that scene. However, this already produced many issues, e.g. if there occurs an error the copied scene will stay, effectively duplicating all materials and objects.
I already had a look at the to_mesh function. However, that only provides the option to either apply all modifiers or none, which is not what I want.
Is there a different way to apply only a specific set of modifiers without having to copy the object/scene?
Thanks, I gonna try that! There is still the issue that when the script crashes, the modifiers would still be disabled in render mode I guess. Thats definitely a smaller issue than having a lot of old scene copies, tho.
You can try/except the entire operation and tell the user about the error, but always revert the modifier settings to the original state in the finally-block.