Adding material to spheres sequentially using Python

by user120911   Last Updated December 07, 2017 09:15 AM

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. Could someone please help me tweak the script to make it function as desired?

import bpy, csv
bpy.ops.script.python_file_run(filepath="C:\\Program Files\\Blender 
bpy.ops.mesh.primitive_plane_add(radius=50,view_align=False, enter_editmode=False, location=(0, 0, 0))
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[3]), location = float(row[0]),float(row[1]),float(row[2])))
        bpy.context.object.active_material.diffuse_color = (1, 0, 0) 
Tags : python

Related Questions

Ipodtouch Jail-Break aid?

Updated March 26, 2015 07:30 AM

Python: Methods to multiply/divide vectors

Updated March 27, 2015 14:20 PM

Adding sliders from UI to pie menu

Updated April 19, 2015 22:09 PM