Page MenuHome

AdvancedModifierTools.py

Authored By
Ali (aliarash)
Jul 8 2021, 9:27 PM
Size
6 KB
Subscribers
None

AdvancedModifierTools.py

bl_info = {
"name": "AdvancedModifierTools",
"blender": (2,92,0),
"version": (1,0),
"category":"Interface",
"description": "Advanced Tools for work better with modifiers",
}
import bpy
class ModifiersBase:
@classmethod
def poll(cls, context):
ob = context.object
return ob and ob.modifiers
class ApplyAll_OT_ModB(bpy.types.Operator):
bl_idname = "applyallmodifiers.func_2"
bl_label = "ApplyAllModifiers"
def execute(self,context):
CollectonAvaible = False
for cl in bpy.data.collections:
print(cl.name)
if cl.name == "BackupCollection":
CollectonAvaible = True
break
if CollectonAvaible == False:
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.collection.create(name="BackupCollection")
BackupCollection = bpy.data.collections['BackupCollection']
C = bpy.context
C.scene.collection.children.link(BackupCollection)
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
src_obj = bpy.context.active_object
new_obj = src_obj.copy()
new_obj.data = src_obj.data.copy()
new_obj.animation_data_clear()
bpy.data.collections['BackupCollection'].objects.link(new_obj)
for ob in bpy.data.collections['BackupCollection'].objects:
ob.hide_viewport = True
print(ob)
try:
if len(bpy.context.object.modifiers.items())>0:
itemEN = ""
for item in bpy.context.object.modifiers.items():
print("type: ",type(item[0]),"name: ",item[0])
itemEN = item[0]
bpy.ops.object.modifier_apply(modifier=item[0])
ShowMessageBox("applied.")
else:
ShowMessageBox("No modifier available.")
except RuntimeError as ex:
ShowMessageBox(itemEN +" modifier settings are not complete.", "Error", 'ERROR')
print(itemEN)
objects = bpy.context.scene.objects
return {'FINISHED'}
class RemoveAll_OT_ModB(bpy.types.Operator):
bl_idname = "removeallmodifiers.func_2"
bl_label = "RemoveAllModifiers"
def execute(self,context):
bpy.ops.object.mode_set(mode = 'OBJECT')
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
try:
if len(bpy.context.object.modifiers.items())>0:
itemEN = ""
for item in bpy.context.object.modifiers.items():
print("type: ",type(item[0]),"name: ",item[0])
itemEN = item[0]
bpy.ops.object.modifier_remove(modifier=item[0])
ShowMessageBox("Removed.")
else:
ShowMessageBox("No modifier available.")
except RuntimeError as ex:
ShowMessageBox(itemEN +" modifier settings are not complete.", "Error", 'ERROR')
print(itemEN)
return {'FINISHED'}
class LayoutPanel(ModifiersBase,bpy.types.Panel):
bl_label = "Apply Modifiers"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "modifier"
def draw(self, context):
layout = self.layout
row = layout.row()
layout.label(text="Choose your modifier to apply")
layout.prop(context.scene, "M_prop",icon="MODIFIER",text="Modifiers")
row.scale_y = 1.5
row.operator(ApplyAll_OT_ModB.bl_idname,icon="IMPORT")
row.operator(RemoveAll_OT_ModB.bl_idname,icon="TRASH")
def update_cb(self, context):
CollectonAvaible = False
for cl in bpy.data.collections:
print(cl.name)
if cl.name == "BackupCollection":
CollectonAvaible = True
break
if CollectonAvaible == False:
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.collection.create(name="BackupCollection")
BackupCollection = bpy.data.collections['BackupCollection']
C = bpy.context
C.scene.collection.children.link(BackupCollection)
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
src_obj = bpy.context.active_object
new_obj = src_obj.copy()
new_obj.data = src_obj.data.copy()
new_obj.animation_data_clear()
bpy.data.collections['BackupCollection'].objects.link(new_obj)
for ob in bpy.data.collections['BackupCollection'].objects:
ob.hide_viewport = True
print(ob)
try:
bpy.ops.object.modifier_apply(modifier=self.M_prop)
ShowMessageBox("applied.")
print(self.M_prop)
except:
ShowMessageBox(self.M_prop +" modifier settings are not complete.", "Error", 'ERROR')
objects = bpy.context.scene.objects
def items_cb(self, context):
l = []
Ml = [item[0] for item in bpy.context.object.modifiers.items()]
l = [(str(x),x,x) for i,x in enumerate(Ml)]
#print(itemsL)
return l
def register():
bpy.utils.register_class(LayoutPanel)
bpy.utils.register_class(ApplyAll_OT_ModB)
bpy.utils.register_class(RemoveAll_OT_ModB)
bpy.types.Scene.M_prop = bpy.props.EnumProperty(items=items_cb, update=update_cb)
def unregister():
bpy.utils.unregister_class(LayoutPanel)
bpy.utils.unregister_class(ApplyAll_OT_ModB)
bpy.utils.unregister_class(RemoveAll_OT_ModB)
if __name__ == "__main__":
register()

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
50/86/d699873563d601b2e0fe68dbc76c

Event Timeline