import bpy def copy_object(name, ifc_name=None, diam=None): #copy the object and move it to another collection bpy.ops.object.select_all(action='DESELECT') target_collection = bpy.data.collections.get("Temp_collection") obj = bpy.data.objects.get(name) obj.select_set(True) copied_obj = obj.copy() copied_obj.data = obj.data.copy() obj.select_set(False) if ifc_name is not None: copied_obj.name = f"{ifc_name}_{diam}" target_collection.objects.link(copied_obj) return copied_obj def get_obj_layers(pictog_name, diam): #get objects from layers bpy.ops.object.select_all(action='DESELECT') collection_layers = bpy.data.collections["Layers"] dic_layers = {"ifc_obj_layer": None, "layers":[]} list_cross_stripe = [] #list for sign with cross stripe, ex: "R-6c" list_single_stripe = [] #list for sign with single stripe, ex: "R-3" for obj in collection_layers.objects: name = obj.name if obj.name == "sign_plate": dic_layers["ifc_obj_layer"] = copy_object(name, pictog_name, diam) if obj.name == "white_layer": dic_layers["layers"].append(copy_object(name)) if obj.name == "cross_stripe" and pictog_name in list_cross_stripe: dic_layers["layers"].append(copy_object(name)) if obj.name == "single_stripe" and pictog_name in list_single_stripe: dic_layers["layers"].append(copy_object(name)) dic_layers["layers"].append(copy_object(pictog_name, "pictogram", diam)) return dic_layers def create_ifc_object(ifc_obj): #creates the IFC object bpy.ops.object.select_all(action='DESELECT') ifc_obj.select_set(True) bpy.context.view_layer.objects.active = ifc_obj bpy.ops.bim.assign_class(ifc_class="IfcSignType", predefined_type="PICTORAL", userdefined_type="") ifc_obj.select_set(False) def join_meshes(dic_layers): #join the layers of representational items bpy.ops.object.select_all(action='DESELECT') for obj in dic_layers["layers"]: obj.select_set(True) ifc_obj = dic_layers["ifc_obj_layer"] ifc_name = ifc_obj.name ifc_obj = bpy.data.objects.get(ifc_name) ifc_obj.select_set(True) bpy.context.view_layer.objects.active = ifc_obj bpy.ops.object.join() bpy.ops.bim.update_representation(obj=ifc_obj.name) bpy.ops.object.select_all(action='DESELECT') coll_pictograms = bpy.data.collections["Pictograms"] diam = "Diam=50cm" for pict in coll_pictograms.objects: name = pict.name dic_layers = get_obj_layers(name, diam) create_ifc_object(dic_layers["ifc_obj_layer"]) join_meshes(dic_layers)