Skip to content
Snippets Groups Projects
Commit 1883ee23 authored by Brendon Murphy's avatar Brendon Murphy
Browse files

update parent to mesh, update & fix crasher in mesh_round_cube, update init.

parent ffaddb3a
Branches
Tags
No related merge requests found
...@@ -200,7 +200,7 @@ class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu): ...@@ -200,7 +200,7 @@ class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu):
def menu_func(self, context): def menu_func(self, context):
self.layout.separator() self.layout.separator()
self.layout.menu("INFO_MT_mesh_vert_add", text="Single Vert", icon="LAYER_ACTIVE") self.layout.menu("INFO_MT_mesh_vert_add", text="Single Vert", icon="LAYER_ACTIVE")
self.layout.menu("INFO_MT_mesh_round_cube_add", text="Round Cube", icon="WIRE") self.layout.operator("mesh.primitive_round_cube_add", text="Round Cube", icon="MOD_SUBSURF")
self.layout.menu("INFO_MT_mesh_math_add", text="Math Function", icon="PACKAGE") self.layout.menu("INFO_MT_mesh_math_add", text="Math Function", icon="PACKAGE")
self.layout.menu("INFO_MT_mesh_pipe_joints_add", text="Pipe Joints", icon="SNAP_PEEL_OBJECT") self.layout.menu("INFO_MT_mesh_pipe_joints_add", text="Pipe Joints", icon="SNAP_PEEL_OBJECT")
self.layout.menu("INFO_MT_mesh_gears_add", text="Gears", icon="SCRIPTWIN") self.layout.menu("INFO_MT_mesh_gears_add", text="Gears", icon="SCRIPTWIN")
......
# GPL # Original Author Liero # # GPL # Original Author Liero #
import bpy import bpy
from bpy.props import StringProperty, FloatProperty, BoolProperty, FloatVectorProperty from bpy.props import StringProperty, BoolProperty, EnumProperty
def centro(objetos): def centro(sel):
x = sum([obj.location[0] for obj in objetos])/len(objetos) x = sum([obj.location[0] for obj in sel])/len(sel)
y = sum([obj.location[1] for obj in objetos])/len(objetos) y = sum([obj.location[1] for obj in sel])/len(sel)
z = sum([obj.location[2] for obj in objetos])/len(objetos) z = sum([obj.location[2] for obj in sel])/len(sel)
return (x,y,z) return (x,y,z)
class P2E(bpy.types.Operator): class P2E(bpy.types.Operator):
bl_idname = 'object.parent_to_empty' bl_idname = 'object.parent_to_empty'
bl_label = 'Parent Selected to Empty' bl_label = 'Parent to Empty'
bl_description = 'Parent selected objects to a new Empty' bl_description = 'Parent selected objects to a new Empty'
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
nombre = StringProperty(name='', default='OBJECTS', description='Give the empty / group a name') nombre = StringProperty(name='', default='OBJECTS', description='Give the empty / group a name')
grupo = bpy.props.BoolProperty(name='Create Group', default=False, description='Also link objects to a new group') grupo = bpy.props.BoolProperty(name='Create Group', default=False, description='Also add objects to a group')
cursor = bpy.props.BoolProperty(name='Cursor Location', default=False, description='Add the empty at cursor / selection center') locat = bpy.props.EnumProperty(name='', items=[('CURSOR','Cursor','Cursor'),('ACTIVE','Active','Active'),
renombrar = bpy.props.BoolProperty(name='Rename Objects', default=False, description='Rename child objects') ('CENTER','Center','Selection Center')],description='Empty location', default='CENTER')
renom = bpy.props.BoolProperty(name='Add Prefix', default=False, description='Add prefix to objects name')
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return (context.object and context.object.select) objs = context.selected_objects
return (len(objs) > 0)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
layout.prop(self,'nombre') layout.prop(self,'nombre')
column = layout.column(align=True) column = layout.column(align=True)
column.prop(self,'locat')
column.prop(self,'grupo') column.prop(self,'grupo')
column.prop(self,'cursor') column.prop(self,'renom')
column.prop(self,'renombrar')
def execute(self, context): def execute(self, context):
objs = bpy.context.selected_objects objs = context.selected_objects
bpy.ops.object.mode_set() act = context.object
if self.cursor: sce = context.scene
loc = context.scene.cursor_location try: bpy.ops.object.mode_set()
except: pass
if self.locat == 'CURSOR':
loc = sce.cursor_location
elif self.locat == 'ACTIVE':
loc = act.location
else: else:
loc = centro(objs) loc = centro(objs)
bpy.ops.object.add(type='EMPTY',location=loc) bpy.ops.object.add(type='EMPTY',location=loc)
bpy.context.object.name = self.nombre context.object.name = self.nombre
context.object.show_name = True
context.object.show_x_ray = True
if self.grupo: if self.grupo:
bpy.ops.group.create(name=self.nombre) bpy.ops.group.create(name=self.nombre)
bpy.ops.group.objects_add_active() bpy.ops.group.objects_add_active()
for o in objs: for o in objs:
o.select = True o.select = True
if not o.parent: if not o.parent:
bpy.ops.object.parent_set(type='OBJECT') bpy.ops.object.parent_set(type='OBJECT')
if self.grupo: if self.grupo:
bpy.ops.group.objects_add_active() bpy.ops.group.objects_add_active()
o.select = False o.select = False
for o in objs: for o in objs:
if self.renombrar: if self.renom:
o.name = self.nombre+'_'+o.name o.name = self.nombre+'_'+o.name
return {'FINISHED'} return {'FINISHED'}
\ No newline at end of file
class PreFix(bpy.types.Operator):
bl_idname = 'object.toggle_prefix'
bl_label = 'Toggle Sufix'
bl_description = 'Toggle parent name as sufix for c'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
act = bpy.context.object
return (act and act.type == 'EMPTY')
def execute(self, context):
act = bpy.context.object
objs = act.children
prefix = act.name+'_'
remove = False
for o in objs:
if o.name.startswith(prefix):
remove = True
break
if remove == True:
for o in objs:
if o.name.startswith(prefix):
o.name = o.name.partition(prefix)[2]
else:
for o in objs:
o.name = prefix+o.name
return {'FINISHED'}
class PanelP2E(bpy.types.Panel):
bl_label = 'Parent to Empty'
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = 'Relations'
def draw(self, context):
layout = self.layout
layout.operator('object.parent_to_empty')
layout.operator('object.toggle_prefix')
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment