this is a script I wrote to paint in tree’s on terrain-
once you run the script these are the controles
“LMB:Paint BMB:Quit Shift:Pan Ctrl:BrushSize”
it paints from the selected objects, its a fairly simple script so might be a good example, the panning is usefull in other tools to so you can move the view without restarting the script.
limitations are it only works in top down view (numpad 7), orthographic (numpad 5)
it needs a recent build of blender
_ EDIT
randomizing scale and rotation can be done with another script I wrote - its in the object menu “Randomize Loc Size Rot” - that way you can tweak the randomness later on.
object_brush_v2.py
#!BPY
"""
Name: 'Brush Selected Objects 2D'
Blender: 234
Group: 'Object'
Tooltip: 'Scatter brush selected objects X/Y'
"""
import Blender
import BPyMesh
import BPyWindow
from Blender import *
mouseViewRay= BPyWindow.mouseViewRay
from Blender import Mathutils, Window, Scene, Draw, sys
from Blender.Mathutils import CrossVecs, Vector, Intersect, LineIntersect, AngleBetweenVecs
LMB= Window.MButs.L
RMB= Window.MButs.R
#MMB= Window.MButs.M
CTRL= Window.Qual.CTRL
SHIFT= Window.Qual.SHIFT
#ALT= Window.Qual.ALT
msg = 'LMB:Paint BMB:Quit Shift:Pan Ctrl:BrushSize - %.2f'
def main():
brush_size= 5.0
# new_
scn= Scene.GetCurrent()
scn_objects = scn.objects
objects= list(scn_objects.selected)
rand_vec = Vector(0,0)
if not objects:
Draw.PupMenu('Aborting%t|no objects selected')
return
Window.DrawProgressBar(0.0, msg % brush_size)
z_level = Window.GetCursorPos()[2]
i= 0 # counter
mco_old = None
mouse_buttons = Window.GetMouseButtons()
while not (mouse_buttons & RMB):
if mouse_buttons & LMB:
mco = Window.GetMouseCoords()
if mco != mco_old:
mouseInView, OriginA, DirectionA = mouseViewRay(*mco)
if mouseInView:
rand_vec.x = Noise.random()-0.5
rand_vec.y = Noise.random()-0.5
rand_vec.length = brush_size * Noise.random()
# Paint now
i +=1
if i == len(objects): i= 0
ob= objects[i].__copy__()
ob.clrParent(2, 1)
scn_objects.link(ob)
ob.loc= OriginA.x + rand_vec.x, OriginA.y + rand_vec.y, z_level
Window.Redraw(Window.Types.VIEW3D)
mco_old= mco
else:
# Pan
qual= Window.GetKeyQualifiers()
while qual & SHIFT:
x,y= Window.GetMouseCoords()
mouseInView, mid_v, DirectionA = mouseViewRay(x,y, None, True)
if mouseInView:
mouseInView, mouse_v, DirectionA = mouseViewRay(x,y, None, False)
if mouseInView:
v_off= Vector(Window.GetViewOffset())
off= (mouse_v-mid_v) * 0.05
Window.SetViewOffset(v_off - off)
Window.Redraw(Window.Types.VIEW3D)
qual= Window.GetKeyQualifiers()
# Brush size
if qual & CTRL:
mco_old = Window.GetMouseCoords()
brush_size_old= brush_size
while qual & CTRL:
mco = Window.GetMouseCoords()
brush_size = brush_size_old + (mco_old[1] - mco[1]) * 0.01
if brush_size<0: brush_size = 0.0 # dissallw neg brushes.
# Bruush Size
Window.DrawProgressBar(0.0, msg % brush_size)
qual= Window.GetKeyQualifiers()
mouse_buttons = Window.GetMouseButtons()
Window.Redraw(Window.Types.VIEW3D)
main()