Page MenuHome

Cannot change object layer with python if object is not in active scene
Closed, InvalidPublic

Description

System Information
Operating system: Arch Linux
Graphics card: GTX 1060

Blender Version
2.79b

Short description of error
Using python, I cannot change an object's visible layers if the object exists in a scene other than the active scene.

Exact steps for others to reproduce the error

  1. Create a new scene and add a cube to layer 1
  2. Try changing the object's layer with python:
import bpy

scene = bpy.data.scenes['Scene.001']
obj = scene.objects['Cube']

layer = 10
for i in reversed(range(20)):
    obj.layers[i] = (i == layer)

Event Timeline

Bastien Montagne (mont29) changed the task status from Unknown Status to Unknown Status.Aug 9 2018, 10:53 AM
Bastien Montagne (mont29) claimed this task.

We do not handle user support on this tracker, only bug reports. User forums like blenderartists.org or blender.stackexchange.com should be used for that matter.

No bug here, you can only use objects to change their layers in current active scene.

To do that in another scene, you have to use the object bases (which are sort of 'hooks' for objects into every given scene):

import bpy

scene = bpy.data.scenes['Scene.001']
base = scene.object_bases['Cube']

layer = 10
for i in reversed(range(20)):
    base.layers[i] = (i == layer)