Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -----------------------------------------
- # Here is a simple Python script for Blender (in Edit Mode) to write the
- # verts on the shortest path between two (pre-selected) points to a file.
- # (Change 'filename' and 'measurement' before running. The script
- # appends new lines onto the file each time.)
- # -----------------------------------------
- import os, bpy, bmesh
- # Ensure all folders of the path exist
- path = "P:/"
- os.makedirs(path, exist_ok=True)
- filename = "measurement.txt"
- measurement = "Label for measurement path"
- oa = bpy.context.active_object
- obj = bpy.context.object
- bpy.ops.mesh.shortest_path_select() #add for request
- me = obj.data
- bm = bmesh.from_edit_mesh(me)
- v1,v2 = [elem for elem in bm.select_history if isinstance(elem, bmesh.types.BMVert)]
- list = [v1]
- verts = len([v.index for v in bm.verts if v.select])
- cont=0
- while cont< verts:
- v=list[cont]
- edges = v.link_edges
- for e in edges:
- if e.select:
- vn = e.other_vert(v)
- if vn not in list:
- list.append(vn)
- cont+=1
- ii = 0
- outpath = ''
- for v in list:
- if ii > 0:
- outpath = outpath + ','
- outpath = outpath + str(v.index)
- ii = ii + 1
- with open(path + filename, "a+") as vertfile:
- vertfile.write(measurement+' ['+outpath+']\n')
- bmesh.update_edit_mesh(me, True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement