Necessary to set an object as active when accessing/exporting properties?

I was doing some code clean-up for my add-ons and I noticed that at one point when iterating through the selected objects in the scene i was setting the current object in the iteration as the ‘active’ object before accessing and exporting certain mesh and armature properties.

I can’t recall why I was doing that in the first place (this part of the code was written a while ago), but removing it doesn’t seem to affect what I need my add-ons to do (basically just exporting to some custom mesh and armature file formats).

Would there be any particular reasons why an object would need to be set as ‘active’ if just accessing mesh and animation properties?

As long as you are not “evaluating” final mesh with modifiers / shape keys / animation, and not using any operator, should not be needed at all.

It might have had something to do with shape keys, now that I think of it. I was probably messing around with that and noticed it wasn’t exporting properly without first setting to active. I don’t actually need to use shape keys as it’s really just non-deforming type animations. So I’m really just exporting:

  • Mesh:
    vertices, vertex normals, texture coordinates, faces, bones (position, rotation, scale), and bone weights

  • Armature:
    bone properties (position, rotation, scale) for each individual frame of a ‘standard’ animation (just simple changes in position and rotation)

I may just leave the ‘active’ selection in-tact to future-proof the code, just in case.

Thanks for the reply. I appreciate it.

Take a look at recent changes in API, segei’s changes to “evaluate” mesh through depsgraph if you need final mesh with shapes keys on it, but even in this case the active state should not be required.

Reading up on it right now (https://wiki.blender.org/wiki/Source/Depsgraph ; https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Scene_and_Object_API). Just a quick preliminary skim through, I noticed the last section “everything is a node”. I wonder if this is moving in the direction of 3ds Max’s notion of a node…

Anyways, I still need to port my add-ons to 2.80 (it’s still going to be a while before I adopt 2.80 exclusively). I’ll keep your suggestion in mind. Thanks for the help.