Does a script exist that could place an object with one click?

I was wondering if there was a script that could clone a random object out of a group and place it wherever your mouse is/object origin/3d cursor is? I’m going to be placing hundreds of objects soon, was wondering if there was an easier way to do it than cloning and dragging each individual one.

Use the particle system.
Set the particle to group.
Select the group of objects and enable the ‘pick random’ option .
You can then influence the position of the random object either by a texture or paint them with weight painting.

I’ll have to do a lot of position adjustments, so if I use a particle system, am I able to apply it and then have all the objects ready to reposition individually? Also, if I apply a particle system, does it function as a clone (Alt-D) or a copy (Shift-D?)

Not really elegant or fail-proof, but might be ok for the job:

import bpy
from bpy.props import IntProperty, FloatProperty
from bpy_extras.view3d_utils import location_3d_to_region_2d

class ModalOperator(bpy.types.Operator):
    """Move an object with the mouse, example"""
    bl_idname = "object.modal_operator"
    bl_label = "Simple Modal Operator"

    def modal(self, context, event):
        if self.start or event.type == 'LEFTMOUSE':
            self.start = False
            bpy.ops.object.duplicate_move('INVOKE_DEFAULT')

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            bpy.ops.object.delete()
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        if context.object:
            self.start = True
            co = context.object.matrix_world.translation
            rv3d = context.space_data.region_3d
            vec = location_3d_to_region_2d(context.region, rv3d, co)
            context.window.cursor_warp(vec.x + context.region.x, vec.y + context.region.y)

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalOperator)


def unregister():
    bpy.utils.unregister_class(ModalOperator)


if __name__ == "__main__":
    register()


Run that in in the text editor, then hit spacebar over view3d and search for “Simple Modal Operator”. The object you wanna duplicate needs to be the active object before you do that, and be visible in the viewport. The mouse cursor will be set to object’s origin and you can LMB to place the duplicate (RMB to stop).

Got an error message, "File “text”, line 27 “window” has no attribute “cursor_warp”
any idea what this means?

2.69 is required, cursor_warp is not available in older versions:

http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.69/Addons#Mouse_Cursor_Access

Ok, guess I’ll finally upgrade to 2.69. Its been a good half year since I’ve upgraded I suppose.

Worked nicely, is there a way to make it Alt-D as opposed to Shift-D?

just replace this line:

bpy.ops.object.duplicate_move('INVOKE_DEFAULT')

by

bpy.ops.object.duplicate_move_linked('INVOKE_DEFAULT')

Thanks for all of the help, this can save me a lot of time :smiley: