Below is a code snippet, nothing special. Just creates a panel in the 3dView.
The intreset here is in the Global variable “myObjs”.
If you run this, all seems well, and at first works as expected.
But…
Do something in the 3dView (object mode). Add a few objects and move them around.
All is still well.
Now, while watching the dos box (or whatever you call it on your os) hit Undo <ctrl>Z a few time.
The object held in myObjs changes. It starts iterating through all the objects in the scene.
This would be funny if I hadn’t discovered it half way through a project
Is this a bug in the blender/python implementation, or some odd behavior with python and Global vars that I don’t know about?
aljo
import bpy
myObjs = []
myObjs.append(bpy.data.objects[‘Cube’])
class MyPanelClass(bpy.types.Panel):
bl_space_type = ‘VIEW_3D’
bl_region_type = ‘UI’
bl_label = “My Panel”
@classmethod
def poll(self, context):
return True
def draw(self, context):
global myObjs
layout = self.layout
col = layout.column()
col.label(text="Some Text")
print(myObjs[0])