# How to scale unconnected edges using individual origins in python?

I want to scale each selected edge individually along it. To do it I first duplicate each selected edge and then try to scale it using bmesh.ops.scale. Unfortunately it scales using origin/median pivot point. How to do it in python so that edges are scaled using individual origins? How can I use different pivot types from python?

Here is my script:

import bpy
import bmesh

def getDupliEdges(edges):
dupEdges = []
for e in edges:
retOneEdge = bmesh.ops.duplicate(
bm,
geom=[e])

dupGeom = retOneEdge["geom"]
dupEdge = [ ele for ele in dupGeom if isinstance(ele, bmesh.types.BMEdge)]
dupEdges.append(dupEdge[0])
return dupEdges

def scaleEdges(dupEdges,factor):
for e in dupEdges:
verts = e.verts
bmesh.ops.scale(
bm,
vec = factor,
verts = verts)

obj = bpy.context.edit_object
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)
bm.faces.active = None

edges = [e for e in bm.edges if e.select == True]

view3dList = [ele for ele in bpy.context.screen.areas if isinstance(ele.spaces[0],bpy.types.SpaceView3D)]
view3d = view3dList[0]
view3d.spaces[0].pivot_point='INDIVIDUAL_ORIGINS'

dupEdges = getDupliEdges(edges)

scaleEdges(dupEdges, [2.0, 2.0, 2.0])

bmesh.update_edit_mesh(mesh, True)


Here is an image to illustrate the question. On the left - initial selection - 3 edges; In the middle - effect of my script; On the right - how I would like it to work.

Thanks for any tips on that :)

• clone the selected edges, separate them from each other, then scale the clones using the individual origins. – zeffii Feb 3 '15 at 8:53

You might do something like:

import bpy
import bmesh

obj = bpy.context.edit_object
bm = bmesh.from_edit_mesh(obj.data)

# current selection
edges = [e for e in bm.edges if e.select]

for e in edges:
v1 = e.verts[0].co
v2 = e.verts[1].co
origin = (v1+v2) * 0.5  # edge origin
bmv1 = bm.verts.new(((v1-origin) * 2) + origin)
bmv2 = bm.verts.new(((v2-origin) * 2) + origin)
bme = bm.edges.new([bmv1, bmv2])

bmesh.update_edit_mesh(obj.data, True)


I may be mistaken but I don't think at present the pivot point has any influence on bmesh.ops. So a slight modification of your original code gives a matrix to each new edge to scale: https://gist.github.com/zeffii/71862f5b1cad1bf1d2c1

• Cool It works:) Thanks a lot for this answer Zeffi. It answers my main question. However I am still a bit puzzled why setting up the pivot did not work in my script. If I wanted to scale these edges along 3DCursor pivot (or others) I still do not know how to do it from python. If you can explain why this line: view3d.spaces[0].pivot_point='INDIVIDUAL_ORIGINS' does not work with bmesh.ops.scale I would really appreciate it. I simply want to uderstand Blender python :) Thanks a lot! – komi3D Feb 3 '15 at 20:14
• @komi3D since it works, could you please mark the answer as accepted (by clicking the check mark). – stacker Feb 4 '15 at 7:59
• @komi3D your script does separate the edges and makes them individual, (tested by commenting out scaleEdges function) in theory that should work, I guess this hasn't been much help then :) – zeffii Feb 4 '15 at 9:28
• @komi3D i'll have a look later, it should be easy – zeffii Feb 4 '15 at 9:30