4
$\begingroup$

I have a list declared like this -

m_list = own.get("m_list")

Now the problem is I can't access this list from another object. How do I declare the list so that I can access it from another object. I have to check whether or not an element exists.

$\endgroup$

1 Answer 1

5
$\begingroup$

If you want data to be global in Python, (within a Blender session).

Typically its best to create a module with a unique name specific to your project, import it - and access variables in that module.

Every script which imports the module will be viewing the same data.

In this exact case it sounds like you should add the object it self to a module.

import my_module
my_module.my_obj = obj

Some other script

import my_module
obj = my_module.my_obj
$\endgroup$
2
  • $\begingroup$ I don't think this works anymore in blender 2.8+ since other textblocks are now loaded with "bpy.data.texts['textblock.py'].as_module()" instead of import and variables don't seem to be global anymore. $\endgroup$
    – MrTheRich
    Commented Nov 20, 2020 at 10:22
  • $\begingroup$ While text blocks can no longer be imported. The answer doesn't mention them, you can use files for this. $\endgroup$
    – ideasman42
    Commented Nov 20, 2020 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .