6
$\begingroup$

I'm trying to move away from Autodesk Max, but I work with a lot of 2d plans, and one thing that I do very very often is to move an object ( or vertices of one object ) a distance x, taking as reference two vertices of another object ( or different objects ).

I know that I can do this in Blender using the 3d cursor, but there's three steps involved, and as I said I do this a few hundred times per day. Is there any way ( even if it's an addon ) to do it faster, without middle steps, like in this animation ( from 3dsmax ):

external snapping

$\endgroup$
2
  • $\begingroup$ Have a look at CAD transform, and see if you get on with it. Personally, I think it looks very promising, but could do with a bit more feedback in use, to be really polished. I agree, Blender's Snap could be slicker and quicker. $\endgroup$ Nov 2 '20 at 11:00
  • 1
    $\begingroup$ I was checking this video ( youtu.be/TWEoZghkalc ) and it seems that CAD Transform addon is exactly what I was looking for. I'll give it a try and see if it suits my work pipeline. $\endgroup$
    – Fabman
    Nov 2 '20 at 11:51
9
$\begingroup$

A basic script for doing nearly the same (in object mode):

enter image description here

It is visually different as the object will move at first step then at the second one.

But the result is as expected, I think.

Use D key to use it. You can use Blender snapping options (i.e. snap to vertex) or not.

The principle is to use grab operator with invoke default from a modal operator:

import bpy
from mathutils import Vector

class GrabOffset(bpy.types.Operator):
    """Move an object by an offset"""
    bl_idname = "object.grab_offset"
    bl_label = "Grab with offset"

    def modal(self, context, event):

        #Left click
        if event.type in {'LEFTMOUSE'}:
            #Second left click?
            if self.second_locations:
                #Calculate delta and move objects
                for obj, floc, sloc in zip(context.selected_objects, self.first_locations, self.second_locations):
                    obj.location = floc + obj.location - sloc
                return {'FINISHED'}
            #First left click
            else:
                #Keep locations
                self.second_locations = [Vector(o.location) for o in context.selected_objects]
                bpy.ops.transform.translate('INVOKE_DEFAULT')

        #Aborting
        if event.type in {'RIGHTMOUSE', 'ESC'}:
            context.object.location = self.first_location
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        if context.selected_objects:
            #Keep original locations
            self.first_locations = [Vector(o.location) for o in context.selected_objects]
            self.second_locations = None

            context.window_manager.modal_handler_add(self)
            
            #Invoke grab
            bpy.ops.transform.translate('INVOKE_DEFAULT')
            
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}

keymaps = []

def register():
    bpy.utils.register_class(GrabOffset)
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(GrabOffset.bl_idname, 'D', 'PRESS', shift=False)
        keymaps.append((km, kmi))

def unregister():
    for km, kmi in keymaps:
        km.keymap_items.remove(kmi)
    keymaps.clear()
    bpy.utils.unregister_class(GrabOffset)

if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.modal_operator('INVOKE_DEFAULT')

$\endgroup$
2
  • 1
    $\begingroup$ Wow! Was this oven-ready? $\endgroup$ Nov 2 '20 at 14:28
  • 2
    $\begingroup$ @RobinBetts, yes it is in the cook book. $\endgroup$
    – lemon
    Nov 2 '20 at 14:41
6
$\begingroup$

In Blender the 'Snap With' > Center refers to the transform center in play at the time the snap is invoked. If Transform Pivot Point is set to '3D Cursor', then, with Snap set to With: 'Center' and To: 'Vertex', for an Object Mode snap, the steps are:

  • Place the cursor at the source reference point. This could be done with ShiftS to the appropriate selected vertex in Edit mode, or, in Object mode, dragging and snapping the cursor itself, using the Cursor tool. If the Cursor tool's default shortcut: ShiftSpacebarSpacebar, is too awkward for frequent use, you can change it, and/or add it to your Quick Menu.
  • Drag the object, hovering over the desired target point.

enter image description here

(A duplicate used, here, for illustration.)

$\endgroup$
1
  • 1
    $\begingroup$ Thank you for your help, although this is what I was trying to avoid, having to use middle steps on the process. $\endgroup$
    – Fabman
    Nov 2 '20 at 11:05
6
$\begingroup$

Maybe there's a cleaner way to do it but you could select all the objects, switch to Edit mode, enable the vertex snapping option (CtrlShiftTab to choose the vertex option), select these 5 vertices and duplicate:

enter image description here

$\endgroup$
6
  • $\begingroup$ The problem with this solution as you said is that is not very clean and if the object has a lot of geometry is kind of slow to work this way. Maybe someone can find a quicker and cleaner way like the one on the gif. $\endgroup$
    – Fabman
    Nov 2 '20 at 10:41
  • 1
    $\begingroup$ Well... I think it's cunning :D $\endgroup$ Nov 2 '20 at 10:52
  • 1
    $\begingroup$ @Robin, I think you've got the right way to do it, I always come with the most trashy ah ah, that said Fabman didn't want to use the 3D cursor, I don't know if it's avoidable though $\endgroup$
    – moonboots
    Nov 2 '20 at 10:53
  • $\begingroup$ It's pretty cunning indeed. I don't mind using the 3d cursor. It's pretty useful for plenty of cases, but in this case a simple one step movement has to be done in three or four steps. :-( $\endgroup$
    – Fabman
    Nov 2 '20 at 10:55
  • $\begingroup$ I wouldn't mind if it were something that you do once a day, but in this case I have to use hundreds of times while I'm working with plans. $\endgroup$
    – Fabman
    Nov 2 '20 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.