Hi, I’ve been working on a script where the following function may be run in or out of edit mode, but I’m finding that when I change the mesh geometry in edit mode the list returned by this function does not update unless I toggle into object mode first.
def findVerts(ob):
"Return a list of xyz coordinates for each vertex"
list = []
for v in ob.data.vertices:
list.append([v.co[0],v.co[1],v.co[2]])
return list
Does anyone know a way to fix this, besides having the script toggle in and out of object mode automatically? Thanks.
The problems here is if you’re in object mode it’s unnecessary and if for some reason your in a mode other than edit or object mode you’ll end up in object mode… but at least it always works (I think).
Is there a way to get the current mode? (Sorry dumb question but can’t find it)
currentMode = bpy.context.object.mode
bpy.ops.object.mode_set() #default is mode='OBJECT'
bpy.ops.object.mode_set(mode=currentMode)
I might be wrong, but it seemed more efficient just to always switch to object mode then to use two if statements (let me know if I’m wrong). Actually I don’t know why I’m worrying about efficiency at all.
Also, in this case the mesh data doesn’t need to be retrieved in object mode. It does needs to be updated by going to object mode apparently. (I would like to just have an update command, which is why I started the thread).
With and if statement (maybe):
m=bpy.context.mode
if bpy.context.mode!='OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode=m)