79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
bl_info = {
|
|
"name": "Reverse Polyline Vertices",
|
|
"author": "ChatGPT + Ryan",
|
|
"version": (1, 0),
|
|
"blender": (2, 80, 0),
|
|
"location": "Mesh > Vertices > Reverse Polyline Vertices",
|
|
"description": "Reverses the vertex order along a selected polyline in edit mode",
|
|
"category": "Mesh",
|
|
}
|
|
|
|
import bpy
|
|
import bmesh
|
|
|
|
class MESH_OT_reverse_polyline_vertices(bpy.types.Operator):
|
|
"""Reverse the vertex positions of a selected polyline"""
|
|
bl_idname = "mesh.reverse_polyline_vertices"
|
|
bl_label = "Reverse Polyline Vertices"
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
@classmethod
|
|
def poll(cls, context):
|
|
return (context.active_object is not None and
|
|
context.active_object.type == 'MESH' and
|
|
context.mode == 'EDIT_MESH')
|
|
|
|
def execute(self, context):
|
|
obj = context.edit_object
|
|
bm = bmesh.from_edit_mesh(obj.data)
|
|
|
|
edges = [e for e in bm.edges if e.select]
|
|
if not edges:
|
|
self.report({'WARNING'}, "No selected edges found")
|
|
return {'CANCELLED'}
|
|
|
|
verts = []
|
|
edge = edges[0]
|
|
v1, v2 = edge.verts
|
|
visited = {v1}
|
|
verts.append(v1)
|
|
current = v1
|
|
|
|
while True:
|
|
link_edges = [e for e in current.link_edges if e in edges]
|
|
next_vert = None
|
|
for e in link_edges:
|
|
other = e.other_vert(current)
|
|
if other not in visited:
|
|
next_vert = other
|
|
break
|
|
if not next_vert:
|
|
break
|
|
visited.add(next_vert)
|
|
verts.append(next_vert)
|
|
current = next_vert
|
|
|
|
if len(verts) < 2:
|
|
self.report({'WARNING'}, "Not enough vertices to reverse")
|
|
return {'CANCELLED'}
|
|
|
|
for i in range(len(verts)//2):
|
|
verts[i].co, verts[-1-i].co = verts[-1-i].co.copy(), verts[i].co.copy()
|
|
|
|
bmesh.update_edit_mesh(obj.data)
|
|
self.report({'INFO'}, "Polyline vertex order reversed")
|
|
return {'FINISHED'}
|
|
|
|
def menu_func(self, context):
|
|
self.layout.operator(MESH_OT_reverse_polyline_vertices.bl_idname)
|
|
|
|
def register():
|
|
bpy.utils.register_class(MESH_OT_reverse_polyline_vertices)
|
|
bpy.types.VIEW3D_MT_edit_mesh_vertices.append(menu_func)
|
|
|
|
def unregister():
|
|
bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(menu_func)
|
|
bpy.utils.unregister_class(MESH_OT_reverse_polyline_vertices)
|
|
|
|
if __name__ == "__main__":
|
|
register()
|