import FreeCAD import random # build a dictionary to store values and associated colors colordict = {} # iterate over each object in the document for obj in FreeCAD.ActiveDocument.Objects: # only consider objects with IFC properties if hasattr(obj,"IfcProperties"): # search for the FireRating property # properties are stored as "PropertyName;;Pset" = "Type;;Value" for key,value in obj.IfcProperties.item(): propname,pset = key.split(";;") proptype,propvalue = value.split(";;") if propname == "FireRating": # look if this value was already stored in colordict if propvalue in colordict: # if yes, just attribute the color to the object obj.ViewObject.ShapeColor = colordict[propvalue] else: # if no, create a new color as a tuple of 3 float values (r,g,b) newcolor = (random.random(),random.random(),random.random()) # store that color for reuse colordict[propvalue] = newcolor obj.ViewObject.ShapeColor = newcolor # upon exporting again to IFC, colors will be kept automatically