I work for a company that is developing a house buildings system where you assemble houses out of standard parts. Think Lego © just for real houses.
Once a house is designed using our construction software I end up with a file that contains all the locations of the parts used.
Now I want to build a blend file that will duplicate all used parts from a standard object library and then be able to do renders of the house.
This is the script I have developed so far (with lots of help from here).
"""
Name: 'populate'
Blender: 237
Group: Object
"""
import Blender
import math
import string
import bpy
from Blender import *
from math import *
from string import *
# prebuilding children list for speed reason
print "building child list" #status information the console window
children = {}
for ob in bpy.data.objects:
if 1 in ob.layers and ob.parent: # all the object library parts are on layer 1 for speed reason
if not ob.parent in children:
children[ob.parent] = []
children[ob.parent].append(ob)
#function to select children of parent objects
def mark_as_selected(the_object):
if the_object in children:
for ob in children[the_object]:
ob.sel = 1
mark_as_selected(ob)
print "starting population"
print "writing logfile"
pf=open('D:\\UDaten\\LLpopulate.log', 'w') #log file
f = file('input_file.dat')
scn = Blender.Scene.GetCurrent()
#read file
for line in f:
ar = split(line, '|') #delimiter character
try:
ob_act = Blender.Object.Get(ar[0]) # object name is first argument
scn.objects.selected = []
ob_act.sel = 1
# select children
mark_as_selected(ob_act)
Blender.Object.Duplicate() #Duplicate linked (might want to change this to not linked
ob_act = Object.GetSelected()
for t in ob_act:
t.layers = [2] # move object to layer 2
if t.getParent() is None: # Find parent
t.LocX = float(ar[7].replace(",",".")) # reposition object at x (7th argument in this case and change "," to "."
...
except:
pftext = "Ojbect %s not found.
" % (ar[0]) # update log file if object not found
pf.write(pftext)
print "ending population"
Blender.Redraw()
This supports objects that have sub-objects (parent-child). And for rendering ease the original parts (objects) are on layer 1 and the new populated parts are on layer 2
Basically this could be used for any case where you have to populate a blend file with objects according to an input file (trees, figures, cars, science stuff …)
Feel free to use it and let me know if you have ideas on how to improve it 
Chris