Newer
Older
# Align Scale Y
class AlignScaleYOperator(Operator):
bl_idname = "object.align_objects_scale_y"
bl_label = "Align Selected Scale Y To Active"
bl_description = "Align Selected Scale Y To Active"
@classmethod
def poll(cls, context):
def execute(self, context):
ScaleY(context)
return {'FINISHED'}
# Align Scale Z
class AlignScaleZOperator(Operator):
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):
def execute(self, context):
ScaleZ(context)
return {'FINISHED'}
# Interface Panel
class AlignUi(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_label = "Align Tools"
bl_context = "objectmode"
bl_category = 'Tools'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.label(text="Active object is: ", icon='OBJECT_DATA')
box.label(text=obj.name, icon='EDITMODE_HLT')
col = layout.column()
col.label(text="Align Loc + Rot:", icon='MANIPUL')
col = layout.column(align=False)
col = layout.column()
col.label(text="Align Location:", icon='MAN_TRANS')
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:", icon='MAN_ROT')
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:", icon='MAN_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")
layout = self.layout
self.layout.operator("object.align_tools", text="Advanced")
# Add-ons Preferences Update Panel
# Define Panel classes for updating
panels = (
AlignUi,
)
message = "Align Tools: Updating Panel locations has failed"
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))
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(
description="Choose a name for the category of the panel",
default="Tools",
def draw(self, context):
layout = self.layout
row = layout.row()
col = row.column()
AlignUi,
AlignOperator,
AlignLocationOperator,
AlignLocationXOperator,
AlignLocationYOperator,
AlignLocationZOperator,
AlignRotationOperator,
AlignRotationXOperator,
AlignRotationYOperator,
AlignRotationZOperator,
AlignScaleOperator,
AlignScaleXOperator,
AlignScaleYOperator,
AlignScaleZOperator,
# 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)