I just want to write a python script to select edges which are marked seams using a python code instead of Shift+G, that is my request, I have to merge this code with a bigger one so Shift+G won't work for me.
Asked
Active
Viewed 705 times
3 Answers
3
Think this should do the trick.
import bpy
import bmesh
obj = bpy.context.active_object
bm = bmesh.from_edit_mesh(obj.data)
for e in bm.edges[:]:
if e.seam:
e.select_set(True)
bmesh.update_edit_mesh(obj.data)
Jakemoyo
- 4,375
- 10
- 20
2
This will work in Object Mode:
import bpy
from bpy import context as C
for e in C.object.data.edges:
e.select = e.use_seam
Or a faster way if you have a lot of geometry:
import bpy, numpy as np
from bpy import context as C
me = C.object.data
array = np.zeros(len(me.polygons), dtype=bool)
me.polygons.foreach_set('select', array)
array = np.zeros(len(me.vertices), dtype=bool)
me.vertices.foreach_set('select', array)
array = np.zeros(len(me.edges), dtype=bool)
me.edges.foreach_get('use_seam', array)
me.edges.foreach_set('select', array)
Markus von Broady
- 36,563
- 3
- 30
- 99
-
Your code is really great and I am glad to see a new approach, But I have to give the answer of Jakemoyo as it's more closer to my need. Thank you tho, – NamanDeep Jun 04 '22 at 03:57
-
@NamanDeep Sure, if you're in Edit Mode, Jakemoyo's answer is the answer. – Markus von Broady Jun 04 '22 at 08:38
1
import bpy
obj = bpy.context.active_object # make obj active object in your scene
if obj.type == 'MESH': # check if active object is a mesh (logical)
# in order to select edges, you need to make sure that
# previously you deselected everything in the Edit Mode
# and set the select_mode to 'EDGE'
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_mode(type = 'EDGE')
bpy.ops.mesh.select_all(action = 'DESELECT')
# we need to return back to the OBJECT mode,
# otherwise, the result won't be seen,
# see https://blender.stackexchange.com/questions/43127 for info
bpy.ops.object.mode_set(mode = 'OBJECT')
# now we check all the edges
for edge in obj.data.edges:
if edge.use_seam: # if the edge uses seam
edge.select = True # select it
# as we did all selection in the OBJECT mode,
# now we set to EDIT to see results
bpy.ops.object.mode_set(mode = 'EDIT')
else:
print("Object is not a mesh") # print if active object is not a mesh
kemplerart
- 610
- 1
- 10
[:]there to make a list copy, as you're not modifying the collection (as in the order or length doesn't change). – Markus von Broady Jun 03 '22 at 20:47