Offset Edge Script

Hey I am a bit of a blender and python newbie, though I have worked with other 3D modeling packages and I am a fairly competent programmer.

Some explanation first. I was noticing that blender lacks a proper edge offset ability. I know you can use the shrink/fatten command on faces but not on edges. I find it really disrupts workflow if you have to extrude your edges just to create an offset. So I have set off to create a script to do just that.

Okay now to the question, this is going to sound stupid after all that but how do I get a list of selected edges?

I have tried


ob = Object.GetSelected()
selEdges = ob[0].getData(False,True).edges.selected()
print selEdges

but selEdges is empty even though I have several edges selected in the view port something tells me that I am making some stupid mistake but I just can’t see it.

I’ve not done any python with edges, so can’t answer your question…
You may be interested in this script by macouno…

http://www.alienhelpdesk.com/python_scripts/inset

you can try to list the edges for your selected object

like

for e in me.edges:
print e

this will give you the vertices for that edge i think

then you can move the vertex associated with that edge

hope it helps

salutations

Heya!

Cause you cant work on more than 1 object at a time, the following prints a list of indeces of selected edges of the active object even if you have more objects selected:

from Blender import *

def Get_selected_edges():
    sce = Scene.GetCurrent()
    ob = Object.GetSelected()[0]
    me = ob.getData(mesh=1)
    sel_edges = []
    for ed in me.edges:
        if ed.sel:
            sel_edges.append(ed.index)
    return sel_edges

print Get_selected_edges()

Script supposes that the active object is a mesh object… otherwise, an error will be
reported.

Regards,

For some reason your script returns an empty list, despite having several edges selected in the view port.

Could you send a .blend file with a mesh object having edges so selected? I will be able to investigate what may be the problem cause I cant see it right now… :eek:

Regards,

doesn’t work for me either, even on a default cube…
looks like a bug to me.

(using 2.49 self compiled)

Well, it works for me in Blender 2.46 but in the same way in 2.49b.

Here is my testing file that I tried in 2.49b - file.

Here is the testing scene:

http://www.sigmirror.com/files/50232_eelz4/Testing_3.jpg

And here are some results in Blender 2.49b console:

http://www.sigmirror.com/files/50171_mxqlo/Testing_console_3.jpg

The first row is when the plane is selected and you run the script. The second - when the cube with ALL its verts (edges, respectively) are selected. The third is when cube’s face to the right ( the dark one) is entirely selected. And the forth result is when cube’s verts/edges are selected as shown on the pic above.

This leading me to think it WORKS… I have also checked if there are some changes in Blender’s API in regards to edges but it is the same for 2.46 and 2.49b… :eek:

Regards,

Just tried that and it seemed to be working… until I started changing selections in edit mode…
I tried to track it down by switching fromedge mode to vertex mode then it seems I figured it out (maybe)

It only works if you toggle out of edit mode, else it keeps what edges you had selected when you first entered edit mode… (in previous tests, none hence the empty list…)

this works;



from Blender import * 
 
def Get_selected_edges(): 
       
    sce = Scene.GetCurrent() 
    ob = Object.GetSelected()[0] 
    me = ob.getData(mesh=1) 
    Window.EditMode(0) 
    Window.EditMode(1) 
    sel_edges = [] 
    for ed in me.edges: 
        if ed.sel: 
            sel_edges.append(ed.index) 
    return sel_edges 
 
print Get_selected_edges()


ps,what OS?

(I’m on linux 64bit )

…which means that you don’t need the for loop…


print me.edges.selected()

does work!

ugly, but I guess it could be neat if you check for edit mode at the start, toggle to object mode, do all your processing then switch back to edit mode


wasEdit =Window.EditMode()
if wasEdit:
    Window.EditMode(0)

#process here
myFunction()

#restore edit mode to be nice
if wasEdit:
    Window.EditMode(1)







You’re right - script works for the last selected edges + its update… Naturally, it happens when you turn to Object mode. But my point was to provide ONE possible and relatively effective solution for what was asked, not to clear out all possible effects of the user interaction within Blender during the process.

Regards,

I think I found a bug in edges.selected() it assumes that if two adjacent vertices are selected then the line between them is selected as well however this is not true for many selection cases. Do you have any Idea how to deal with this?