Hi,
So, I have been working on a project. I want to create an IfcOpenShell code that changes the color of elements that contain pre-established criteria.
I tried to assign styles to the elements, but they aren't changing color when I open the file and am confused about it. Could it be because some of the elements I am trying to change already have a material assigned to it? Do styles override materials? Could someone help me with the code?
I will paste it here in case anyone wants to read what I've done so far:
#### Model path:
model = ifcopenshell.open("file_path")
#### Creating the color styles:
waste = ifcopenshell.api.run("style.add_style", model, name = 'Waste')
reclaim = ifcopenshell.api.run("style.add_style", model, name = 'Reclaim')
recycle = ifcopenshell.api.run("style.add_style", model, name = 'Recycle')
reuse = ifcopenshell.api.run("style.add_style", model, name = 'Reuse')
#### Giving the styles a surface color:
ifcopenshell.api.run("style.add_surface_style", model, style=waste, ifc_class="IfcSurfaceStyleShading", attributes={"SurfaceColour":{ "Name": None, "Red": 1, "Green": 0, "Blue": 0 }})
ifcopenshell.api.run("style.add_surface_style", model, style=reclaim, ifc_class="IfcSurfaceStyleShading", attributes={"SurfaceColour":{ "Name": None, "Red": 0, "Green": 0, "Blue": 1 }})
ifcopenshell.api.run("style.add_surface_style", model, style=recycle, ifc_class="IfcSurfaceStyleShading", attributes={"SurfaceColour":{ "Name": None, "Red": 1, "Green": 1, "Blue": 0 }})
ifcopenshell.api.run("style.add_surface_style", model, style=reuse, ifc_class="IfcSurfaceStyleShading", attributes={"SurfaceColour":{ "Name": None, "Red": 0, "Green": 1, "Blue": 0 }})
#### Assigning colors:
for i in model.by_type('IfcElement'):
#### Filtering elements that have a DfR - Pset
if 'DfR - Pset' in Element.get_psets(i):
#### Filtering elements that have the attribute EoL assigned
if 'Material' in Element.get_psets(i)['DfR - Pset']:
representation = i.Representation
#### Assigning the colors:
if 'Material' == 'Waste':
ifcopenshell.api.run("style.assign_representation_styles", model, shape_representation=representation, styles=[waste])
elif 'Material' == 'Reclaim':
ifcopenshell.api.run("style.assign_representation_styles", model, shape_representation=representation, styles=[reclaim])
elif 'Material' == 'Recycle':
ifcopenshell.api.run("style.assign_representation_styles", model, shape_representation=representation, styles=[recycle])
elif 'Material' == 'Reuse':
ifcopenshell.api.run("style.assign_representation_styles", model, shape_representation=representation, styles=[reuse])
model.write('file_path')