1
$\begingroup$

I try to explain the issu as clear as possible, but it will take a little while.

Background: Basically, what I try to do is to create two CollectionProperties in my scene and store custom PropertyGroup items in there. The two collections are not identical, there is members in one that the other one does not have, and the order and hierachy is different. With that said, I really would like to solve the problem behind in this way.

Problem: Some of the members should be part of both lists. That means, not only have the same values in there but really contain the same items, to be more clear, have the same result in the hash() function. Why? Only one of the collections will be used to display in a UI list, but both Collections shall respond to property updates.

Now, I already can create the Collections, fill them with items and assign the members to both, having the same hash() result. I can access the values and they are fine. So what's the point? The issue is, this only works as long as I am INSIDE the operators execute() function. When the operator finishes, one Collection still contains the data it should but the other one contains empty elements. The second collection is not empty, it has the right number of members, but the reference to the item in the other collection has been lost.

When I re-hookup the elements from the interactive Python console manually, everything works. simple code example here:

assume the collection prop has a name and zIndex prop. Then I do the following:

x = bpy.context.scene.col1.add()

x.name='col1'
x.zIndex=44

y = bpy.context.scene.col2.add()
y = x

print(y.zIndex)

this code above run from the interactive console will print 44, when run from inside the operator it will print 44 as well. However, when I just run the operator and then in the console get the value of bpy.context.scene.col2.zIndex it will print 0, while bpy.context.scene.col1.zIndex will still print 44.

Is there a way to get around this?

$\endgroup$
2
  • 1
    $\begingroup$ You can use an update function to keep both props in sync. skip to the "update example" here: blender.org/api/blender_python_api_2_66_4/bpy.props.html $\endgroup$
    – TLousky
    Oct 7, 2015 at 8:56
  • $\begingroup$ might be a workaround, but it does not explain why the reference to the other item is lost after operator exit. I suspect it is because my variable (y in the example) is removed by the Garbage Collection, but I am only guessing... $\endgroup$
    – aliasguru
    Oct 7, 2015 at 9:06

0

You must log in to answer this question.

Browse other questions tagged .