Background: Hello, I'm a researcher looking into the supply chain. A few years ago I was creating a static visualisation of vessels across the globe. I discovered Blender and using several tutorials was able to create a realistic map and using Python place glowing/emissive rods on the map. However, I needed more data and therefore left the project till now.
However, in that time things have changed in Blender and my script no longer work (not even on old versions).
Task: I'd like to run a For Loop, which parses through a preprepared csv file (I have this) and then creates a rod at many specific locations and then later applies colour and emissive properties to that particular rod (not necessarily in that order).
Current situation: When this was working, I was able to perform tasks in Blender (manually) and then copy the Python code for those steps from the console (this is still the case, but it's not working for me). As I recall, I had to add a step by giving each rod a "name", so that it could be assigned a material property (emissiveness and colour).
My old code (for the previous Blender version) looked like this:
import bpy, csv, random, os
fp = _file_path1_
cp = _file_path2_
with open( cp ) as csvfile:
rdr = csv.reader(csvfile, delimiter=';')
for i, row in enumerate( rdr):
if i == 0: continue # Skip column title
material = bpy.data.materials.new(name=str(row[0]))
material.use_nodes = True
material.node_tree.nodes.remove(material.node_tree.nodes.get('Diffuse BSDF'))
material_output = material.node_tree.nodes.get('Material Output')
emission = material.node_tree.nodes.new('ShaderNodeEmission')
emission.inputs['Strength'].default_value = 15.0
emission.inputs['Color'].default_value = (float(row[1]), float(row[2]), float(row[3]), float(1.0))
material.node_tree.links.new(material_output.inputs[0], emission.outputs[0])
rands_list = random.sample(range(35000), 2000)
with open( fp ) as csvfile:
rdr = csv.reader(csvfile, delimiter=';')
for i, row in enumerate( rdr ):
# if i >= 30000 and i < 30050:
if i in rands_list:
# Add spheres
bpy.ops.mesh.primitive_cylinder_add(
vertices=5,
radius= 0.005,
location = (float(row[1]), float(row[2]), float(0.045)),
depth = 0.01
)
bpy.context.object.active_material = bpy.data.materials[str(row[0])]
I'm a bit discouraged now. So would really appreciate help with this task.