Adding new objects from Python while in local-view


In 2.8 how should addons add new objects while the user is in local-view mode and have them show up immediately?

In 2.7x this was accomplished by calling layers_from_view on the newly added object:

Example Scenario:

  • User is focused on a particular object in local-view
  • User invokes an addon to wrap the selected object in a new Lattice object
    lattice ='dc_lattice')
    lattice_object ='dc_lattice', lattice)
  • This new lattice object should be visible in local-view immediately (as-if the user had selected both objects before going into local-view)

The api no longer seems to exist and I’m unable to find an equivalent when searching. Should the addon manually go in/out of local-view mode and perform the selection itself?

Note: Objects added by calls to bpy.ops.mesh.primitive_* are shown in local view immediately. Somehow, intentionally or not, they are handling this mode (which is a good thing™)


Well for now I’m doing the following inside the op:

    # Toggle out of local-view mode and re-enter to ensure lattice shows up
    if context.space_data.local_view is not None: