Object cloner script ( create instance's )

object cloner ( create instance’s )

#---------------------------------------------------

Like Alt+D , CANT do metaballs,text or emptys.

#---------------------------------------------------

Place clone’s ‘Linear’ or ‘Circular’(spiral).


#!BPY

"""
Name: 'Object cloner'
Blender: 233
Group: 'Wizards'
Tip: 'Create clones of sellected object'
"""

#------------------------------------------------------------------
# Jimmy Hazevoet  Aug. 2004
#---------------------------------------------------
# object cloner ( create instance's )
#---------------------------------------------------
## Like Alt+D , CANT do metaballs,text or emptys. ##
#---------------------------------------------------
# Place clone's 'Linear' or 'Circular'(spiral).
#-----------------------------------------------------------------

import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *
from math import sin, cos
from Blender.Noise import random

#----------------------------------------------------------------
numob = Create(8)
Lx = Create(0.0)
Ly = Create(0.0)
Lz = Create(0.0)
Rx = Create(0.0)
Ry = Create(0.0)
Rz = Create(0.0)
Sx = Create(0.0)
Sy = Create(0.0)
Sz = Create(0.0)
RL = Create(0.0)
RR = Create(0.0)
RS = Create(0.0)
circular = Create(0)
radius = Create(4.0)
length = Create(2.0)
spiro = Create(0.0)

#-----------------------------------------------------------------
def reset_fu():
   global numob, radius, length, spiro
   global Lx, Ly, Lz, Rx, Ry, Rz
   global Sx, Sy, Sz, RL, RR, RS

   numob = Create(8)
   Lx = Create(0.0)
   Ly = Create(0.0)
   Lz = Create(0.0)
   Rx = Create(0.0)
   Ry = Create(0.0)
   Rz = Create(0.0)
   Sx = Create(0.0)
   Sy = Create(0.0)
   Sz = Create(0.0)
   RL = Create(0.0)
   RR = Create(0.0)
   RS = Create(0.0)
   radius = Create(4.0)
   lenght = Create(2.0)
   spiro = Create(0.0)

#------------------------------------------------------------------
def input_fu():
   global numob, circular, radius, length, spiro
   global Lx, Ly, Lz, Rx, Ry, Rz
   global Sx, Sy, Sz, RL, RR, RS

   try:
      obj = Blender.Object.GetSelected()[0]
      scn = Scene.getCurrent()
      type = obj.getType()

      for i in range(0, numob.val):

         ob = Object.New(type)
         ob.shareFrom(obj) 
         scn.link(ob)

         randL = RL.val * random()
         randR = RR.val * random()
         randS = RS.val * random()

         if circular.val==1:
            phi = 3.141592653589 * length.val * i / numob.val
            spi = (spiro.val*phi)
            x =  randL + radius.val * cos(phi) +Lx.val
            x+= x*spi
            y =  randL + radius.val * sin(phi) +Ly.val
            y+= y*spi
            z = i * Lz.val + randL
          ##z+= z*spi##
         else:
            phi = 3.141592653589 * 2 * i / (numob.val-1)
            x = i * Lx.val + randL
            y = i * Ly.val + randL
            z = i * Lz.val + randL

         ob.setLocation(x,y,z)


         ob.SizeX = ob.SizeX + randS + Sx.val *i
         ob.SizeY = ob.SizeY + randS + Sy.val *i
         ob.SizeZ = ob.SizeZ + randS + Sz.val *i
         if ob.SizeX < 0.0:  ob.SizeX = 0.0
         if ob.SizeY < 0.0:  ob.SizeY = 0.0
         if ob.SizeZ < 0.0:  ob.SizeZ = 0.0

         ob.RotX = randR + Rx.val * phi/360
         ob.RotY = randR + Ry.val * phi/360
         ob.RotZ = randR + Rz.val * phi/360

      #
      ob.drawMode = obj.drawMode 
      ob.Layer = obj.Layer 
      scn.update(1) 

      return ob
   except:
      print "error"

#------------------------------------------------------------------
def GUI_Box(x, y, w, h, r, g, b):
   glColor3f(r+0.075, g+0.075, b+0.075)
   glRecti(x+6, y-6, w+6, h-6)
   glColor3f(r+0.05, g+0.05, b+0.05)
   glRecti(x+5, y-5, w+5, h-5)
   glColor3f(r+0.025, g+0.025, b+0.025)
   glRecti(x+4, y-4, w+4, h-4)
   glColor3f(r, g, b)
   glRecti(x+3, y-3, w+3, h-3)
   glColor3f(r-0.025, g-0.025, b-0.025)
   glRecti(x+2, y-2, w+2, h-2)
   glColor3f(r-0.3, g-0.3, b-0.3)
   glRecti(x, y, w, h)
   glColor3f(r+0.2, g+0.2, b+0.2)
   glRecti(x+1, y+1, w-1, h-1)

   if circular.val==0:
      glColor3f(r-0.15, g-0.15, b-0.15)
      glRecti(x+31, y+145, w-269, h-30)
      glColor3f(r-0.05, g-0.05, b-0.05)
      glRecti(x+46, y+142, w-250, h-28)
      glColor3f(r+0.05, g+0.05, b+0.05)
      glRecti(x+66, y+141, w-224, h-26)
      glColor3f(r+0.15, g+0.15, b+0.15)
      glRecti(x+92, y+139, w-102, h-24)

#------------------------------------------------------------------
def gui():
   global numob, circular, radius, length, spiro
   global Lx, Ly, Lz, Rx, Ry, Rz
   global Sx, Sy, Sz, RL, RR, RS

   BGL.glClearColor(0.6, 0.6, 0.6, 1)
   BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)

   GUI_Box(10, 10, 319, 193, 0.5,0.5,0.5)

   glColor3f(0.0, 0.0, 0.0)
   glRasterPos2d(18, 130)
   Text("Obj.","small")
   numob = Number("",3,40,125,56,18,numob.val,1,1000)

   circular = Toggle("Circle",3,162,125,56,18,circular.val)
   if circular.val==1:
      glColor3f(0.0, 0.0, 0.0)
      glRasterPos2d(55,173)
      Text("Radius","small")
      glRasterPos2d(115,173)
      Text("Length","small")
      glRasterPos2d(177,173)
      Text("Spiral","small")
      radius = Number("",3,40,150,56,18,radius.val,0.0,50.0)
      length = Number("",3,101,150,56,18,length.val,0.0,50.0)
      spiro  = Number("",3,162,150,56,18,spiro.val,-1.0,1.0)
   else:
      glColor3f(0.1, 0.1, 0.1)
      glRasterPos2d(121,155)
      Text("Object cloner.")

   glColor3f(0.0, 0.0, 0.0)
   glRasterPos2d(67, 108)
   Text("X","small")
   glRasterPos2d(127, 108)
   Text("Y","small")
   glRasterPos2d(188, 108)
   Text("Z","small")
   glRasterPos2d(18, 90)
   Text("Ofs.","small")
   Lx = Number("",3,40,85,56,18,Lx.val,-50.0,50.0)
   Ly = Number("",3,101,85,56,18,Ly.val,-50.0,50.0)
   Lz = Number("",3,162,85,56,18,Lz.val,-50.0,50.0)

   glRasterPos2d(18, 65)
   Text("Rot.","small")
   Rx = Number("",3,40,60,56,18,Rx.val,-1000.0,1000.0)
   Ry = Number("",3,101,60,56,18,Ry.val,-1000.0,1000.0)
   Rz = Number("",3,162,60,56,18,Rz.val,-1000.0,1000.0)

   glRasterPos2d(18, 40)
   Text("Size","small")
   Sx = Number("",3,40,35,56,18,Sx.val,-50.0,50.0)
   Sy = Number("",3,101,35,56,18,Sy.val,-50.0,50.0)
   Sz = Number("",3,162,35,56,18,Sz.val,-50.0,50.0)

   glRasterPos2d(244, 108)
   Text("Random","small")
   RL = Number("",3,233,85,56,18,RL.val,-50.0,50.0)
   RR = Number("",3,233,60,56,18,RR.val,-50.0,50.0)
   RS = Number("",3,233,35,56,18,RS.val,-50.0,50.0)

   Button("Clone",2,101,125,56,18)
   Button("Reset",4,233,125,56,18)
   Button("Exit",1,233,150,56,18)

#---------------------------------------
def event(evt, val):
   if (evt == ESCKEY and not val):
      name = "OK?%t|Exit %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         Exit()
#---------------------------------------
def bevent(evt):
   global B, infotext
   if evt == 1:
      name = "OK?%t|Exit %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         Exit()
   if evt == 2:
      input_fu()
      Blender.Redraw()
   if evt == 3:
      Draw()
   if evt == 4:
      name = "OK?%t|Reset %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         reset_fu()
         Draw()

Register(gui, event, bevent)

just to post the address of a script to copy a list of objects on a mesh like duplivert but with several objects:
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_b223new.htm#duplicopy232