From 0ecc6cbd1528cb72fca8a486eb9119373af636f1 Mon Sep 17 00:00:00 2001 From: kiminseob Date: Tue, 15 Oct 2024 17:44:22 +0900 Subject: [PATCH] Fix for blender 4.2 version --- blenderSimplify.py | 14 +++++++------- blenderSimplifyNumFaces.py | 14 +++++++------- blenderSimplifyV2.py | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/blenderSimplify.py b/blenderSimplify.py index b86e7a6..fb69bf7 100644 --- a/blenderSimplify.py +++ b/blenderSimplify.py @@ -52,7 +52,7 @@ def get_args(): bpy.ops.object.select_all(action='DESELECT') # selection -bpy.data.objects['Camera'].select = True +bpy.data.objects['Camera'].select_set(True) # remove it bpy.ops.object.delete() @@ -61,15 +61,15 @@ def get_args(): # select objects by type for o in bpy.data.objects: if o.type == 'MESH': - o.select = True + o.select_set(True) else: - o.select = False + o.select_set(False) # call the operator once bpy.ops.object.delete() print('\n Beginning the process of Decimation using Blender Python API ...') -bpy.ops.import_scene.obj(filepath=input_model) +bpy.ops.wm.obj_import(filepath=input_model) print('\n Obj file imported successfully ...') modifierName='DecimateMod' @@ -83,14 +83,14 @@ def get_args(): print("{} meshes".format(len(meshes))) for i, obj in enumerate(meshes): - bpy.context.scene.objects.active = obj + bpy.context.view_layer.objects.active = obj print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name)) print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) modifier = obj.modifiers.new(modifierName,'DECIMATE') modifier.ratio = decimateRatio modifier.use_collapse_triangulate = True - bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName) + bpy.ops.object.modifier_apply(modifier=modifierName) print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) -bpy.ops.export_scene.obj(filepath=output_model) +bpy.ops.wm.obj_export(filepath=output_model) print('\n Process of Decimation Finished ...') diff --git a/blenderSimplifyNumFaces.py b/blenderSimplifyNumFaces.py index 519d38b..23636e1 100644 --- a/blenderSimplifyNumFaces.py +++ b/blenderSimplifyNumFaces.py @@ -54,7 +54,7 @@ def get_args(): bpy.ops.object.select_all(action='DESELECT') # selection -bpy.data.objects['Camera'].select = True +bpy.data.objects['Camera'].select_set(True) # remove it bpy.ops.object.delete() @@ -63,15 +63,15 @@ def get_args(): # select objects by type for o in bpy.data.objects: if o.type == 'MESH': - o.select = True + o.select_set(True) else: - o.select = False + o.select_set(False) # call the operator once bpy.ops.object.delete() print('\nImporting the input 3D model, please wait.......') -bpy.ops.import_scene.obj(filepath=input_model) +bpy.ops.wm.obj_import(filepath=input_model) print('\nObj file imported successfully ...') @@ -123,16 +123,16 @@ def get_args(): print("{} meshes".format(len(meshes))) for i, obj in enumerate(meshes): - bpy.context.scene.objects.active = obj + bpy.context.view_layer.objects.active = obj print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name)) print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) modifier = obj.modifiers.new(modifierName,'DECIMATE') modifier.ratio = decimateRatio modifier.use_collapse_triangulate = True - bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName) + bpy.ops.object.modifier_apply(modifier=modifierName) print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) -bpy.ops.export_scene.obj(filepath=str(nameOfFolder) + "/" + output_model) +bpy.ops.wm.obj_export(filepath=str(nameOfFolder) + "/" + output_model) print('\nProcess of Decimation Finished ...') print('\nOutput Mesh is stored in corresponding folder ...') diff --git a/blenderSimplifyV2.py b/blenderSimplifyV2.py index 9a0dd03..ba8332e 100644 --- a/blenderSimplifyV2.py +++ b/blenderSimplifyV2.py @@ -55,7 +55,7 @@ def get_args(): bpy.ops.object.select_all(action='DESELECT') # selection -bpy.data.objects['Camera'].select = True +bpy.data.objects['Camera'].select_set(True) # remove it bpy.ops.object.delete() @@ -64,15 +64,15 @@ def get_args(): # select objects by type for o in bpy.data.objects: if o.type == 'MESH': - o.select = True + o.select_set(True) else: - o.select = False + o.select_set(False) # call the operator once bpy.ops.object.delete() print('\nImporting the input 3D model, please wait.......') -bpy.ops.import_scene.obj(filepath=input_model) +bpy.ops.wm.obj_import(filepath=input_model) print('\nObj file imported successfully ...') #Creating a folder named as the Number of faces: named '150000' @@ -96,16 +96,16 @@ def get_args(): print("{} meshes".format(len(meshes))) for i, obj in enumerate(meshes): - bpy.context.scene.objects.active = obj + bpy.context.view_layer.objects.active = obj print("{}/{} meshes, name: {}".format(i, len(meshes), obj.name)) print("{} has {} verts, {} edges, {} polys".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) modifier = obj.modifiers.new(modifierName,'DECIMATE') modifier.ratio = decimateRatio modifier.use_collapse_triangulate = True - bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modifierName) + bpy.ops.object.modifier_apply(modifier=modifierName) print("{} has {} verts, {} edges, {} polys after decimation".format(obj.name, len(obj.data.vertices), len(obj.data.edges), len(obj.data.polygons))) -bpy.ops.export_scene.obj(filepath=str(nameOfFolder) + "%/" + output_model) +bpy.ops.wm.obj_export(filepath=str(nameOfFolder) + "%/" + output_model) print('\nProcess of Decimation Finished ...') print('\nOutput Mesh is stored in corresponding folder ...')