1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Original Author Liero
6 from bpy
.types
import Operator
7 from bpy
.props
import (
15 x
= sum([obj
.location
[0] for obj
in sel
]) / len(sel
)
16 y
= sum([obj
.location
[1] for obj
in sel
]) / len(sel
)
17 z
= sum([obj
.location
[2] for obj
in sel
]) / len(sel
)
22 bl_idname
= "object.parent_to_empty"
23 bl_label
= "Parent to Empty"
24 bl_description
= "Parent selected objects to a new Empty"
25 bl_options
= {"REGISTER", "UNDO"}
27 nombre
: StringProperty(
30 description
='Give the empty / group a name'
35 description
="Also add objects to a group"
39 items
=[('CURSOR', 'Cursor', 'Cursor'), ('ACTIVE', 'Active', 'Active'),
40 ('CENTER', 'Center', 'Selection Center')],
41 description
='Empty location',
47 description
="Add prefix to objects name"
51 def poll(cls
, context
):
52 objs
= context
.selected_objects
53 return (len(objs
) > 0)
55 def draw(self
, context
):
57 layout
.prop(self
, "nombre")
58 column
= layout
.column(align
=True)
59 column
.prop(self
, "locat")
60 column
.prop(self
, "grupo")
61 column
.prop(self
, "renom")
63 def execute(self
, context
):
64 objs
= context
.selected_objects
69 bpy
.ops
.object.mode_set()
73 if self
.locat
== 'CURSOR':
74 loc
= sce
.cursor
.location
75 elif self
.locat
== 'ACTIVE':
80 bpy
.ops
.object.add(type='EMPTY', location
=loc
)
81 context
.object.name
= self
.nombre
82 context
.object.show_name
= True
83 context
.object.show_in_front
= True
86 bpy
.ops
.collection
.create(name
=self
.nombre
)
87 bpy
.ops
.collection
.objects_add_active()
92 bpy
.ops
.object.parent_set(type='OBJECT')
94 bpy
.ops
.collection
.objects_add_active()
98 o
.name
= self
.nombre
+ '_' + o
.name
102 class PreFix(Operator
):
103 bl_idname
= "object.toggle_prefix"
104 bl_label
= "Toggle Sufix"
105 bl_description
= "Toggle parent name as sufix for c"
106 bl_options
= {"REGISTER", "UNDO"}
109 def poll(cls
, context
):
111 return (act
and act
.type == 'EMPTY')
113 def execute(self
, context
):
116 prefix
= act
.name
+ '_'
119 if o
.name
.startswith(prefix
):
125 if o
.name
.startswith(prefix
):
126 o
.name
= o
.name
.partition(prefix
)[2]
129 o
.name
= prefix
+ o
.name