i have a file containing ~ 10thousands coordinates and I need to create an object that is 1 gold sphere for each coordinate.
I realized that if I do something like:
def createsphere(name, position, size):
#bpy.ops.mesh.primitive_uv_sphere_add( location=position, size=size )
bpy.ops.surface.primitive_nurbs_surface_sphere_add( location=position, size=size )
ob = bpy.context.object
ob.name = name
ob.show_name = False
me = ob.data
me.name = name+'Mesh'
return ob
p=read("/home/cpi/BLENDER/terrazze.xyz")
for i in p:
if i.symbol == "C" :
createsphere('C', i.position,0.4)
setMaterial(bpy.context.object, rubber)
elif i.symbol == "H" :
createsphere('H', i.position,0.2)
setMaterial(bpy.context.object, gold)
elif i.symbol == "Au" :
createsphere('Au', i.position,1.2)
setMaterial(bpy.context.object, gold)
I can hanlde max ~100 spheres... What should I do to create my terraces made of gold spheres?
Thanks for your help
Carlo
Dear all, i found something that works although I am not sure to understand all details:
def qsphere( position, size):
bpy.ops.mesh.primitive_uv_sphere_add( location=position, size=size )
ob = bpy.context.active_object
return ob
def returnScene (passedIndex = 0):
try:
return bpy.data.scenes[passedIndex]
except:
return None
p=read(filei)
ob = qsphere(p[0].position,1.4) # NOTE: We only mess with the context one time.
ob.name = geoname
me = ob.data
me.name = geoname
print(me.name)
localScene = returnScene()
for i in p[1:]:
if i.symbol == "C" :
createsphere('C', i.position,0.4)
bpy.ops.object.shade_smooth()
setMaterial(bpy.context.object, rubber)
elif i.symbol == "H" :
createsphere('H', i.position,0.2)
bpy.ops.object.shade_smooth()
setMaterial(bpy.context.object, gold)
elif i.symbol == "Au" :
tempObjectName = i.symbol + returnNameForNumber(i)
ob_temp = bpy.data.objects.new(tempObjectName, me)
ob_temp.location=i.position
localScene.objects.link(ob_temp)