I am trying to replicate the functionality of Object Parent using the dropper select tool in Python (an image is attached for what exactly am I trying to replicate).:
For this purpose, I am using the PointerProperty to get a pointer to the object. Most of the functionalities work as expected, similar to the implementation above. However, if I delete the object (either using the keyboard shortcuts or the python method), it disappears from the 3D view but it is still present in bpy.data.objects. Moreover, the PointerProperty does not clear the object field as is the case with the original object parent field. I have tested this in Blender 2.79 and 2.81 with similar results. Any suggestions would be appreciated. This is the code I am using.
import bpy
bl_info = {
"name": "Pointer Property Test",
"author": "Mr. Potato",
"version": (0, 1),
"blender": (2, 79, 0)
}
class PT_test_constraint(bpy.types.Panel):
"""Add Rigid Body Properties"""
bl_label = "TEST PROPERTIES"
bl_idname = "addon.test_constraint"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context= "physics"
bpy.types.Object.test_constraint_parent = bpy.props.PointerProperty(name="Parent", type=bpy.types.Object)
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop_search(context.object, "test_constraint_parent", context.scene, "objects")
def register():
from bpy.utils import register_class
register_class(PT_test_constraint)
def unregister():
from bpy.utils import unregister_class
unregister_class(PT_test_constraint)
if __name__ == "__main__":
register()
#unregister()
bpy.data.objects.remove(ob)
the object it will also be gone from the pointer prop. Might find this useful blender.stackexchange.com/a/101301/15543. Also recommend declaring properties in the register method, rather than in panel class. $\endgroup$parent_object
(selected by the PointerProperty) has less than 2 users (as if it has less than 2 users, it would mean that someone deleted it from the scene graph using the keyboard delete key). If so, I should callbpy.data.objects.remove(parent_object)
in the Labelspoll()
method so that it is safely removed from the PointerProperty and bpy.data.objects. Does this seem reasonable? $\endgroup$parent
is a special case that is quite likely dealt with by the depsgraph when the object is unlinked from scene or deleted. A getter / setter approach on the property could be the go, setting toNone
if the pointer is not in the scene. $\endgroup$