3
$\begingroup$

I would like to iterate through all objects in my scene and change their type to Mesh using script. It works, however after every iteration blender sorts all objects on the map (I've got over 130 000 objects). It is realy slowing down the process.

Is there a way to disable it through some function or just modify convert function in Blender source code? (I've tried to look for it but I failed, do someone knows where is it exactly?)

Or maybe there is another way to convert curves to meshes or optimize it?

Thanks in advance for any help. Cheers

My convert function:

def to_mesh(obj):
    obj.select = True
    bpy.context.scene.objects.active = obj
    bpy.ops.object.convert(target = 'MESH')
    obj.select = False

enter image description here

Console output. I think that the process is so slow because convert sorts all objects after operation (ordered on the top), or am I wrong?

$\endgroup$

1 Answer 1

4
$\begingroup$

Run the operator once for all curves

I imagine you are getting poor performance because you are running the operator for each curve object, rather than once for all. See Python performance with Blender operators

Suggest selecting all the curves in scene, and running the operator once, example test code.

import bpy

context = bpy.context

# select only curves
for o in context.scene.objects:
    o.select = o.type == 'CURVE'

curves = context.selected_objects
if curves:
    # just in case context object not a curve
    if not context.object.select:
        context.scene.objects.active = curves[0]
    # convert them all
    bpy.ops.object.convert(target='MESH')

As for the sorting, that's just what blender does in its background processing, and is I doubt responsible for slowing down your blender.

There is also the Object.to_mesh which can be used to convert the curve to mesh without using the operator. However in this case I think selecting all curves and converting with one operator call is sufficient.

$\endgroup$
2
  • $\begingroup$ Thank you so much. That's what I needed. But maybe you can help me with another problem? What if I want to do the same with converting this meshes physics type to 'NAVMESH'? I looked for answer in your link, theres much help about operations but nothing about physics type. Cheers, and again, thanks for help. $\endgroup$ Commented Apr 30, 2018 at 18:23
  • $\begingroup$ Related After the convert operator all new meshes will be context.selected_objects either loop thru and set ob.game.physics_type = 'NAVMESH' or if you want a single mesh, join them bpy.ops.object.join() then context.object.game.physics_type = 'NAVMESH' $\endgroup$
    – batFINGER
    Commented May 1, 2018 at 6:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .