Page MenuHome

Add "Snap Selection to Active" option in snap menu
ClosedPublic

Authored by Isaac Weaver (wisaac) on May 3 2016, 4:34 AM.

Details

Summary

This patch adds an option to the snap menu to snap the selected items to the location of the active item.
I would've added an offset option (like with the snap selected to cursor operator) but I couldn't figure out how to not offset the active element (I'm pretty new to Blender development and c/c++ coding). If someone could tell me how to accomplish this, that would be great!

Diff Detail

Repository
rB Blender

Event Timeline

Isaac Weaver (wisaac) retitled this revision from to Add "Snap Selection to Active" option in snap menu.
Isaac Weaver (wisaac) updated this object.
Isaac Weaver (wisaac) set the repository for this revision to rB Blender.

hi, very welcome addition imo. I know this is not place for feature requests, however if your working in this menu area, "snap selected to center" seems missing here.

The reason I implemented Snap Selection to Active is because I found myself frequently doing Snap Cursor to Selection then selecting a bunch of other stuff and doing Snap Selection to Cursor. I don't think snapping stuff to the center is really that common (most of the time Alt-G will suffice). That said, if it would be helpful, then I'd be more than happy to implement it :)

@Isaac Weaver (wisaac) yes Alt/g does the object, but not the cursor, making it 2 moves to "clear object location & snap cursor to selected" There's times where this is very handy, similar to your addition, I find doing the 2 moves happens regularly with snapping both the cursor & selected object needed in object creation & modeling.
Thanks.

@Brendon Murphy (meta-androcto) You're saying it would snap the objects and the cursor to the center? I can see how that could be useful, but it seems like a bit of a corner case. Either way I would like to get some more input form people before implementing it, maybe you could open a feature requrest on rightclickselect.com?

@Isaac Weaver (wisaac), hi, yes, it's "You're saying it would snap the objects and the cursor to the center".
Place the cursor anywhere in the screen, shift/a a new object & it's created at the cursor location, which may or may not be the desired outcome.
Append an object from another file & it's created at the original location which may or may not be the desired outcome.
Having a way to reset the object & cursor at 0,0,0 in one move seems time saving in these & possibly more cases.
I'm not fussed with this enough to do a entry on rightclickselect.com, If you think it's good, go for it, if not, stick to your original patch, I can always add to the spacebar menu addon as there's already extended snapping methods available there.
Cheers :)

@Brendon Murphy (meta-androcto) I'm probably not going to implement it the C code, but I did write a simple python script that should work just as well:

import bpy


class SnapCursSelToCenter(bpy.types.Operator):
    """Snap 3D cursor and selected objects to the center"""
    bl_idname = "view3d.snap_cursor_selected_to_center"
    bl_label = "Snap Cursor & Selection to Center"

    @classmethod
    def poll(cls, context):
        # Only works on objects
        return (context.mode == "OBJECT")

    def execute(self, context):
        context.space_data.cursor_location = (0, 0, 0)
        for obj in context.selected_objects:
            obj.location = (0, 0, 0)
        return {'FINISHED'}


# Add the operator to the snap menu
def draw(self, context):
    self.layout.operator(SnapCursSelToCenter.bl_idname, text="Snap Cursor & Selection to Center")


def register():
    bpy.utils.register_module(__name__)
    bpy.types.VIEW3D_MT_snap.append(draw)


def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.VIEW3D_MT_snap.remove(draw)


if __name__ == "__main__":
    register()

This will add an option to the bottom of the snap menu called "Snap Cursor & Selection to Center" which will move the selected objects and the cursor to 0, 0, 0

Hope this helps!

Campbell Barton (campbellbarton) requested changes to this revision.Jul 14 2016, 3:43 PM
Campbell Barton (campbellbarton) edited edge metadata.

This option could be useful however it adds quite a bit of code, which is logically a duplicate of code we have already.

Best that we make the "Snap to Cursor" function more generic so it takes a position argument,
Then it can be called by this operator, and the snap to active operator - so we can avoid a lot of duplicate code,

This revision now requires changes to proceed.Jul 14 2016, 3:43 PM
This revision is now accepted and ready to land.Jul 15 2016, 9:09 AM

Committed rB91556cb973ef8bfc0f159d0113a37918d4b868d3d with de-duplicated logic.