Newer
Older
# Align Scale Z
class OBJECT_OT_AlignScaleZOperator(Operator):
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
bl_idname = "object.align_objects_scale_z"
bl_label = "Align Selected Scale Z To Active"
bl_description = "Align Selected Scale Z To Active"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
ScaleZ(context)
return {'FINISHED'}
# Interface Panel
class VIEW3D_PT_AlignUi(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Align Tools"
bl_context = "objectmode"
bl_category = 'Item'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
obj = context.object
if obj is not None:
row = layout.row()
row.label(text="Active object is: ", icon='OBJECT_DATA')
box = layout.box()
box.label(text=obj.name, icon='EDITMODE_HLT')
col = layout.column()
col.label(text="Align Loc + Rot:")
col = layout.column(align=False)
col.operator("object.align", text="XYZ")
col = layout.column()
col.label(text="Align Location:")
col = layout.column_flow(columns=4, align=True)
col.operator("object.align_location_x", text="X")
col.operator("object.align_location_y", text="Y")
col.operator("object.align_location_z", text="Z")
col.operator("object.align_location_all", text="All")
col = layout.column()
col.label(text="Align Rotation:")
col = layout.column_flow(columns=4, align=True)
col.operator("object.align_rotation_x", text="X")
col.operator("object.align_rotation_y", text="Y")
col.operator("object.align_rotation_z", text="Z")
col.operator("object.align_rotation_all", text="All")
col = layout.column()
col.label(text="Align Scale:")
col = layout.column_flow(columns=4, align=True)
col.operator("object.align_objects_scale_x", text="X")
col.operator("object.align_objects_scale_y", text="Y")
col.operator("object.align_objects_scale_z", text="Z")
col.operator("object.align_objects_scale_all", text="All")
if obj is not None:
col = layout.column()
col.label(text="Advanced Align Operations")
layout = self.layout
self.layout.operator("object.align_tools", text="Advanced")
# Add-ons Preferences Update Panel
# Define Panel classes for updating
panels = (
VIEW3D_PT_AlignUi,
)
def update_panel(self, context):
message = "Align Tools: Updating Panel locations has failed"
try:
for panel in panels:
if "bl_rna" in panel.__dict__:
bpy.utils.unregister_class(panel)
for panel in panels:
panel.bl_category = context.preferences.addons[__name__].preferences.category
bpy.utils.register_class(panel)
except Exception as e:
print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
pass
class AlignAddonPreferences(AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__
category: StringProperty(
name="Tab Category",
description="Choose a name for the category of the panel",
default="Item",
update=update_panel
)
def draw(self, context):
layout = self.layout
row = layout.row()
col = row.column()
col.label(text="Tab Category:")
col.prop(self, "category", text="")
# Class List
classes = (
VIEW3D_PT_AlignUi,
OBJECT_OT_AlignOperator,
OBJECT_OT_AlignLocationOperator,
OBJECT_OT_AlignLocationXOperator,
OBJECT_OT_AlignLocationYOperator,
OBJECT_OT_AlignLocationZOperator,
OBJECT_OT_AlignRotationOperator,
OBJECT_OT_AlignRotationXOperator,
OBJECT_OT_AlignRotationYOperator,
OBJECT_OT_AlignRotationZOperator,
OBJECT_OT_AlignScaleOperator,
OBJECT_OT_AlignScaleXOperator,
OBJECT_OT_AlignScaleYOperator,
OBJECT_OT_AlignScaleZOperator,
OBJECT_OT_align_tools,
AlignAddonPreferences,
)
# Register all operators and panels
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()