1 # SPDX-FileCopyrightText: 2015-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Original Author Liero
8 from bpy
.types
import Operator
9 from bpy
.props
import (
17 x
= sum([obj
.location
[0] for obj
in sel
]) / len(sel
)
18 y
= sum([obj
.location
[1] for obj
in sel
]) / len(sel
)
19 z
= sum([obj
.location
[2] for obj
in sel
]) / len(sel
)
24 bl_idname
= "object.parent_to_empty"
25 bl_label
= "Parent to Empty"
26 bl_description
= "Parent selected objects to a new Empty"
27 bl_options
= {"REGISTER", "UNDO"}
29 nombre
: StringProperty(
32 description
='Give the empty / group a name'
37 description
="Also add objects to a group"
41 items
=[('CURSOR', 'Cursor', 'Cursor'), ('ACTIVE', 'Active', 'Active'),
42 ('CENTER', 'Center', 'Selection Center')],
43 description
='Empty location',
49 description
="Add prefix to objects name"
53 def poll(cls
, context
):
54 objs
= context
.selected_objects
55 return (len(objs
) > 0)
57 def draw(self
, context
):
59 layout
.prop(self
, "nombre")
60 column
= layout
.column(align
=True)
61 column
.prop(self
, "locat")
62 column
.prop(self
, "grupo")
63 column
.prop(self
, "renom")
65 def execute(self
, context
):
66 objs
= context
.selected_objects
71 bpy
.ops
.object.mode_set()
75 if self
.locat
== 'CURSOR':
76 loc
= sce
.cursor
.location
77 elif self
.locat
== 'ACTIVE':
82 bpy
.ops
.object.add(type='EMPTY', location
=loc
)
83 context
.object.name
= self
.nombre
84 context
.object.show_name
= True
85 context
.object.show_in_front
= True
88 bpy
.ops
.collection
.create(name
=self
.nombre
)
89 bpy
.ops
.collection
.objects_add_active()
94 bpy
.ops
.object.parent_set(type='OBJECT')
96 bpy
.ops
.collection
.objects_add_active()
100 o
.name
= self
.nombre
+ '_' + o
.name
104 class PreFix(Operator
):
105 bl_idname
= "object.toggle_prefix"
106 bl_label
= "Toggle Sufix"
107 bl_description
= "Toggle parent name as sufix for c"
108 bl_options
= {"REGISTER", "UNDO"}
111 def poll(cls
, context
):
113 return (act
and act
.type == 'EMPTY')
115 def execute(self
, context
):
118 prefix
= act
.name
+ '_'
121 if o
.name
.startswith(prefix
):
127 if o
.name
.startswith(prefix
):
128 o
.name
= o
.name
.partition(prefix
)[2]
131 o
.name
= prefix
+ o
.name