Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created November 27, 2015 14:41
Show Gist options
  • Save zeffii/9edee1b182bc8a05dac7 to your computer and use it in GitHub Desktop.
Save zeffii/9edee1b182bc8a05dac7 to your computer and use it in GitHub Desktop.
bl_info = {
"name": "Align Geometry",
"author": "Dealga McArdle",
"version": (0, 1),
"blender": (2, 7, 6),
"location": "",
"description": "align mid, neg, pos",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"
}
import bpy
import bmesh
def align(mode, axis):
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
if mode == 'm':
a = bm.faces.active.calc_center_median()
amount = getattr(a, axis)
for f in bm.faces:
if f == bm.faces.active:
continue
if f.select:
p = f.calc_center_median()
pamount = getattr(p, axis)
diff = amount - pamount
for v in f.verts:
co = v.co
pos = getattr(co, axis)
setattr(co, axis, pos + diff)
bmesh.update_edit_mesh(me, True)
class MeshAlignVerts(bpy.types.Operator):
""" tooltip"""
bl_label = "Align Geometry"
bl_idname = "mesh.zs_align_geometry"
def execute(self, context):
scn = context.scene
align(mode=scn.zs_selected_mode, axis=scn.zs_selected_axis)
return {'FINISHED'}
class ZSAlignPanel(bpy.types.Panel):
""" tooltip"""
bl_label = "zs align panel"
bl_idname = "SCENE_PT_layout_align"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
layout = self.layout
scn = context.scene
col = layout.column()
col.prop(scn, "zs_selected_mode", expand=True)
col.prop(scn, "zs_selected_axis", expand=True)
row = layout.row(align=True)
row.operator('mesh.zs_align_geometry', text='Align')
def register():
S = bpy.types.Scene
S.zs_selected_mode = bpy.props.EnumProperty(
items=[(n, n, '', i) for i, n in enumerate('m+-')],
description="offers mode of alignment",
default="m"
)
S.zs_selected_axis = bpy.props.EnumProperty(
items=[(n, n, '', i) for i, n in enumerate('xyz')],
description="offers axis selection",
default="z"
)
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_class(__name__)
S = bpy.types.Scene
del S.zs_selected_mode
del S.zs_selected_axis
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment