I am trying to take the 1s and 0s in the B column, and use those to apply the mat_available (1) and the mat_occupied (0) to the planes.
I am a beginner in python, so my knowledge is limited. I was able to get the planes assigned to a material through the for loop, but I am unaware of how to use the csv as a guide to which planes get what material.
Example: "Unit 301" would be the first plane ("Plane") , and that plane would be assigned the 'mat_available' material since the B column is a 1. Then the next plane would get assigned its material based on column B and so on.
If I failed at explaining, please tell me.
Thanks!
import csv
import bpy
#---------------------------------------------------------#
# available material
mat_available = bpy.data.materials.new(name='available')
mat_available.use_nodes=True
mat_available_nodes = mat_available.node_tree.nodes
mat_available_links = mat_available.node_tree.links
mat_available_nodes['Principled BSDF'].inputs['Emission Strength'].default_value = (1)
mat_available_nodes['Principled BSDF'].inputs['Emission'].default_value = (1, 1, 1, 1)
# occupied material
mat_occupied = bpy.data.materials.new(name='occupied')
mat_occupied.use_nodes=True
mat_occupied_nodes = mat_occupied.node_tree.nodes
mat_occupied_links = mat_occupied.node_tree.links
mat_occupied_nodes['Principled BSDF'].inputs['Emission Strength'].default_value = (0)
mat_occupied_nodes['Principled BSDF'].inputs['Emission'].default_value = (1, 1, 1, 1)
#---------------------------------------------------------#
# De-selects objects
bpy.ops.object.select_all(action='DESELECT')
# Loads CSV
with open('C:/Users/Bryce/Desktop/python_test/occupancy.csv') as ufile:
readout = list(csv.reader(ufile))
lights = bpy.data.collections['lights'].objects
for obj in lights:
if readout[1] == 1:
obj.data.materials[0] = mat_available
else:
obj.data.materials[0] = mat_occupied