2
$\begingroup$

I recently started to learn Python and I started to develop a selection pie, which the user can quickly select objects and quickly switch between selection sets, like working with multiple character rigs and each rig has it's own selection set.

I'm trying to figure out what is the simplest way to switch between multiple lists, that can be stored in scene? I haven't figured out how to append objects to a ID property list, so I'm using a regular list, that the stored scene lists refer to and vice versa. But my functions refer to that temp list('curList'), which isn't stored in the scene.

So my problem is how I can have a function "know" what list it needs to stored and disconnect from the('curList'), before it switches to another list? I thought about saving all lists before making the switch, but I get an error that 'object can't be iterated' or something like that. But as an noob, I haven't figured out a way around that issue? :)

Here is a very simple example of what I'm trying to have functions do automatically.

import bpy

ctx = bpy.context
scn = ctx.scene
scn['list_a'] = ['']
scn['list_b'] = ['']
curList = []

curList = scn['list_a']       # tempList connects to sceneList
curList.append('Cube')

scn['list_a'] = curList       # current sceneList gets updates from temp 
scn['list_a'] = scn['list_a'] # current sceneList disconnects from temp 

curList = scn['list_b']       # tempList switches to another sceneList
# etc.

Any suggestions or tips are hugely appreciated! :)

$\endgroup$
1
  • $\begingroup$ Hello, this looks like an XY problem to me that you're jumping through hoops to solve. The supported way to store lists in Blender is to use bpy.props.CollectionProperty. See there for an example. Also since lists are not value types the variables only store a pointer to the construct in memory so curList = scn['list_a'] and scn['list_a'] = curList are redundant $\endgroup$
    – Gorgious
    Commented Aug 31, 2022 at 5:49

1 Answer 1

0
$\begingroup$

This is my current solution that seems to work? But I'm sure there is a much better way out there!? :)

def list_obj_append(Id):
    global curList
    obj_selected = [o for o in bpy.data.objects if o.select]

    curList = scn["set_1"]
    scn["set_1"] = curList

    for ob in obj_selected:
        curList.append(ob.name + suffix[Id])

    scn["set_1"] = curList
    curList = scn["set_1"]

    return curList
$\endgroup$
0

You must log in to answer this question.

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