I am working on a script to replace objects.
For architectural visualisation I have files where I have lots of duplicates of one object and want to replace them with duplicates of another objects.
I have managed to tackle parenting and local/global coordinates.
As I am using the array modifier sometimes I would also like to check for that in the search object and create that in the replace duplicate.
I am stuck finding the right settings. I am using the zoologique api site for lookup but I cannot seem to find what I need.
Anyone able to point me in the right direction?
Also am open to improvement ideas of the current script.
thanks in advance
chris
script looks like this so far:
import bpy
import Blender
#from Blender import *
print "START--------------------"
sce = bpy.data.scenes.active
#list of search/replace tuples
searchReplaceObj = [
("Cube", "Sphere"),
("Cylinder", "Pyramid")]
for cur_SRO in searchReplaceObj:
searchObj = cur_SRO[0]
replaceObj = cur_SRO[1]
print "searching for [%s]" % searchObj
print "replacing with [%s]" % replaceObj
sce.objects.selected = []
for obj in sce.objects:
if obj.getName()[:len(searchObj)] == searchObj:
print obj, obj.getName(), obj.getParent()
mods = obj.modifiers
for mod in mods:
print mod, mod.name
print
# get replacement Object
obj_new = Blender.Object.Get(replaceObj)
# make it active
obj_new.sel = 1
# duplicate it
Blender.Object.Duplicate()
# get the current duplicated
ob_act = sce.objects.active
# get worldspace data
(x, y, z) = obj.getLocation('worldspace')
(rx, ry, rz) = obj.getEuler('worldspace')
# print loc, rot
# update the location
ob_act.LocX = x
ob_act.LocY = y
ob_act.LocZ = z
# update the rotation
ob_act.RotX = rx
ob_act.RotY = ry
ob_act.RotZ = rz
# possibly update parent
if obj.getParent():
ob_list = []
ob_list.append(ob_act)
obj.getParent().makeParent(ob_list)
# deselect all
sce.objects.selected = []
# delete original search object
sce.unlink(obj)
sce.update()
Blender.Redraw()