0
$\begingroup$

i have some code, which moves vertices in a mesh:

#not working!
#translate the sign pole to ensure it is behind sign
transAmt = kvMaxY - spMinY
print (transAmt)
for v in signPoleVerts:
    loc = v.co + mathutils.Vector((0, transAmt, 0))
    v.co = loc

in its current state it doesnt seem to work - the position of the vertices in signPoleVerts does not change.

when i add a bmesh, it works, even when i do nothing with it:

dummy_bmesh = bmesh.new()
dummy_bmesh.from_mesh(sign.data)
dummy_bmesh.to_mesh(sign.data)

#now works
#translate the sign pole to ensure it is behind sign
transAmt = kvMaxY - spMinY
print (transAmt)
for v in signPoleVerts:
    loc = v.co + mathutils.Vector((0, transAmt, 0))
    v.co = loc

what is happening here? I would prefer not to create the bmesh for no reason...

EDIT here is the code directly before the above - it defines kvMaxY, spMinY and signPoleVerts

#get the key vertices which will ensure pole does not poke through sign, and find max y
keyVerts = getVertsInGroup(sign, sign.vertex_groups["poleConnectionVerts"])
kvMaxY = -math.inf
print("keyverts:")
for v in keyVerts:
    print(v.co.y)
    if v.co.y > kvMaxY:
        kvMaxY = v.co.y 

#get the sign pole vertices, and find min y
signPoleVerts = getVertsInGroup(sign, sign.vertex_groups["signPole"])
spMinY = math.inf
print ("signPoleVerts:")
for v in signPoleVerts:
    print (v.co.y)
    if v.co.y < spMinY:
        spMinY = v.co.y

getVertsInGroup is a function defined as below:

def getVertsInGroup (obj, vertexGroup):
vertexGroupId = vertexGroup.index
return [vert for vert in obj.data.vertices if  vertexGroupId in [vg.group for vg in vert.groups]]
$\endgroup$
4
  • $\begingroup$ Please expand on the code above, in particular how you assign signPoleVerts $\endgroup$ – batFINGER Sep 28 '17 at 12:27
  • $\begingroup$ have added some more of the code :) $\endgroup$ – Matt Creighton Sep 28 '17 at 12:58
  • $\begingroup$ Suggest going one way or 'tother. Either use mesh.vertices and no bmesh, or bm.verts The bmesh bm_dummy is a snapshot of the mesh from when you from meshed it. If you want to use a live edit (mode) mesh bm = bmesh.from_edit_mesh(mesh) $\endgroup$ – batFINGER Sep 28 '17 at 13:06
  • $\begingroup$ @batFINGER Hello, just to follow up, I did a bit more research on bmesh and performed the whole of my script on a bmesh rather than using bpy.ops, and that has fixed the problem. never got to the root cause of this bit of behaviour though! thanks for your help. $\endgroup$ – Matt Creighton Oct 3 '17 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.