Is there a low level alternative for bpy.ops.object.convert()?

by Ed Tate   Last Updated April 16, 2018 11:15 AM - source

I am using bpy.ops.object.convert(target='MESH', keep_original= False) in a python function in blender to convert metaballs to a mesh. The script works fine when run from the text editor. However, the goal is to add the function to the render events via and

When the function using bpy.ops.object.convert is used in the handler, a polling error occurs. The typical recommendation is to either use overrides or low-level functions to eliminate the polling/context error. I would like to use the low-level functions.

A code snippet in the Blender 2.75a low-level API for bpy.ops.object.convert(target='MESH', keep_original= False), where the selected object is a meatball, would be appreciated.

Answers 3

The to_mesh method

import bpy

context = bpy.context
scene = context.scene

mball ="Mball")

if mball:
    me = mball.to_mesh(scene, False, 'PREVIEW')

    # add an object
    o ="MBallMesh", me)
    o.matrix_world = mball.matrix_world

    # not keep original
October 12, 2015 03:21 AM

I had the similar problem. And to_mesh did not help me, it still didn't work. I imported some curves and then tried to convert them to mesh and exception related to incorrect context occurred. After short investigation I discover that correct context for convert function means existence not-None active_object and not-None selected_object in bpy.context. So the following code should work for conversion from/to mesh:

obj = D.objects[0] # the sample = obj = True
bpy.ops.object.convert.poll() # should return True now
December 21, 2016 22:37 PM

I wanted to add that if you create the metaballs programmatically as in

metaball ='MetaBall')
obj ='MetaBallObject', metaball)

element = = (0, 0, 0)
element.radius = 1.0

you need to add bpy.context.scene.update() after you created the metaballs. Then you can

mesh = obj.to_mesh(bpy.context.scene, False, 'PREVIEW')
new_obj ='MetaBallMeshObject', mesh)

otherwise you won't have any geometry.

Nikolai Janakiev
Nikolai Janakiev
April 16, 2018 11:01 AM

Related Questions

How to create a claw out of this mesh?

Updated September 15, 2017 23:15 PM

How can I add a description to an object

Updated October 07, 2018 19:15 PM

Baking metaball solver

Updated April 07, 2015 18:06 PM