mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
resource.add_resource_quantity to ensure quantity type is supported
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.resource
|
||||
|
||||
|
||||
def add_resource_quantity(
|
||||
@@ -66,6 +67,14 @@ def add_resource_quantity(
|
||||
"""
|
||||
settings = {"resource": resource, "ifc_class": ifc_class}
|
||||
|
||||
resource_type = resource.is_a()
|
||||
supported_quantities = ifcopenshell.util.resource.RESOURCES_TO_QUANTITIES[resource_type]
|
||||
if ifc_class not in supported_quantities:
|
||||
raise ValueError(
|
||||
f"Resource type '{resource_type}' does not support quantity type '{ifc_class}'. "
|
||||
f"Supported quantities: {','.join(supported_quantities)}"
|
||||
)
|
||||
|
||||
quantity = file.create_entity(settings["ifc_class"], Name="Unnamed")
|
||||
# 3 IfcPhysicalSimpleQuantity Value
|
||||
if settings["ifc_class"] == "IfcQuantityCount":
|
||||
|
||||
Reference in New Issue
Block a user