Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align 2d Cursor #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 66 additions & 7 deletions op_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
class op(bpy.types.Operator):
bl_idname = "uv.textools_align"
bl_label = "Align"
bl_description = "Align vertices, edges or shells"
bl_description = "Align vertices, edges or shells.\nHold Alt to align the cursor.\nHold Ctrl to force Selection Mode.\nHold Shift to force Canvas mode"
bl_options = {'REGISTER', 'UNDO'}

direction : bpy.props.StringProperty(name="Direction", default="top")
direction: bpy.props.StringProperty(name="Direction", default="top")
align_mode: bpy.props.StringProperty(name="Align Mode", default="SELECTION")
align_cursor: bpy.props.BoolProperty(name="Align Cursor", default=False)


@classmethod
def poll(cls, context):
Expand All @@ -28,26 +31,82 @@ def poll(cls, context):
return False
return True

def invoke(self, context, event):

self.align_mode = bpy.context.scene.texToolsSettings.align_mode

self.align_cursor = event.alt

if event.shift:
self.align_mode = 'CANVAS'
elif event.ctrl:
self.align_mode = 'SELECTION'

self.execute(context)
return {'FINISHED'}


def execute(self, context):
align_mode = bpy.context.scene.texToolsSettings.align_mode

if align_mode == 'SELECTION':
if self.align_mode == 'SELECTION':
all_ob_bounds = utilities_uv.multi_object_loop(utilities_uv.getSelectionBBox, need_results=True)
if not any(all_ob_bounds):
return {'CANCELLED'}

boundsAll = utilities_uv.get_BBOX_multi(all_ob_bounds)

utilities_uv.multi_object_loop(align, context, align_mode, self.direction, boundsAll=boundsAll)

if self.align_cursor:
align_cursor(context, self.align_mode, self.direction, boundsAll)
else:
utilities_uv.multi_object_loop(align, context, self.align_mode, self.direction, boundsAll=boundsAll)
else:
udim_tile, column, row = utilities_uv.get_UDIM_tile_coords(bpy.context.active_object)
utilities_uv.multi_object_loop(align, context, align_mode, self.direction, column=column, row=row)

if self.align_cursor:
align_cursor(context, self.align_mode, self.direction, column=column, row=row)
else:
utilities_uv.multi_object_loop(align, context, self.align_mode, self.direction, column=column, row=row)

return {'FINISHED'}


def align_cursor(context, align_mode, direction, boundsAll=None, column=0, row=0):

if not boundsAll:
boundsAll = {}
boundsAll["min"] = Vector((column, row))
boundsAll["max"] = Vector((column + 1, row + 1))
boundsAll["center"] = Vector((column + 0.5, row + 0.5))

if direction == "bottom":
context.space_data.cursor_location[1] = boundsAll['min'].y
elif direction == "top":
context.space_data.cursor_location[1] = boundsAll['max'].y
elif direction == "left":
context.space_data.cursor_location[0] = boundsAll['min'].x
elif direction == "right":
context.space_data.cursor_location[0] = boundsAll['max'].x
elif direction == "center":
context.space_data.cursor_location = boundsAll['center']
elif direction == "horizontal":
context.space_data.cursor_location[1] = boundsAll['center'].y
elif direction == "vertical":
context.space_data.cursor_location[0] = boundsAll['center'].x
elif direction == "bottomleft":
context.space_data.cursor_location[1] = boundsAll['min'].y
context.space_data.cursor_location[0] = boundsAll['min'].x
elif direction == "topright":
context.space_data.cursor_location[1] = boundsAll['max'].y
context.space_data.cursor_location[0] = boundsAll['max'].x
elif direction == "topleft":
context.space_data.cursor_location[1] = boundsAll['max'].y
context.space_data.cursor_location[0] = boundsAll['min'].x
elif direction == "bottomright":
context.space_data.cursor_location[1] = boundsAll['min'].y
context.space_data.cursor_location[0] = boundsAll['max'].x
else:
print("Unknown direction: "+str(direction))


def align(context, align_mode, direction, boundsAll={}, column=0, row=0):
prepivot = bpy.context.space_data.pivot_point
Expand Down