ifcopenshell.api.cost.assign_cost_item_quantity¶
Module Contents¶
- class ifcopenshell.api.cost.assign_cost_item_quantity.FormulaEvaluator(values: dict[str, float | None])¶
Bases:
ast.NodeVisitorA node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method.
This class is meant to be subclassed, with the subclass adding visitor methods.
Per default the visitor functions for the nodes are
'visit_'+ class name of the node. So a TryFinally node visit function would be visit_TryFinally. This behavior can be changed by overriding the visit method. If no visitor function exists for a node (return value None) the generic_visit visitor is used instead.Don’t use the NodeVisitor if you want to apply changes to nodes during traversing. For this a special visitor exists (NodeTransformer) that allows modifications.
- generic_visit(node: ast.AST) Any¶
Called if no explicit visitor function exists for a node.
- visit_Attribute(node: ast.Attribute) float | None¶
- visit_BinOp(node: ast.BinOp) float¶
- visit_Constant(node: ast.Constant) Any¶
- visit_Name(node: ast.Name) float | None¶
- values¶
- class ifcopenshell.api.cost.assign_cost_item_quantity.Usecase¶
- add_quantity_from_qto(qto: ifcopenshell.entity_instance) None¶
- execute(cost_item: ifcopenshell.entity_instance, products: list[ifcopenshell.entity_instance], prop_name: str, formula: str, ifc_class: str)¶
- update_cost_item_count()¶
- file: ifcopenshell.file¶
- class ifcopenshell.api.cost.assign_cost_item_quantity.VariableExtractor¶
Bases:
ast.NodeVisitorA node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method.
This class is meant to be subclassed, with the subclass adding visitor methods.
Per default the visitor functions for the nodes are
'visit_'+ class name of the node. So a TryFinally node visit function would be visit_TryFinally. This behavior can be changed by overriding the visit method. If no visitor function exists for a node (return value None) the generic_visit visitor is used instead.Don’t use the NodeVisitor if you want to apply changes to nodes during traversing. For this a special visitor exists (NodeTransformer) that allows modifications.
- visit_Attribute(node: ast.Attribute) None¶
- visit_Name(node: ast.Name) None¶
- ifcopenshell.api.cost.assign_cost_item_quantity.assign_cost_item_quantity(file: ifcopenshell.file, cost_item: ifcopenshell.entity_instance, products: list[ifcopenshell.entity_instance], prop_name: str = '', formula: str = '', ifc_class: str = 'IfcQuantityLength') None¶
Adds a cost item quantity that is parametrically connected to a product
A cost item may have its subtotal calculated by multiplying a unit value by a quantity associated with the cost item. That quantity may be either manually specified or parametrically connected to a quantity on a product. This API function lets you create that parametric connection.
For example, you may wish to have a cost item linked to the “NetVolume” quantity on all IfcSlabs. Each quantity has a name which you can specify. If the quantity is updated in-place (which should occur for Native IFC applications) then the quantity for the cost item will automatically update as well. If the quantity is deleted and then re-added, then the parametric relationship is also lost.
This API also automatically assigns a control relationship between the cost item and the product, so it is not necessary to use ifcopenshell.api.control.assign_control.
If cost item has just 1 quantity and it’s IfcQuantityCount, API will assume that quantity is used for counting controlled objects and it will recalculate the quantity value at the end of the API call as long as the RelatedObjects are not IfcConstructionResource which do not count towards the cost item (they only provide value).
- Parameters:
cost_item – The IfcCostItem to assign parametric quantities to
products – The IfcObjects to assign parametric quantities to
prop_name – The name of the quantity. If this is not specified, then it is assumed that there is no calculated quantity, and the number of objects are counted instead.
formula – The string that contains the formula
ifc_class – The quantity class of the calculated value if the formula is specified. Can be [‘IfcQuantityCount’, ‘IfcQuantityNumber’, ‘IfcQuantityLength’, ‘IfcQuantityArea’, ‘IfcQuantityVolume’, ‘IfcQuantityWeight’, ‘IfcQuantityTime’]. Check ifcopenshell.util.unit.QUANTITY_CLASS for more info.
- Returns:
None
Example:
schedule = ifcopenshell.api.cost.add_cost_schedule(model) item = ifcopenshell.api.cost.add_cost_item(model, cost_schedule=schedule) # Let's imagine a unit cost of 5.0 per unit volume value = ifcopenshell.api.cost.add_cost_value(model, parent=item) ifcopenshell.api.cost.edit_cost_value(model, cost_value=value, attributes={"AppliedValue": 5.0}) slab = ifcopenshell.api.root.create_entity(model, ifc_class="IfcSlab") # Usually the quantity would be automatically calculated via a # graphical authoring application but let's assign a manual quantity # for now. qto = ifcopenshell.api.pset.add_qto(model, product=slab, name="Qto_SlabBaseQuantities") ifcopenshell.api.pset.edit_qto(model, qto=qto, properties={"NetVolume": 42.0}) # Now let's parametrically link the slab's quantity to the cost # item. If the slab is edited in the future and 42.0 changes, then # the updated value will also automatically be applied to the cost # item. ifcopenshell.api.cost.assign_cost_item_quantity(model, cost_item=item, products=[slab], prop_name="NetVolume") # Now let's use the formula in order to calculate the quantity value. # For example, let's say that a IfcWall has the reinfocement volume ratio # stored in the Pset_ConcreteElementGeneral.ReinforcementVolumeRatio # and of course it has also the gross volume stored in the # Qto_WallBaseQuantities.GrossVolume. So we can add an IfcQuantity that stores the # reinforcement volume calculated with reinfocement volume ratio * gross volume. ifcopenshell.api.cost.assign_cost_item_quantity(model, cost_item=item, products=[wall], formula="Pset_ConcreteElementGeneral.ReinforcementVolumeRatio * NetVolume" ifc_class="IfcQuantityVolume")
- ifcopenshell.api.cost.assign_cost_item_quantity.OPERATORS¶