Created
January 6, 2021 08:58
-
-
Save BurntNail/43ac58aa506424de58eb5d1ae7befdd7 to your computer and use it in GitHub Desktop.
Addon of the align object between other 2 objects script. Mapped to Ctrl-Shift-V
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from bpy.utils import register_class, unregister_class | |
class RotateBetweenTwoOperator (bpy.types.Operator): | |
bl_idname = "ops.align_between_two" | |
bl_label = "Align Object between 2 other objects." | |
@classmethod | |
def poll(cls, context): | |
return context.active_object and context.mode is not "EDIT_MESH" | |
def execute(cls, context): | |
if len(bpy.context.selected_objects) != 3: return | |
objTarget = bpy.context.view_layer.objects.active | |
posA, posB = [ob.location for ob in bpy.context.selected_objects if ob != objTarget] | |
midPoint = (posA + posB)/2 | |
objTarget.location = midPoint | |
axis = posA - posB | |
rotation_mode = objTarget.rotation_mode | |
objTarget.rotation_mode = 'QUATERNION' | |
objTarget.rotation_quaternion = axis.to_track_quat('Z','Y') | |
objTarget.rotation_mode = rotation_mode | |
return {'FINISHED'} | |
class RotateTwoPie (bpy.types.Menu): | |
bl_idname = "menu.Rotate_Pie" | |
bl_label = "Rotate Between 2 Pie" | |
def draw (self, ctx): | |
l = self.layout | |
p = l.menu_pie() | |
p.operator(RotateBetweenTwoOperator.bl_idname) | |
bl_info = { | |
"name" : "Align Objects by Axis", | |
"author" : "AIG, Thanks to Sergey Kritisky & Jack Maguire", | |
"blender" : (2, 91, 0), | |
"version" : (1, 0, 0), | |
"location" : "View3D", | |
"category" : "3D View" | |
} | |
def register (): | |
register_class(RotateBetweenTwoOperator) | |
register_class(RotateTwoPie) | |
kc = bpy.context.window_manager.keyconfigs.addon | |
km = kc.keymaps.new(name="3D View", space_type="VIEW_3D") | |
kmi = km.keymap_items.new("wm.call_menu_pie", "V", "PRESS", shift=True, ctrl=True) | |
kmi.properties.name = RotateTwoPie.bl_idname | |
def unregister (): | |
unregister_class(RotateBetweenTwoOperator) | |
unregister_class(RotateTwoPie) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment