I have the following data in my script:
- Any mesh object, referenced as context.active_object
- bpy.types.Object.markers = CollectionProperty(type = Marker), where Marker is a class containing just id, name and single vector to store location
- ui with the UIList, on which I draw elements from the markers list
I have also a number of classes for making data, addings objects, etc. The script allows to easily click on a mesh and add new empty in the 3dcursor location. I have all those empties parented to the object, and I'm collecting their names in markers collection. All items for a mesh object is draw in a list using UIList. Here is my draw_items function:
class MarkerList(UIList):
def draw_item(self,context,layout,data,item,icon,active_data,active_progname):
if not item or item.name == '':
layout.row().label('no name for id'+str(item.id),icon='CANCEL')
else:
if item.name in bpy.data.objects.keys():
ob = bpy.data.objects[item.name]
layout.prop(data=ob,property='name',icon='PINNED',emboss=False,text='')
else:
lab = layout.label(icon='QUESTION',text=item.name)
Now, the UIList is showing props using their names (data=ob, property='name'). That's OK, BUT, if somebody double click the name, it could be changed. This change also changes the name of the real empty object. I would like to update also markers list for that change, but I do not know how.
So, IS there any kind of 'update' function which is called after changing the name of the prop from the list? Or 'notify', or whatever. I would like to keep markers as a simple list of names and locations, but also I would like to allow user to change their names. If that's not possible, alternative question is: how to block names change in the UIlist?
Also, sorry for poor formulated question, I had no better idea how to ask how to detect name change of objects changed in UIList and invoking some additional action after that (ie. updating my markers list name).
Here is the UIList:
The counter is just a IntProperty added to bpy.types.Object.
Here is the name double clicked in the list:
It is automatically selected and user can change the name of the real object.
Here is the name changed by the user:
After this change, the real name of the object is changed, which is desired. I don't know, how to update the name in my own list, so I put the condition:
if item.name in bpy.data.objects.keys():
in draw_items to at least show this in the list. But I want to update my own data instead. After name is changed, the following info appears in the info window:
My list is looking like that at this stage:
My outliner is showing the change of new name of the object parented:
So, any advice will be most welcome. I can either block this editing behaviour (how?) or allow to detect name change of specific item and update markers data respectively. The script is going to manage thousands of those objects.