Skip to content

Instantly share code, notes, and snippets.

@mio3io
Last active June 8, 2024 01:52
Show Gist options
  • Save mio3io/efb85127dfd6c953c9d98d338e594555 to your computer and use it in GitHub Desktop.
Save mio3io/efb85127dfd6c953c9d98d338e594555 to your computer and use it in GitHub Desktop.
import bpy
bl_info = {
"name": "Mio3 AlignVertices",
"author": "mio",
"version": (1, 2, 0),
"blender": (3, 6, 0),
"warning": "",
"location": "View3D > Sidebar > Edit Tab",
"description": "",
"category": "Mesh",
}
class MIO3SAV_OT_Align(bpy.types.Operator):
bl_idname = "mesh.align_vertices"
bl_label = "Align Vertices"
bl_description = "Align Vertices"
bl_options = {"REGISTER", "UNDO"}
type: bpy.props.EnumProperty(
items=[
("X", "X", "Align Vertices X"),
("Y", "Y", "Align Vertices Y"),
("Z", "Z", "Align Vertices Z"),
("ALL", "All", "Align Vertices All"),
],
name="type",
default="X",
)
orientation: bpy.props.EnumProperty(
items=[
("DEFAULT", "Default", "Use the default transform orientation"),
("GLOBAL", "Global", "Align vertices in global space"),
("LOCAL", "Local", "Align vertices in local space"),
("VIEW", "View", "Align vertices in view space"),
("NORMAL", "Normal", "Align vertices in normal space"),
("GIMBAL", "Gimbal", "Align vertices in gimbal space"),
("CURSOR", "Cursor", "Align vertices in cursor space"),
],
name="Orientation",
default="DEFAULT",
)
scale: bpy.props.FloatProperty(
name="Scale",
default=0.0,
min=0.0,
max=1.0
)
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
if self.type == "X":
value = (self.scale, 1, 1)
elif self.type == "Y":
value = (1, self.scale, 1)
elif self.type == "Z":
value = (1, 1, self.scale)
else:
value = (self.scale, self.scale, self.scale)
if self.orientation == "DEFAULT":
orient_type = context.scene.transform_orientation_slots[0].type
else:
orient_type = self.orientation
bpy.ops.transform.resize(
value=value,
orient_type=orient_type,
orient_matrix_type=orient_type,
)
return {"FINISHED"}
class MIO3SAV_PT_Mio3AlignVertices(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Edit"
bl_context = "mesh_edit"
bl_label = "Mio3AlignVertices"
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.operator(MIO3SAV_OT_Align.bl_idname, text="X").type = "X"
row.operator(MIO3SAV_OT_Align.bl_idname, text="Y").type = "Y"
row.operator(MIO3SAV_OT_Align.bl_idname, text="Z").type = "Z"
row.operator(MIO3SAV_OT_Align.bl_idname, text="All").type = "ALL"
classes = [
MIO3SAV_PT_Mio3AlignVertices,
MIO3SAV_OT_Align,
]
def register():
for c in classes:
bpy.utils.register_class(c)
def unregister():
for c in reversed(classes):
bpy.utils.unregister_class(c)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment