1
$\begingroup$

For a blender v2.80 plugin I am developing I have to export a file generated from data available in the blender context. When I try to do the file export I obtain this exception:

from_object(...): currently only mesh objects are supported

which is given by the function bmesh.from_object()

I think it's because in the context I have some "illegal" element, but I am not able to understand which one. Can anyone help me?

I also attach the traceback of the error:

**Traceback (most recent call last):**

> File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\bl\menus.py", line 101, in execute
    fds_file = sc.to_fds(context=context, full=True)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2030, in to_fds
    bodies.append(context.scene.collection.to_fds(context))
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2069, in to_fds
    bodies.extend(child.to_fds(context) for child in self.children)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2069, in <genexpr>
    bodies.extend(child.to_fds(context) for child in self.children)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2068, in to_fds
    bodies.extend(ob.to_fds(context) for ob in obs)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2068, in <genexpr>
    bodies.extend(ob.to_fds(context) for ob in obs)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 1956, in to_fds
    return self.bf_namelist.to_fds(context)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\types.py", line 244, in to_fds
    to_fds = p(self.element).to_fds(context)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 1229, in to_fds
    xbs, msg = geometry.to_fds.ob_to_xbs(context, ob, scale_length)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\geometry\to_fds.py", line 136, in ob_to_xbs
    return _choice_to_xbs[ob.bf_xb](context, ob, scale_length)  # recalc
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\geometry\to_fds.py", line 58, in _ob_to_xbs_bbox
    xbs = list((utils.get_bbox_xbs(context, ob, scale_length, world=True),))
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\geometry\utils.py", line 78, in get_bbox_xbs
    bm = get_object_bmesh(context, ob, world=True)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\geometry\utils.py", line 13, in get_object_bmesh
    bpy.ops.object.mode_set(mode="OBJECT")  # actualize
  File "F:\Tools\Blender\2.80\scripts\modules\bpy\ops.py", line 201, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect

> location: F:\Tools\Blender\2.80\scripts\modules\bpy\ops.py:201

> location: F:\Tools\Blender\2.80\scripts\modules\bpy\ops.py:201
Error: Traceback (most recent call last):
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\bl\menus.py", line 101, in execute
    fds_file = sc.to_fds(context=context, full=True)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2030, in to_fds
    bodies.append(context.scene.collection.to_fds(context))
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2069, in to_fds
    bodies.extend(child.to_fds(context) for child in self.children)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2069, in <genexpr>
    bodies.extend(child.to_fds(context) for child in self.children)
  File "C:\Users\Carlo\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\blenderfds28x\lang.py", line 2068, in to_fds
    bodies.extend(ob.to_fds(context) for ob in ... truncated
$\endgroup$
0
$\begingroup$

The "only mesh objects are supported" would indicate that the object you are trying to get mesh data from is not a mesh object.

If you are looping through the selected objects, test that the object is a mesh object before converting.

for obj in bpy.context.selected_objects:
    if obj.type == 'MESH':
        bm.from_object(obj, context.view_layer.depsgraph)

You may also want to consider that bmesh is intended for editing mesh data, you can read the mesh data without converting it to bmesh.

for obj in bpy.context.selected_objects:
    if obj.type == 'MESH':
        for v in obj.data.vertices:
            print(v.co)
        for e in obj.data.edges:
            print(e.index)
        for f in obj.data.polygons:
            print(f.index)
$\endgroup$

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.