From be32f6d5b8f9ec06718bb107a2cd7e648636a6b7 Mon Sep 17 00:00:00 2001
From: Stephen Swaney <sswaney@centurytel.net>
Date: Mon, 11 Oct 2004 20:33:51 +0000
Subject: [PATCH] bugfix: #1624  Can not switch layers of some objects through
 python.

All Bases were not getting updated with new layer.
---
 source/blender/python/api2_2x/Object.c | 28 +++++++++++++++-----------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index e0d0f626eab0..bdb3ad33a51c 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -2336,25 +2336,29 @@ static int Object_setAttr( BPy_Object * obj, char *name, PyObject * value )
 		Base *base;
 		int newLayer;
 		int local;
-		if( PyArg_Parse( value, "i", &newLayer ) ) {
-			/* uppper 2 bytes are for local view */
-			newLayer &= 0x00FFFFFF;
-			if( newLayer == 0 )	/* bail if nothing to do */
-				return ( 0 );
 
-			/* update any bases pointing to our object */
-			base = FIRSTBASE;
+		if( ! PyArg_Parse( value, "i", &newLayer ) ) {
+			return EXPP_ReturnIntError( PyExc_AttributeError,
+						    "expected int as bitmask" );
+		}
+
+		/* uppper 2 nibbles are for local view */
+		newLayer &= 0x00FFFFFF;
+		if( newLayer == 0 )	/* bail if nothing to do */
+			return ( 0 );
+		
+		/* update any bases pointing to our object */
+		base = FIRSTBASE;  /* first base in current scene */
+		while( base ){
 			if( base->object == obj->object ) {
 				local = base->lay &= 0xFF000000;
 				base->lay = local | newLayer;
 				object->lay = base->lay;
 			}
-			countall(  );
-		} else {
-			return EXPP_ReturnIntError( PyExc_AttributeError,
-						    "expected int as bitmask" );
+			base = base->next;
 		}
-
+		countall(  );
+		
 		return ( 0 );
 	}
 	if( StringEqual( name, "parent" ) ) {
-- 
GitLab