I have the following script, which I was hoping would add a basic red material to my spheres as they are sequentially created. Unfortunately, the script does not work, in the sense that no material is added to any sphere. Indeed, no spheres are created, but in the absence of "bpy.ops.material.new()" and "bpy.context.object.active_material.diffuse_color = (1, 0, 0)", the script produces spheres.
Could someone please help me tweak the script to make it function as desired?
import bpy, csv fp = "C:/Blender/Spheres.csv" with open( fp ) as csvfile: rdr = csv.reader(csvfile, delimiter=';') for i, row in enumerate( rdr ): if i == 0: continue # Skip column title # Generate UV sphere at x = row0, y = row1, z = row2, and radius = row3. bpy.ops.mesh.primitive_uv_sphere_add(size = float(row), location = float(row),float(row),float(row))) bpy.ops.material.new() bpy.context.object.active_material.diffuse_color = (1, 0, 0)
A snippet of my CSV. spheres.csv
x;y;z;r 2.34;2.45;7.65;0.024 6.78;9.31;6.33;0.0467 3.36;8;1.04;0.3626