1 # GPL # Original Author Liero #
4 from bpy
.types
import Operator
5 from bpy
.props
import (
13 x
= sum([obj
.location
[0] for obj
in sel
]) / len(sel
)
14 y
= sum([obj
.location
[1] for obj
in sel
]) / len(sel
)
15 z
= sum([obj
.location
[2] for obj
in sel
]) / len(sel
)
20 bl_idname
= "object.parent_to_empty"
21 bl_label
= "Parent to Empty"
22 bl_description
= "Parent selected objects to a new Empty"
23 bl_options
= {"REGISTER", "UNDO"}
25 nombre
: StringProperty(
28 description
='Give the empty / group a name'
33 description
="Also add objects to a group"
37 items
=[('CURSOR', 'Cursor', 'Cursor'), ('ACTIVE', 'Active', 'Active'),
38 ('CENTER', 'Center', 'Selection Center')],
39 description
='Empty location',
45 description
="Add prefix to objects name"
49 def poll(cls
, context
):
50 objs
= context
.selected_objects
51 return (len(objs
) > 0)
53 def draw(self
, context
):
55 layout
.prop(self
, "nombre")
56 column
= layout
.column(align
=True)
57 column
.prop(self
, "locat")
58 column
.prop(self
, "grupo")
59 column
.prop(self
, "renom")
61 def execute(self
, context
):
62 objs
= context
.selected_objects
67 bpy
.ops
.object.mode_set()
71 if self
.locat
== 'CURSOR':
72 loc
= sce
.cursor
.location
73 elif self
.locat
== 'ACTIVE':
78 bpy
.ops
.object.add(type='EMPTY', location
=loc
)
79 context
.object.name
= self
.nombre
80 context
.object.show_name
= True
81 context
.object.show_in_front
= True
84 bpy
.ops
.collection
.create(name
=self
.nombre
)
85 bpy
.ops
.collection
.objects_add_active()
90 bpy
.ops
.object.parent_set(type='OBJECT')
92 bpy
.ops
.collection
.objects_add_active()
96 o
.name
= self
.nombre
+ '_' + o
.name
100 class PreFix(Operator
):
101 bl_idname
= "object.toggle_prefix"
102 bl_label
= "Toggle Sufix"
103 bl_description
= "Toggle parent name as sufix for c"
104 bl_options
= {"REGISTER", "UNDO"}
107 def poll(cls
, context
):
109 return (act
and act
.type == 'EMPTY')
111 def execute(self
, context
):
114 prefix
= act
.name
+ '_'
117 if o
.name
.startswith(prefix
):
123 if o
.name
.startswith(prefix
):
124 o
.name
= o
.name
.partition(prefix
)[2]
127 o
.name
= prefix
+ o
.name