0
$\begingroup$

Beginner Python scripter here, upon running my operator Blender crashes, inspecting the crashlog just yields an EAV as described. The crash appears to happen at the "facemaps[x-1].add(face)" line. I haven't been able to find much information about the new facemaps so have only been going off what I found on other similar properties.

I cannot use vertex groups as an alternative as during subdivisions they blend out into other vertices which is not ideal for my purposes.

   def execute(self, context):
        obj = bpy.context.edit_object
        me = obj.data
        bmsh = bmesh.from_edit_mesh(me)
        
        verts = []
        facemaps = []
        face = [0]
        
        x = 1
        
        for f in bmsh.faces:
            for v in f.verts:
                verts.append(v.co)
                
            face[0] = f.index
            facemaps.append(obj.face_maps.new( name = str(x)))
            bpy.ops.object.editmode_toggle()
            facemaps[x-1].add(face)
            bpy.ops.object.editmode_toggle()
            x = x + 1
$\endgroup$
1
$\begingroup$

Perhaps the cause of the crash was accessing an invalid reference.

>>> import bmesh
>>> obj = bpy.context.edit_object
>>> me = obj.data
>>> bmsh = bmesh.from_edit_mesh(me)
>>> bmsh.faces
<BMFaceSeq object at 0x000002686604A600>

>>> bpy.ops.object.editmode_toggle()
{'FINISHED'}

>>> bpy.ops.object.editmode_toggle()
{'FINISHED'}

>>> bmsh.faces
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
ReferenceError: BMesh data of type BMesh has been removed

The following script is based on the examples in API documents.

def execute(self, context):
    obj = bpy.context.edit_object
    me = obj.data
    bmsh = bmesh.from_edit_mesh(me)
    fm_lay = bmsh.faces.layers.face_map.active
    
    for f in bmsh.faces:
            
        fm = obj.face_maps.new( name=str(f.inded+1) )
        f[fm_lay] = fm.index
$\endgroup$
2
  • $\begingroup$ After integrating this into the script, it works, but very inconsistently, and I can't figure why. More often it throws AttributeError: BMElem[key]: invalid key, must be a BMLayerItem on the f[fm_lay] = fm.index line. $\endgroup$ Dec 26 '20 at 7:39
  • $\begingroup$ I'm thinking there must be some context stuff going on, I'm in edit mode and need to have some number of faces selected that will be used later in the script. $\endgroup$ Dec 26 '20 at 7:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.