1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
8 from bpy
.props
import *
12 class curvetoolsSelectedObjectHeader(bpy
.types
.Header
):
13 bl_label
= "Selection"
14 bl_space_type
= "VIEW_3D"
21 blenderSelectedObjects
= bpy
.context
.selected_objects
22 selectedObjects
= bpy
.context
.scene
.curvetools
.SelectedObjects
24 selectedObjectsToRemove
= []
25 for selectedObject
in selectedObjects
:
26 if not selectedObject
.IsElementOf(blenderSelectedObjects
): selectedObjectsToRemove
.append(selectedObject
)
27 for selectedObject
in selectedObjectsToRemove
: selectedObjects
.remove(selectedObject
)
29 blenderObjectsToAdd
= []
30 for blenderObject
in blenderSelectedObjects
:
31 if not curvetoolsSelectedObject
.ListContains(selectedObjects
, blenderObject
): blenderObjectsToAdd
.append(blenderObject
)
32 for blenderObject
in blenderObjectsToAdd
:
33 newSelectedObject
= curvetoolsSelectedObject(blenderObject
)
34 selectedObjects
.append(newSelectedObject
)
37 def draw(self
, context
):
38 selectedObjects
= bpy
.context
.scene
.curvetools
.SelectedObjects
39 nrSelectedObjects
= len(selectedObjects
)
43 row
.label(text
="Sel: " + str(nrSelectedObjects
))
46 class curvetoolsSelectedObject(bpy
.types
.PropertyGroup
):
47 name
: StringProperty(name
= "name", default
= "??")
51 def UpdateThreadTarget(lock
, sleepTime
, selectedObjectNames
, selectedBlenderObjectNames
):
54 newSelectedObjectNames
= []
56 for name
in selectedObjectNames
:
57 if name
in selectedBlenderObjectNames
: newSelectedObjectNames
.append(name
)
59 for name
in selectedBlenderObjectNames
:
60 if not (name
in selectedObjectNames
): newSelectedObjectNames
.append(name
)
62 # sometimes it still complains about the context
64 nrNewSelectedObjects
= len(newSelectedObjectNames
)
65 bpy
.context
.scene
.curvetools
.NrSelectedObjects
= nrNewSelectedObjects
67 selectedObjects
= bpy
.context
.scene
.curvetools
.SelectedObjects
68 selectedObjects
.clear()
69 for i
in range(nrNewSelectedObjects
): selectedObjects
.add()
70 for i
, newSelectedObjectName
in enumerate(newSelectedObjectNames
):
71 selectedObjects
[i
].name
= newSelectedObjectName
76 def GetSelectedObjectNames():
77 selectedObjects
= bpy
.context
.scene
.curvetools
.SelectedObjects
80 selectedObjectValues
= selectedObjects
.values()
81 for selectedObject
in selectedObjectValues
: rvNames
.append(selectedObject
.name
)
87 def GetSelectedBlenderObjectNames():
88 blenderSelectedObjects
= bpy
.context
.selected_objects
91 for blObject
in blenderSelectedObjects
: rvNames
.append(blObject
.name
)
97 bpy
.utils
.register_class(operators
)
101 bpy
.utils
.unregister_class(operators
)
103 if __name__
== "__main__":
107 curvetoolsSelectedObject
,