5
$\begingroup$

I'm new to Blender and I'm having a few issues attempting to run a 'limited dissolve' over thousands of objects. Is there a simple way of doing this?

What I've tried so far is:

  • Select all objects/faces in the "object mode" and then in the edit mode run the limited dissolved feature. However for some reason 'limited dissolved' seems to only work on single faces/object.

  • Python script looping through all objects and selecting the objects individually to do a 'limited dissolve' on each one. However when I run the script the dissolve_limited method doesn't seem to work - see code below:

    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.data.objects['Shape_IndexedFaceSet.'+str(HundsCol)+str(TensCol)+str(CountTens)].select = True
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.dissolve_limited()   
    bpy.ops.mesh.dissolve_limited(angle_limit=1.75)
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.data.objects['Shape_IndexedFaceSet.'str(HundsCol)+str(TensCol)+str(CountTens)].select = False
    
$\endgroup$
0

1 Answer 1

6
$\begingroup$

To change the context object (for operators) use

context.scene.objects.active = obj

or new in 2.8, instead use

context.view_layer.objects.active = obj
# and select with 
obj.select_set(state=True)

as well as (or instead of) setting the select property.

In your code above you would be running the op on context object for each object.

For multiple objects consider using the bmesh module as shown in this Related Answer, replace the remove doubles bmesh operator with limited dissolve.

Test code, runs the limited dissolve on every selected mesh object.

import bpy
import bmesh
from math import radians

context = bpy.context

distance = 0.0 # remove doubles tolerance.
if True: #def execute(self, context):

    meshes = set(o.data for o in context.selected_objects
                      if o.type == 'MESH')

    bm = bmesh.new()

    for m in meshes:
        bm.from_mesh(m)
        bmesh.ops.dissolve_limit(bm, angle_limit=radians(1.7), verts=bm.verts, edges=bm.edges)
        bm.to_mesh(m)
        m.update()
        bm.clear()

    bm.free()

On a side note, suggest using string formatting to make key names.

key = "Shape_IndexedFaceSet.%d_%d" % (hundreds, tens)
obj = scene.objects.get(key) # obj is None if not exist.

or with f-strings

key = f"Shape_IndexedFaceSet.{hundreds}_{tens}"
$\endgroup$

You must log in to answer this question.

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