Blender Fix Script - Please copy and run after import! | X |
import bpy
import math
import time
curarea = bpy.context.area
curarea.header_text_set("Please wait... This can take forever...")
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
lastime = time.time()
time.sleep(0.1)
cnt = 0
for obj in bpy.data.objects:
cnt = cnt + 1
bpy.ops.object.select_all(action='DESELECT') # deselect all objects
if obj.type=="EMPTY":
if len(obj.children)>0:
if obj.children[0].type=="MESH":
print(obj.children)
for child in obj.children:
child.select_set(True)
with bpy.context.temp_override(active_object=obj.children[0],selected_objects=obj.children):
bpy.ops.object.join()
print("JOINED: " + obj.name)
newtime = time.time()
diftime = ((newtime - lastime) * ((len(bpy.data.objects) + len(bpy.data.materials)) - cnt)) / 60
if diftime / 3600 > 1:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime / 3600)) + " hours... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
elif diftime / 60 > 1:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime / 60)) + " minutes... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
else:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime)) + " seconds... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
time.sleep(0.01)
lastime = time.time()
for mat in bpy.data.materials:
cnt = cnt + 1
obj_set=[]
bpy.ops.object.select_all(action='DESELECT') # deselect all objects
for obj in bpy.data.objects:
if obj.users>0 and obj.parent==None and len(obj.material_slots)==1:
if obj.material_slots[0].name==mat.name:
obj_set.append(obj)
obj.select_set(True)
if len(obj_set)>0:
print(mat.name)
with bpy.context.temp_override(active_object=obj_set[0],selected_objects=obj_set):
bpy.ops.object.join()
print("JOINED: " + mat.name)
newtime = time.time()
diftime = ((newtime - lastime) * ((len(bpy.data.objects) + len(bpy.data.materials)) - cnt)) / 60
if diftime / 3600 > 1:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime / 3600)) + " hours... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
elif diftime / 60 > 1:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime / 60)) + " minutes... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
else:
curarea.header_text_set("Please wait... This can take up to " + str(math.ceil(diftime)) + " seconds... " + str(math.floor( (cnt / (len(bpy.data.objects) + len(bpy.data.materials))) * 100 )) + "%")
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
time.sleep(0.01)
lastime = time.time()
for mat in bpy.data.materials:
if mat.node_tree.nodes.get("Principled BSDF", None) is not None:
mat.node_tree.nodes["Principled BSDF"].inputs["Specular"].default_value = 0
curarea.header_text_set(None)