Skip to content
Snippets Groups Projects
Commit e347b967 authored by lijenstina's avatar lijenstina
Browse files

Align Tools: Update panel Rename

Bumped version to 0.3.2
Pep8 Cleanup
Remove unused imports
As a part of the task T50726:
Update the Panel rename code to more generic one
Use tuple imports for bpy.types
Consistent prop definitions
Fix typo using o.type instead of obj.type
Update wiki link
Add missing bl_description to operators
Small UI changes
No other functional changes
parent 246de4dc
No related branches found
No related tags found
No related merge requests found
......@@ -21,82 +21,108 @@
bl_info = {
"name": "Align Tools",
"author": "gabhead, Lell, Anfeo",
"version": (0, 3, 1),
"version": (0, 3, 2),
"blender": (2, 77, 0),
"location": "View3D > Tool Shelf > Tools",
"description": "Align Selected Objects to Active Object",
"warning": "",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/3D interaction/Align_Tools",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "3D View",
}
import bpy
from bpy.props import EnumProperty, PointerProperty, FloatProperty, BoolProperty, FloatVectorProperty
from mathutils import Vector, Matrix
from math import *
## Simple Align Defs ##
## Align all
from bpy.types import (
Operator,
Panel,
AddonPreferences,
)
from bpy.props import (
EnumProperty,
BoolProperty,
FloatVectorProperty,
StringProperty,
)
from mathutils import (
Vector,
Matrix,
)
# Simple Align Defs #
# Align all
def main(context):
for i in bpy.context.selected_objects:
i.location = bpy.context.active_object.location
i.rotation_euler = bpy.context.active_object.rotation_euler
## Align Location
# Align Location
def LocAll(context):
for i in bpy.context.selected_objects:
i.location = bpy.context.active_object.location
def LocX(context):
for i in bpy.context.selected_objects:
i.location.x = bpy.context.active_object.location.x
def LocY(context):
for i in bpy.context.selected_objects:
i.location.y = bpy.context.active_object.location.y
def LocZ(context):
for i in bpy.context.selected_objects:
i.location.z = bpy.context.active_object.location.z
## Align Rotation
# Align Rotation
def RotAll(context):
for i in bpy.context.selected_objects:
i.rotation_euler = bpy.context.active_object.rotation_euler
def RotX(context):
for i in bpy.context.selected_objects:
i.rotation_euler.x = bpy.context.active_object.rotation_euler.x
def RotY(context):
for i in bpy.context.selected_objects:
i.rotation_euler.y = bpy.context.active_object.rotation_euler.y
def RotZ(context):
for i in bpy.context.selected_objects:
i.rotation_euler.z = bpy.context.active_object.rotation_euler.z
## Align Scale
# Align Scale
def ScaleAll(context):
for i in bpy.context.selected_objects:
i.scale = bpy.context.active_object.scale
def ScaleX(context):
for i in bpy.context.selected_objects:
i.scale.x = bpy.context.active_object.scale.x
def ScaleY(context):
for i in bpy.context.selected_objects:
i.scale.y = bpy.context.active_object.scale.y
def ScaleZ(context):
for i in bpy.context.selected_objects:
i.scale.z = bpy.context.active_object.scale.z
## Advanced Align Defs ##
# Advanced Align Defs #
# subject to object 0, 1 and 2 to pivot for cursor
def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y, loc_z, ref1, ref2, loc_offset,
......@@ -142,12 +168,12 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
for p in me.vertices:
co_list.append(p.co)
elif o.type == 'SURFACE' and len(me.splines) > 0:
elif obj.type == 'SURFACE' and len(me.splines) > 0:
ok = True
for s in me.splines:
for p in s.points:
co_list.append(p.co)
elif o.type == 'FONT' and len(o.data.splines) > 0:
elif obj.type == 'FONT' and len(obj.data.splines) > 0:
ok = True
for s in me.splines:
for p in s.bezier_points:
......@@ -164,20 +190,25 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
min_z = co_list[0][2]
for v in co_list:
# the strings of the list compared with the smaller and more found
# in order to find the minor and major for each axis
act_x = v[0]
if act_x > max_x: max_x = act_x
if act_x < min_x: min_x = act_x
if act_x > max_x:
max_x = act_x
if act_x < min_x:
min_x = act_x
act_y = v[1]
if act_y > max_y: max_y = act_y
if act_y < min_y: min_y = act_y
if act_y > max_y:
max_y = act_y
if act_y < min_y:
min_y = act_y
act_z = v[2]
if act_z > max_z: max_z = act_z
if act_z < min_z: min_z = act_z
if act_z > max_z:
max_z = act_z
if act_z < min_z:
min_z = act_z
else:
# otherwise use the pivot object
......@@ -221,7 +252,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
if ref_max[2] > sel_max[2]:
sel_max[2] = ref_max[2]
return sel_min, sel_max;
return sel_min, sel_max
def find_ref2_co(act_obj):
# It contains the coordinates of the reference point for the positioning
......@@ -249,7 +280,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
ref_points = get_reference_points(obj, "global")
if loc_x == True:
if loc_x is True:
if ref1 == "0":
min_x = ref_points[0]
new_x = ref2_co[0] + (obj.location[0] - min_x) + loc_offset[0]
......@@ -262,7 +293,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
max_x = ref_points[2]
new_x = ref2_co[0] - (max_x - obj.location[0]) + loc_offset[0]
obj.location[0] = new_x
if loc_y == True:
if loc_y is True:
if ref1 == "0":
min_y = ref_points[3]
new_y = ref2_co[1] + (obj.location[1] - min_y) + loc_offset[1]
......@@ -275,7 +306,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
max_y = ref_points[5]
new_y = ref2_co[1] - (max_y - obj.location[1]) + loc_offset[1]
obj.location[1] = new_y
if loc_z == True:
if loc_z is True:
if ref1 == "0":
min_z = ref_points[6]
new_z = ref2_co[2] + (obj.location[2] - min_z) + loc_offset[2]
......@@ -290,19 +321,19 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
obj.location[2] = new_z
def find_new_rotation(obj):
if rot_x == True:
if rot_x is True:
obj.rotation_euler[0] = act_obj.rotation_euler[0] + rot_offset[0]
if rot_y == True:
if rot_y is True:
obj.rotation_euler[1] = act_obj.rotation_euler[1] + rot_offset[1]
if rot_z == True:
if rot_z is True:
obj.rotation_euler[2] = act_obj.rotation_euler[2] + rot_offset[2]
def find_new_scale(obj):
if scale_x == True:
if scale_x is True:
obj.scale[0] = act_obj.scale[0] + scale_offset[0]
if scale_y == True:
if scale_y is True:
obj.scale[1] = act_obj.scale[1] + scale_offset[1]
if scale_z == True:
if scale_z is True:
obj.scale[2] = act_obj.scale[2] + scale_offset[2]
def find_new_dimensions(obj, ref_dim):
......@@ -317,7 +348,6 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
dim = ref_points[8] - ref_points[6]
obj.scale[2] = (ref_dim[2] / dim) * act_obj.scale[2]
def move_pivot(obj):
me = obj.data
vec_ref2_co = Vector(ref2_co)
......@@ -373,16 +403,16 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
ref_co = obj_mtx * ref_co
ok = True
break
#se nessun oggetto aveva dati, uso la posizione di un oggetto che non fosse quello attivo
# come punto interno della selezione
if ok == False:
# if no object had data, use the position of an object that was not active as an internal
# point of selection
if ok is False:
ref_co = ref_ob.location
return ref_co
if subject == "0":
# if act_obj.type == ('MESH' or 'FONT' or 'CURVE' or 'SURFACE'):
if act_obj.type == 'MESH' or act_obj.type == 'FONT' or act_obj.type == 'SURFACE': #or act_obj.type == 'CURVE'
if act_obj.type == 'MESH' or act_obj.type == 'FONT' or act_obj.type == 'SURFACE':
ref2_co = find_ref2_co(act_obj)
else:
if ref2 == "4":
......@@ -440,7 +470,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
# print("ehy", ref2_co)
find_new_coord(obj)
if active_too == True:
if active_too is True:
if loc_x or loc_y or loc_z:
find_new_coord(act_obj)
if rot_x or rot_y or rot_z:
......@@ -460,7 +490,7 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
if obj != act_obj and obj.type == 'MESH':
move_pivot(obj)
if active_too == True:
if active_too is True:
if act_obj.type == 'MESH':
if loc_x or loc_y or loc_z:
if self_or_active == "0":
......@@ -469,37 +499,42 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
elif subject == "2":
if self_or_active == "1":
if act_obj.type == 'MESH' or act_obj.type == 'FONT' or act_obj.type == 'SURFACE': #or act_obj.type == 'CURVE'
if act_obj.type == 'MESH' or act_obj.type == 'FONT' or act_obj.type == 'SURFACE':
ref2_co = find_ref2_co(act_obj)
ref_points = get_reference_points(act_obj, "global")
else:
ref2_co = act_obj.location
ref_points = [act_obj.location[0], act_obj.location[0], act_obj.location[0], act_obj.location[1], act_obj.location[1], act_obj.location[1], act_obj.location[2], act_obj.location[2], act_obj.location[2]]
ref_points = [act_obj.location[0], act_obj.location[0], act_obj.location[0],
act_obj.location[1], act_obj.location[1], act_obj.location[1],
act_obj.location[2], act_obj.location[2], act_obj.location[2]]
if ref2 == "0":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = ref_points[0] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = ref_points[3] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = ref_points[6] + loc_offset[2]
elif ref2 == "1":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = ref_points[1] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = ref_points[4] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = ref_points[7] + loc_offset[2]
elif ref2 == "2":
if loc_x == True: bpy.context.scene.cursor_location[0] = act_obj.location[0] + loc_offset[0]
if loc_y == True: bpy.context.scene.cursor_location[1] = act_obj.location[1] + loc_offset[1]
if loc_z == True: bpy.context.scene.cursor_location[2] = act_obj.location[2] + loc_offset[2]
if loc_x is True:
bpy.context.scene.cursor_location[0] = act_obj.location[0] + loc_offset[0]
if loc_y is True:
bpy.context.scene.cursor_location[1] = act_obj.location[1] + loc_offset[1]
if loc_z is True:
bpy.context.scene.cursor_location[2] = act_obj.location[2] + loc_offset[2]
elif ref2 == "3":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = ref_points[2] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = ref_points[5] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = ref_points[8] + loc_offset[2]
elif self_or_active == "2":
ref_co = point_in_selection(act_obj, sel_obj)
......@@ -508,99 +543,194 @@ def align_function(subject, active_too, consistent, self_or_active, loc_x, loc_y
sel_center = sel_min + ((sel_max - sel_min) / 2)
if ref2 == "0":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = sel_min[0] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = sel_min[1] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = sel_min[2] + loc_offset[2]
elif ref2 == "1":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = sel_center[0] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = sel_center[1] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = sel_center[2] + loc_offset[2]
elif ref2 == "3":
if loc_x == True:
if loc_x is True:
bpy.context.scene.cursor_location[0] = sel_max[0] + loc_offset[0]
if loc_y == True:
if loc_y is True:
bpy.context.scene.cursor_location[1] = sel_max[1] + loc_offset[1]
if loc_z == True:
if loc_z is True:
bpy.context.scene.cursor_location[2] = sel_max[2] + loc_offset[2]
## Classes ##
## Advanced Align
class OBJECT_OT_align_tools(bpy.types.Operator):
"""Align Object"""
# Classes #
# Advanced Align
class OBJECT_OT_align_tools(Operator):
bl_idname = "object.align_tools"
bl_label = "Align Operator"
bl_description = "Align Object Tools"
bl_options = {'REGISTER', 'UNDO'}
#property definition
# property definitions
# Object-Pivot-Cursor:
subject = EnumProperty (items=(("0", "Object", "Align Objects"), ("1", "Pivot", "Align Objects Pivot"), ("2", "Cursor", "Align Cursor To Active")),
name = "Align To", description = "What will be moved")
subject = EnumProperty(
items=(("0", "Object", "Align Objects"),
("1", "Pivot", "Align Objects Pivot"),
("2", "Cursor", "Align Cursor To Active")),
name="Align To",
description="What will be moved"
)
# Move active Too:
active_too = BoolProperty (name = "Active too", default= False, description= "Move the active object too")
active_too = BoolProperty(
name="Active too",
default=False,
description="Move the active object too"
)
# advanced options
advanced = BoolProperty (name = "Advanced Options", default = False, description = "Show advanced options")
consistent = BoolProperty (name = "Consistent Selection", default = False, description = "Use consistent selection")
advanced = BoolProperty(
name="Advanced Options",
default=False,
description="Show advanced options"
)
consistent = BoolProperty(
name="Consistent Selection",
default=False,
description="Use consistent selection"
)
# Align Location:
loc_x = BoolProperty (name = "Align to X axis", default= False, description= "Enable X axis alignment")
loc_y = BoolProperty (name = "Align to Y axis", default= False, description= "Enable Y axis alignment")
loc_z = BoolProperty (name = "Align to Z axis", default= False, description= "Enable Z axis alignment")
loc_x = BoolProperty(
name="Align to X axis",
default=False,
description="Enable X axis alignment"
)
loc_y = BoolProperty(
name="Align to Y axis",
default=False,
description="Enable Y axis alignment"
)
loc_z = BoolProperty(
name="Align to Z axis",
default=False,
description="Enable Z axis alignment"
)
# Selection Option:
ref1 = EnumProperty (items=(("3", "Max", "Align the maximum point"), ("1", "Center", "Align the center point"), ("2", "Pivot", "Align the pivot"),
ref1 = EnumProperty(
items=(("3", "Max", "Align the maximum point"),
("1", "Center", "Align the center point"),
("2", "Pivot", "Align the pivot"),
("0", "Min", "Align the minimum point")),
name = "Selection reference", description = "Moved objects reference point")
name="Selection reference",
description="Moved objects reference point"
)
# Active Oject Option:
ref2 = EnumProperty (items=(("3", "Max", "Align to the maximum point"), ("1", "Center", "Align to the center point"), ("2", "Pivot", "Align to the pivot"),
("0", "Min", "Align to the minimum point"), ("4", "Cursor", "Description")),
name = "Active reference", description = "Destination point")
self_or_active = EnumProperty (items = (("0", "Self", "In relation of itself"), ("1", "Active", "In relation of the active object"), ("2", "Selection", "In relation of the entire selection")),
name = "Relation", default = "1", description = "To what the pivot will be aligned")
ref2 = EnumProperty(
items=(("3", "Max", "Align to the maximum point"),
("1", "Center", "Align to the center point"),
("2", "Pivot", "Align to the pivot"),
("0", "Min", "Align to the minimum point"),
("4", "Cursor", "Description")),
name="Active reference",
description="Destination point"
)
self_or_active = EnumProperty(
items=(("0", "Self", "In relation of itself"),
("1", "Active", "In relation of the active object"),
("2", "Selection", "In relation of the entire selection")),
name="Relation",
default="1",
description="To what the pivot will be aligned"
)
# Location Offset
loc_offset = FloatVectorProperty(name="Location Offset", description="Offset for location align position", default=(0.0, 0.0, 0.0),
subtype='XYZ', size=3)
loc_offset = FloatVectorProperty(
name="Location Offset",
description="Offset for location align position",
default=(0.0, 0.0, 0.0),
subtype='XYZ', size=3
)
# Rotation Offset
rot_offset = FloatVectorProperty(name="Rotation Offset", description="Offset for rotation alignment", default=(0.0, 0.0, 0.0),
subtype='EULER', size=3)
rot_offset = FloatVectorProperty(
name="Rotation Offset",
description="Offset for rotation alignment",
default=(0.0, 0.0, 0.0),
subtype='EULER', size=3
)
# Scale Offset
scale_offset = FloatVectorProperty(name="Scale Offset", description="Offset for scale match", default=(0.0, 0.0, 0.0),
subtype='XYZ', size=3)
scale_offset = FloatVectorProperty(
name="Scale Offset",
description="Offset for scale match",
default=(0.0, 0.0, 0.0),
subtype='XYZ', size=3
)
# Fit Dimension Prop:
fit_x = BoolProperty (name = "Fit Dimension to X axis", default= False, description= "")
fit_y = BoolProperty (name = "Fit Dimension to Y axis", default= False, description= "")
fit_z = BoolProperty (name = "Fit Dimension to Z axis", default= False, description= "")
fit_x = BoolProperty(
name="Fit Dimension to X axis",
default=False,
description=""
)
fit_y = BoolProperty(
name="Fit Dimension to Y axis",
default=False,
description=""
)
fit_z = BoolProperty(
name="Fit Dimension to Z axis",
default=False,
description=""
)
# Apply Fit Dimension:
apply_dim = BoolProperty (name = "Apply Dimension", default= False, description= "")
apply_dim = BoolProperty(
name="Apply Dimension",
default=False,
description=""
)
# Align Rot Prop:
rot_x = BoolProperty (name = "Align Rotation to X axis", default= False, description= "")
rot_y = BoolProperty (name = "Align Rotation to Y axis", default= False, description= "")
rot_z = BoolProperty (name = "Align Rotation to Z axis", default= False, description= "")
rot_x = BoolProperty(
name="Align Rotation to X axis",
default=False,
description=""
)
rot_y = BoolProperty(
name="Align Rotation to Y axis",
default=False,
description=""
)
rot_z = BoolProperty(
name="Align Rotation to Z axis",
default=False,
description=""
)
# Apply Rot:
apply_rot = BoolProperty (name = "Apply Rotation", default= False, description= "")
apply_rot = BoolProperty(
name="Apply Rotation",
default=False,
description=""
)
# Align Scale:
scale_x = BoolProperty (name = "Match Scale to X axis", default= False, description= "")
scale_y = BoolProperty (name = "Match Scale to Y axis", default= False, description= "")
scale_z = BoolProperty (name = "match Scale to Z axis", default= False, description= "")
scale_x = BoolProperty(
name="Match Scale to X axis",
default=False,
description=""
)
scale_y = BoolProperty(
name="Match Scale to Y axis",
default=False,
description=""
)
scale_z = BoolProperty(
name="match Scale to Z axis",
default=False,
description=""
)
# Apply Scale:
apply_scale = BoolProperty (name = "Apply Scale", default= False, description= "")
apply_scale = BoolProperty(
name="Apply Scale",
default=False,
description=""
)
def draw(self, context):
layout = self.layout
......@@ -622,19 +752,19 @@ class OBJECT_OT_align_tools(bpy.types.Operator):
# Align Location:
row3 = layout.row()
row3.prop(self, "loc_x", text="X")
row3.prop(self, "loc_y", text="Y")
row3.prop(self, "loc_z", text="Z")
row3.prop(self, "loc_x", text="X", toggle=True)
row3.prop(self, "loc_y", text="Y", toggle=True)
row3.prop(self, "loc_z", text="Z", toggle=True)
# Offset:
if self.advanced == True:
if self.advanced is True:
# row8 = col.row()
# row8.label(text='Location Offset')
row9 = layout.row()
row9.prop(self, 'loc_offset', text='')
# Selection Options
if self.advanced == True:
if self.advanced is True:
sel = bpy.context.selected_objects
sel_obs = len(sel)
if sel_obs != 0:
......@@ -650,7 +780,7 @@ class OBJECT_OT_align_tools(bpy.types.Operator):
# Active Object Options: Number of select objects
act = bpy.context.active_object
if self.advanced == True:
if self.advanced is True:
if act:
row6 = layout.row()
row6.label(text="Active: " + act.name, icon='OBJECT_DATA')
......@@ -661,229 +791,246 @@ class OBJECT_OT_align_tools(bpy.types.Operator):
row12 = layout.row()
row12.label(icon='MAN_ROT', text='Align Rotation:')
row13 = layout.row(align=True)
row13.prop (self, 'rot_x', text='X')
row13.prop (self, 'rot_y', text='Y')
row13.prop (self, 'rot_z', text='Z')
row13.prop (self, 'apply_rot', text='Apply')
if self.advanced == True:
row13.prop(self, 'rot_x', text='X', toggle=True)
row13.prop(self, 'rot_y', text='Y', toggle=True)
row13.prop(self, 'rot_z', text='Z', toggle=True)
row13.prop(self, 'apply_rot', text='Apply', toggle=True)
if self.advanced is True:
row13b = layout.row()
row13b.prop(self, 'rot_offset', text='')
row14 = layout.row()
row14.label(icon='MAN_SCALE', text='Match Scale:')
row15 = layout.row(align=True)
row15.prop (self, 'scale_x', text='X')
row15.prop (self, 'scale_y', text='Y')
row15.prop (self, 'scale_z', text='Z')
row15.prop (self, 'apply_scale', text='Apply')
if self.advanced == True:
row15.prop(self, 'scale_x', text='X', toggle=True)
row15.prop(self, 'scale_y', text='Y', toggle=True)
row15.prop(self, 'scale_z', text='Z', toggle=True)
row15.prop(self, 'apply_scale', text='Apply', toggle=True)
if self.advanced is True:
row15b = layout.row()
row15b.prop(self, 'scale_offset', text='')
row10 = layout.row()
row10.label(icon='MAN_SCALE', text='Fit Dimensions:')
row11 = layout.row(align=True)
row11.prop (self, 'fit_x', text='X')
row11.prop (self, 'fit_y', text='Y')
row11.prop (self, 'fit_z', text='Z')
row11.prop (self, 'apply_dim', text='Apply')
row11.prop(self, 'fit_x', text='X', toggle=True)
row11.prop(self, 'fit_y', text='Y', toggle=True)
row11.prop(self, 'fit_z', text='Z', toggle=True)
row11.prop(self, 'apply_dim', text='Apply', toggle=True)
def execute(self, context):
align_function(self.subject, self.active_too, self.consistent, self.self_or_active, self.loc_x, self.loc_y, self.loc_z,
align_function(
self.subject, self.active_too, self.consistent,
self.self_or_active, self.loc_x, self.loc_y, self.loc_z,
self.ref1, self.ref2, self.loc_offset,
self.rot_x, self.rot_y, self.rot_z, self.rot_offset,
self.scale_x, self.scale_y, self.scale_z, self.scale_offset, self.fit_x, self.fit_y, self.fit_z)
self.scale_x, self.scale_y, self.scale_z, self.scale_offset,
self.fit_x, self.fit_y, self.fit_z
)
return {'FINISHED'}
## Simple Align Classes ##
## Align All Rotation And Location
class AlignOperator(bpy.types.Operator):
""""""
# Simple Align Classes #
# Align All Rotation And Location
class AlignOperator(Operator):
bl_idname = "object.align"
bl_label = "Align Selected To Active"
bl_description = "Align Selected To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
## Align Location All
class AlignLocationOperator(bpy.types.Operator):
""""""
# Align Location All
class AlignLocationOperator(Operator):
bl_idname = "object.align_location_all"
bl_label = "Align Selected Location To Active"
bl_description = "Align Selected Location To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
LocAll(context)
return {'FINISHED'}
## Align Location X
class AlignLocationXOperator(bpy.types.Operator):
""""""
# Align Location X
class AlignLocationXOperator(Operator):
bl_idname = "object.align_location_x"
bl_label = "Align Selected Location X To Active"
bl_description = "Align Selected Location X To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
LocX(context)
return {'FINISHED'}
## Align Location Y
class AlignLocationYOperator(bpy.types.Operator):
""""""
# Align Location Y
class AlignLocationYOperator(Operator):
bl_idname = "object.align_location_y"
bl_label = "Align Selected Location Y To Active"
bl_description = "Align Selected Location Y To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
LocY(context)
return {'FINISHED'}
## Align LocationZ
class AlignLocationZOperator(bpy.types.Operator):
""""""
# Align LocationZ
class AlignLocationZOperator(Operator):
bl_idname = "object.align_location_z"
bl_label = "Align Selected Location Z To Active"
bl_description = "Align Selected Location Z To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
LocZ(context)
return {'FINISHED'}
## Align Rotation All
class AlignRotationOperator(bpy.types.Operator):
""""""
# Align Rotation All
class AlignRotationOperator(Operator):
bl_idname = "object.align_rotation_all"
bl_label = "Align Selected Rotation To Active"
bl_description = "Align Selected Rotation To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
RotAll(context)
return {'FINISHED'}
## Align Rotation X
class AlignRotationXOperator(bpy.types.Operator):
""""""
# Align Rotation X
class AlignRotationXOperator(Operator):
bl_idname = "object.align_rotation_x"
bl_label = "Align Selected Rotation X To Active"
bl_description = "Align Selected Rotation X To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
RotX(context)
return {'FINISHED'}
## Align Rotation Y
class AlignRotationYOperator(bpy.types.Operator):
""""""
# Align Rotation Y
class AlignRotationYOperator(Operator):
bl_idname = "object.align_rotation_y"
bl_label = "Align Selected Rotation Y To Active"
bl_description = "Align Selected Rotation Y To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
RotY(context)
return {'FINISHED'}
## Align Rotation Z
class AlignRotationZOperator(bpy.types.Operator):
""""""
# Align Rotation Z
class AlignRotationZOperator(Operator):
bl_idname = "object.align_rotation_z"
bl_label = "Align Selected Rotation Z To Active"
bl_description = "Align Selected Rotation Z To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
RotZ(context)
return {'FINISHED'}
## Scale All
class AlignScaleOperator(bpy.types.Operator):
""""""
# Scale All
class AlignScaleOperator(Operator):
bl_idname = "object.align_objects_scale_all"
bl_label = "Align Selected Scale To Active"
bl_description = "Align Selected Scale To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
ScaleAll(context)
return {'FINISHED'}
## Align Scale X
class AlignScaleXOperator(bpy.types.Operator):
""""""
# Align Scale X
class AlignScaleXOperator(Operator):
bl_idname = "object.align_objects_scale_x"
bl_label = "Align Selected Scale X To Active"
bl_description = "Align Selected Scale X To Active"
@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
ScaleX(context)
return {'FINISHED'}
## Align Scale Y
class AlignScaleYOperator(bpy.types.Operator):
""""""
# 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):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
ScaleY(context)
return {'FINISHED'}
## Align Scale Z
class AlignScaleZOperator(bpy.types.Operator):
""""""
# 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):
return context.active_object != None
return context.active_object is not None
def execute(self, context):
ScaleZ(context)
return {'FINISHED'}
## Interface Panel ##
class AlignUi(bpy.types.Panel):
# Interface Panel
class AlignUi(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_label = "Align Tools"
......@@ -895,25 +1042,22 @@ class AlignUi(bpy.types.Panel):
layout = self.layout
obj = context.object
if obj != None:
if obj is not None:
row = layout.row()
row.label(text="Active object is: ", icon='OBJECT_DATA')
row = layout.row()
row.label(obj.name, icon='EDITMODE_HLT')
layout.separator()
box = layout.box()
box.label(obj.name, icon='EDITMODE_HLT')
col = layout.column()
col.label(text="Align Loc + Rot:", icon='MANIPUL')
col = layout.column(align=False)
col.operator("object.align", text="XYZ")
col = layout.column()
col.label(text="Align Location:", icon='MAN_TRANS')
col = layout.column_flow(columns=5,align=True)
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")
......@@ -922,7 +1066,7 @@ class AlignUi(bpy.types.Panel):
col = layout.column()
col.label(text="Align Rotation:", icon='MAN_ROT')
col = layout.column_flow(columns=5,align=True)
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")
......@@ -931,48 +1075,66 @@ class AlignUi(bpy.types.Panel):
col = layout.column()
col.label(text="Align Scale:", icon='MAN_SCALE')
col = layout.column_flow(columns=5,align=True)
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 != None:
if obj is not None:
col = layout.column()
col.label(text="Advanced Align")
layout = self.layout
self.layout.operator("object.align_tools", text="Advanced")
## Addons Preferences Update Panel
# Add-ons Preferences Update Panel
# Define Panel classes for updating
panels = (
AlignUi,
)
def update_panel(self, context):
message = "Align Tools: Updating Panel locations has failed"
try:
bpy.utils.unregister_class(AlignUi)
except:
for panel in panels:
if "bl_rna" in panel.__dict__:
bpy.utils.unregister_class(panel)
for panel in panels:
panel.bl_category = context.user_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
AlignUi.bl_category = context.user_preferences.addons[__name__].preferences.category
bpy.utils.register_class(AlignUi)
class AlignAddonPreferences(bpy.types.AddonPreferences):
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 = bpy.props.StringProperty(
name="Category",
category = StringProperty(
name="Tab Category",
description="Choose a name for the category of the panel",
default="Tools",
update=update_panel)
update=update_panel
)
def draw(self, context):
layout = self.layout
row = layout.row()
col = row.column()
col.label(text="Category:")
col.label(text="Tab Category:")
col.prop(self, "category", text="")
# Class List
classes = [
classes = (
AlignUi,
AlignOperator,
AlignLocationOperator,
......@@ -988,17 +1150,20 @@ classes = [
AlignScaleYOperator,
AlignScaleZOperator,
OBJECT_OT_align_tools,
AlignAddonPreferences
]
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment