diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index b4f4487bba..4578562b7e 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -120,6 +120,8 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty(name="Material Name") name: bpy.props.StringProperty(default="Default") + category: bpy.props.StringProperty(default="") + description: bpy.props.StringProperty(default="") def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) @@ -127,10 +129,14 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator): def draw(self, context): row = self.layout row.prop(self, "name", text="Name") + row = self.layout + row.prop(self, "description", text="Description") + row = self.layout + row.prop(self, "category", text="Category") def _execute(self, context): obj = bpy.data.materials.get(self.obj) if self.obj else None - core.add_material(tool.Ifc, tool.Material, tool.Style, obj=obj, name=self.name) + core.add_material(tool.Ifc, tool.Material, tool.Style, obj=obj, name=self.name, category=self.category, description=self.description) material_prop_purge() diff --git a/src/blenderbim/blenderbim/core/material.py b/src/blenderbim/blenderbim/core/material.py index 87a3ae9e0a..bd3eb87748 100644 --- a/src/blenderbim/blenderbim/core/material.py +++ b/src/blenderbim/blenderbim/core/material.py @@ -21,10 +21,10 @@ def unlink_material(ifc, obj=None): ifc.unlink(obj=obj) -def add_material(ifc, material, style, obj=None, name=None): +def add_material(ifc, material, style, obj=None, name=None, category=None, description=None): if not obj: obj = material.add_default_material_object(name) - ifc_material = ifc.run("material.add_material", name=material.get_name(obj)) + ifc_material = ifc.run("material.add_material", name=material.get_name(obj), category=category, description=description) ifc.link(ifc_material, obj) ifc_style = style.get_style(obj) if ifc_style: diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py index f8cd351e03..ad05948a03 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_material.py @@ -20,7 +20,7 @@ from typing import Optional def add_material( - file: ifcopenshell.file, name: Optional[str] = None, category: Optional[str] = None + file: ifcopenshell.file, name: Optional[str] = None, category: Optional[str] = None, description: Optional[str] = None ) -> ifcopenshell.entity_instance: """Adds a new material @@ -50,11 +50,16 @@ def add_material( Note that categories are not available in IFC2X3. This shortcoming is one of the big reasons projects should upgrade to IFC4. + Additionally, a material's description provides more information beyond + its name or category. + :param name: The name of the material, typically tagged in a finishes drawing or schedule. :type name: str, optional :param category: The category of the material. :type category: str, optional + :param description: A description of the material. + :type description: str, optional :return: The newly created IfcMaterial :rtype: ifcopenshell.entity_instance @@ -63,8 +68,8 @@ def add_material( .. code:: python # Let's create two materials with their respective categories - concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete") - steel = ifcopenshell.api.run("material.add_material", model, name="ST01", category="steel") + concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete", description="Garage Slab") + steel = ifcopenshell.api.run("material.add_material", model, name="ST01", category="steel", description="Corten Steel") # Let's imagine an urban concrete bench which is purely made out of concrete concrete_bench = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurnitureType") @@ -73,9 +78,11 @@ def add_material( # "Style" has been specified. ifcopenshell.api.run("material.assign_material", model, products=[concrete_bench], material=concrete) """ - settings = {"name": name or "Unnamed", "category": category} + settings = {"name": name or "Unnamed", "category": category, "description": description } material = file.create_entity("IfcMaterial", **{"Name": settings["name"] or "Unnamed"}) if settings["category"]: material.Category = settings["category"] + if settings["description"]: + material.Description = settings["description"] return material