Works great when I manually click on each plane I need flattened, but as there are 123 planes which need to be flattened, I’d really like to figure out how to do this with a for loop.
I won’t write out all my failed code as It might prossibly span pages, but here’s the most recent code attempt which doesn’t work:
import bpy
for obj in bpy.data.objects:
obj.select = True
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.looptools_flatten(influence=100, plane='normal', restriction='none')
bpy.ops.object.editmode_toggle()
obj.select = False
Can someone tell me why this doesn’t work and what the correct way to go about doing this is? Thanks.
Try this.
I added in some test code. hope this helps.
# If there ARE objects selected then act on all objects
if bpy.context.selected_objects != []:
for obj in bpy.context.selected_objects:
print(obj.name, obj, obj.type)
if obj.type == 'MESH':
print(">>>>", obj.name)
# If there are NO objects selected then act on all objects
if bpy.context.selected_objects == []:
print('selected:')
for obj in bpy.context.scene.objects:
print(obj.name, obj, obj.type)
if obj.type == 'MESH':
print(">>>>", obj.name)