def test_creating_an_entity(self): element = self.file.create_entity("IfcPerson") assert element.is_a("IfcPerson") element = self.file.create_entity("IfcPerson", "identification") assert element.Identification == "identification" element = self.file.create_entity("IfcPerson", Identification="identification") assert element.Identification == "identification" element = self.file.create_entity("IfcPerson", Identification="identification", id=42) assert element.id() == 42 element = self.file.createIfcPerson() assert element.is_a("IfcPerson")
def patch(self): deleted = [] hashes = {} for element in self.file: if element.is_a('IfcRoot'): continue h = hash(tuple(element)) if h in hashes: for inverse in self.file.get_inverse(element): ifcopenshell.util.element.replace_attribute( inverse, element, hashes[h]) deleted.append(element.id()) else: hashes[h] = element deleted.sort() deleted_q = deque(deleted) new = '' for line in self.file.wrapped_data.to_string().split('\n'): try: if int(line.split('=')[0][1:]) != deleted_q[0]: new += (line + '\n') else: deleted_q.popleft() except: new += (line + '\n') self.file = new
def copy_object_placements(self, element): if not element.is_a("IfcProduct") or not element.ObjectPlacement: return element.ObjectPlacement = ifcopenshell.util.element.copy( self.file, element.ObjectPlacement) element.ObjectPlacement.RelativePlacement = ifcopenshell.util.element.copy_deep( self.file, element.ObjectPlacement.RelativePlacement)
def _get_own_collection(cls, element, obj): if element.is_a("IfcProject"): return bpy.data.collections.get(obj.name, bpy.data.collections.new(obj.name)) if tool.Ifc.get_schema() == "IFC2X3": if element.is_a("IfcSpatialStructureElement"): return bpy.data.collections.get( obj.name, bpy.data.collections.new(obj.name)) else: if element.is_a("IfcSpatialElement"): return bpy.data.collections.get( obj.name, bpy.data.collections.new(obj.name)) if element.is_a("IfcGrid"): return bpy.data.collections.get(obj.name, bpy.data.collections.new(obj.name)) if element.is_a("IfcGridAxis"): if element.PartOfU: grid = element.PartOfU[0] axes = "UAxes" elif element.PartOfV: grid = element.PartOfV[0] axes = "VAxes" elif element.PartOfW: grid = element.PartOfW[0] axes = "WAxes" grid_obj = tool.Ifc.get_object(grid) if grid_obj: grid_col = bpy.data.collections.get(grid_obj.name) axes_col = [c for c in grid_col.children if axes in c.name] if axes_col: return axes_col[0] return bpy.data.collections.new(axes) if element.is_a("IfcAnnotation"): for rel in element.HasAssignments or []: if rel.is_a("IfcRelAssignsToGroup" ) and rel.RelatingGroup.ObjectType == "DRAWING": name = "IfcGroup/" + rel.RelatingGroup.Name return bpy.data.collections.get( name, bpy.data.collections.new(name)) if element.is_a("IfcStructuralMember"): return bpy.data.collections.get( "Members", bpy.data.collections.new("Members")) if element.is_a("IfcStructuralConnection"): return bpy.data.collections.get( "Connections", bpy.data.collections.new("Connections")) if getattr(element, "IsDecomposedBy", None): return bpy.data.collections.get(obj.name, bpy.data.collections.new(obj.name))
def invoke(self, context, event): props = bpy.context.scene.BIMSearchProperties props.filter_classes.clear() ifc_types = {} for obj in context.selected_objects: element = tool.Ifc.get_entity(obj) if not element: continue ifc_types.setdefault(element.is_a(), 0) ifc_types[element.is_a()] += 1 for name, total in dict(sorted(ifc_types.items())).items(): new = props.filter_classes.add() new.name = name new.total = total props.filter_type = "CLASSES" return context.window_manager.invoke_props_dialog(self, width=250)
def name(cls): element = tool.Ifc.get_entity(bpy.context.active_object) if not element: return name = element.is_a() predefined_type = ifcopenshell.util.element.get_predefined_type( element) if predefined_type: name += f"[{predefined_type}]" return name
def execute(self, context): self.file = IfcStore.get_file() for obj in context.visible_objects: if not obj.BIMObjectProperties.ifc_definition_id: continue element = self.file.by_id( obj.BIMObjectProperties.ifc_definition_id) if does_keyword_exist(self.ifc_class, element.is_a(), context): obj.select_set(True) return {"FINISHED"}
def get_wildcard_attributes(self, attribute): results = set() pset_qto_name = attribute.split('.', 1)[0] for element in self.ifc_file.by_type('IfcPropertySet') + self.ifc_file.by_type('IfcElementQuantity'): if element.Name != pset_qto_name: continue if element.is_a('IfcPropertySet'): results.update([p.Name for p in element.HasProperties]) else: results.update([p.Name for p in element.Quantities]) return ['{}.{}'.format(pset_qto_name, n) for n in results]
def relating_type_classes(cls): results = [] obj = bpy.context.active_object if not obj: return element = tool.Ifc.get_entity(obj) if not element: return [] types = ifcopenshell.util.type.get_applicable_types( element.is_a(), schema=tool.Ifc.get_schema()) results.extend((t, t, "") for t in types) return results
def get_element_pset(element, name): if element.is_a('IfcTypeObject'): if element.HasPropertySets: for pset in element.HasPropertySets: if pset.is_a('IfcPropertySet') \ and pset.Name == name: return pset else: for relationship in element.IsDefinedBy: if relationship.is_a('IfcRelDefinesByProperties') \ and relationship.RelatingPropertyDefinition.is_a('IfcPropertySet') \ and relationship.RelatingPropertyDefinition.Name == name: return relationship.RelatingPropertyDefinition
def delete_ifc_object(self, obj): if obj.BIMObjectProperties.ifc_definition_id: element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) IfcStore.delete_element(element) if getattr(element, "FillsVoids", None): self.remove_filling(element) if element.is_a("IfcOpeningElement"): for rel in element.HasFillings: self.remove_filling(rel.RelatedBuildingElement) if element.VoidsElements: self.delete_opening_element(element) elif getattr(element, "HasOpenings", None): for rel in element.HasOpenings: self.delete_opening_element(rel.RelatedOpeningElement)
def get_classes(self, element, position): classes = [position, element.is_a()] for association in element.HasAssociations: if association.is_a('IfcRelAssociatesMaterial'): classes.append('material-{}'.format( re.sub( '[^0-9a-zA-Z]+', '', self.get_material_name(association.RelatingMaterial)))) classes.append('globalid-{}'.format(element.GlobalId)) for attribute in self.attributes: result = self.selector.get_element_value(element, attribute) if result: classes.append('{}-{}'.format( re.sub('[^0-9a-zA-Z]+', '', attribute), re.sub('[^0-9a-zA-Z]+', '', result))) return classes
def _get_collection(cls, element, obj): if element.is_a("IfcTypeObject"): return cls._create_project_child_collection("Types") if element.is_a("IfcOpeningElement"): return cls._create_project_child_collection("IfcOpeningElements") if element.is_a("IfcGridAxis"): if element.PartOfU: grid = element.PartOfU[0] axes = "UAxes" elif element.PartOfV: grid = element.PartOfV[0] axes = "VAxes" elif element.PartOfW: grid = element.PartOfW[0] axes = "WAxes" grid_obj = tool.Ifc.get_object(grid) if grid_obj: return bpy.data.collections.get(grid_obj.name) if element.is_a("IfcAnnotation"): for rel in element.HasAssignments or []: if rel.is_a("IfcRelAssignsToGroup" ) and rel.RelatingGroup.ObjectType == "DRAWING": return cls._create_project_child_collection("Views") if element.is_a("IfcStructuralItem"): return cls._create_project_child_collection("StructuralItems") aggregate = ifcopenshell.util.element.get_aggregate(element) if aggregate: aggregate_obj = tool.Ifc.get_object(aggregate) if aggregate_obj: collection = bpy.data.collections.get(aggregate_obj.name) if collection: return collection container = ifcopenshell.util.element.get_container(element) if container: container_obj = tool.Ifc.get_object(container) collection = bpy.data.collections.get(container_obj.name) if collection: return collection if element.is_a("IfcProject"): return bpy.context.scene.collection project_obj = tool.Ifc.get_object( tool.Ifc.get().by_type("IfcProject")[0]) if project_obj: collection = bpy.data.collections.get(project_obj.name) if collection: return collection
def _execute(self, context): self.file = IfcStore.get_file() colours = cycle(colour_list) ifc_classes = {} for obj in context.visible_objects: if not obj.BIMObjectProperties.ifc_definition_id: continue element = self.file.by_id( obj.BIMObjectProperties.ifc_definition_id) ifc_class = element.is_a() if ifc_class not in ifc_classes: ifc_classes[ifc_class] = next(colours) obj.color = ifc_classes[ifc_class] areas = [a for a in context.screen.areas if a.type == "VIEW_3D"] if areas: areas[0].spaces[0].shading.color_type = "OBJECT" return {"FINISHED"}
def get_brick_type(element): result = None predefined_type = ifcopenshell.util.element.get_predefined_type(element) if predefined_type: result = ifc4_to_brick_map.get(f"{element.is_a()}.{predefined_type}", None) if not result: result = ifc4_to_brick_map.get(element.is_a(), None) if not result: element_type = ifcopenshell.util.element.get_type(element) if element_type: ifc_type_class = element_type.is_a().replace("Type", "") result = ifc4_to_brick_map.get( f"{ifc_type_class}.{predefined_type}", None) if not result: result = ifc4_to_brick_map.get(ifc_type_class, None) if result: return f"https://brickschema.org/schema/Brick#{result}" # We choose equipment as a generic fallback return f"https://brickschema.org/schema/Brick#Equipment"
def set_element_key(ifc_file, element, key, value): if key == 'type' and element.is_a() != value: return IfcAttributeExtractor.change_ifc_class(ifc_file, element, value) if hasattr(element, key): setattr(element, key, value) return element if '.' not in key: return element if key[0:3] == 'Qto': qto, prop = key.split('.', 1) qto = IfcAttributeExtractor.get_element_qto(element, qto_name) if qto: IfcAttributeExtractor.set_qto_property(qto, prop, value) return element pset_name, prop = key.split('.', 1) pset = IfcAttributeExtractor.get_element_pset(element, pset_name) if pset: IfcAttributeExtractor.set_pset_property(pset, prop, value) return element return element
def set_element_key(ifc_file, element, key, value): if key == "type" and element.is_a() != value: return ifcopenshell.util.schema.reassign_class( ifc_file, element, value) if hasattr(element, key): setattr(element, key, value) return element if "." not in key: return element if key[0:3] == "Qto": qto_name, prop = key.split(".", 1) qto = IfcAttributeSetter.get_element_qto(element, qto_name) if qto: IfcAttributeSetter.set_qto_property(qto, prop, value) return element pset_name, prop = key.split(".", 1) pset = IfcAttributeSetter.get_element_pset(element, pset_name) if pset: IfcAttributeSetter.set_pset_property(ifc_file, pset, prop, value) return element return element
def get_covetool_category(self, obj): if not hasattr(obj, "data") or not isinstance(obj.data, bpy.types.Mesh): return if not obj.BIMObjectProperties.ifc_definition_id: return element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) ifc_class = element.is_a() if "IfcSlab" in ifc_class: return "floors" elif "IfcRoof" in ifc_class: return "roofs" elif "IfcWall" in ifc_class: if self.is_wall_internal(element): return "interior_walls" return "walls" elif "IfcWindow" in ifc_class: if self.is_window_skylight(element): return "skylights" return "windows" elif "IfcShadingDevice" in ifc_class: return "shading_devices"
def execute(self, context): obj = context.active_object self.file = IfcStore.get_file() ifc_class = obj.name.split("/")[0] context.active_object.BIMObjectProperties.is_reassigning_class = True ifc_products = [ "IfcElement", "IfcElementType", "IfcSpatialElement", "IfcGroup", "IfcStructural", "IfcPositioningElement", "IfcContext", "IfcAnnotation", "IfcRelSpaceBoundary", ] for ifc_product in ifc_products: if ifcopenshell.util.schema.is_a(IfcStore.get_schema().declaration_by_name(ifc_class), ifc_product): context.scene.BIMRootProperties.ifc_product = ifc_product element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) context.scene.BIMRootProperties.ifc_class = element.is_a() if hasattr(element, "PredefinedType") and element.PredefinedType: context.scene.BIMRootProperties.ifc_predefined_type = element.PredefinedType return {"FINISHED"}
def test_adding_an_element(self): g = ifcopenshell.file() element = g.createIfcWall() result = self.file.add(element) assert result.is_a() == element.is_a()
def remove_representations(self, element): if element.is_a("IfcProduct"): element.Representation = None elif element.is_a("IfcTypeProduct"): element.RepresentationMaps = None
def ifc_class(cls): element = tool.Ifc.get_entity(bpy.context.active_object) if element: return element.is_a()
def is_product(cls): element = tool.Ifc.get_entity(bpy.context.active_object) return element.is_a("IfcProduct")