Created
November 27, 2015 11:16
-
-
Save zeffii/7a943ef34c7fa7fc2b93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import bmesh | |
class MeshAlignVerts(bpy.types.Operator): | |
bl_idname = "mesh.align_verts" | |
bl_label = "Align verts pos" | |
bl_options = {'REGISTER', 'UNDO'} | |
unlocked = bpy.props.BoolProperty() | |
def update_unlock(self, context): | |
self.unlocked = True | |
# update individual verts | |
def update_indiv_vert_pos(self,context): | |
mesh=bmesh.from_edit_mesh(context.object.data) | |
sel_verts = [] | |
for v in mesh.verts: | |
if v.select: | |
sel_verts.append(v) | |
# TODO: Add logic to move points along custom defined transform orientation | |
# bpy.context.space_data.transform_orientation = 'GLOBAL' | |
for v in sel_verts: | |
if self.chosen_axis == 'X': | |
v.co.x = self.x_pos | |
if self.chosen_axis == 'Y': | |
v.co.y = self.y_pos | |
if self.chosen_axis == 'Z': | |
v.co.z = self.z_pos | |
x_pos = bpy.props.FloatProperty(name="X",description="X axis",default=0.0) | |
y_pos = bpy.props.FloatProperty(name="Y",description="Y axis",default=0.0) | |
z_pos = bpy.props.FloatProperty(name="Z",description="Z axis",default=0.0) | |
chosen_axis = bpy.props.EnumProperty( | |
items=(('X','X','Align along X axis'),('Y','Y','Align along Y axis'),('Z','Z','Align along Z axis')), | |
name="Choose Axis") | |
def execute(self,context): | |
print (self.chosen_axis) | |
if self.unlocked: | |
self.update_indiv_vert_pos(context) | |
print ("Executed script") | |
return {'FINISHED'} | |
def draw(self, context): | |
scn = context.scene | |
l = self.layout | |
col = l.column() | |
col.prop(self, 'x_pos') | |
col.prop(self, 'y_pos') | |
col.prop(self, 'z_pos') | |
col.prop(self, 'chosen_axis') | |
col.operator('mesh.align_verts', text='Mesh Align').unlocked = True | |
def register(): | |
bpy.utils.register_class(MeshAlignVerts) | |
def unregister(): | |
bpy.utils.unregister_class(MeshAlignVerts) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment