ifcopenshell.api.cost

Submodules

Package Contents

ifcopenshell.api.cost.add_cost_item(file, cost_schedule=None, cost_item=None) None

Add a new cost item

A cost item represents a single line item in a cost schedule. Cost items may then be broken down into cost subitems.

Parameters:
  • cost_schedule (ifcopenshell.entity_instance) – If the cost item is to be added as a root or top level cost item to a cost schedule, the IfcCostSchedule may be specified. This is mutually exlclusive to the cost_item parameter.

  • cost_item (ifcopenshell.entity_instance) – If the cost item is to be added as a subitem to an existing cost item, the parent IfcCostItem may be specified. This is mutually exclusive to the cost_schedule parameter.

Returns:

The newly created IfcCostItem

Return type:

ifcopenshell.entity_instance

Example:

# The very first cost item must be in a cost schedule
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)

# You may add cost items as top level item in the schedule
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# Alternatively you may add them as subitems
item2 = ifcopenshell.api.run("cost.add_cost_item", model, cost_item=item1)
ifcopenshell.api.cost.add_cost_item_quantity(file, cost_item=None, ifc_class='IfcQuantityCount') None

Adds a new quantity associated with a cost item

Cost items calculate their subtotal by multiplying the sum of the cost item’s “values” by the sum of the cost item’s “quantities”. The quantities may be either parametrically linked to quantities measured on physical product, or manually specified.

The quantity must be of a particular type, common examples are:

  • IfcQuantityCount: to count the total occurrences of a product, useful for things like doors, windows, and furniture

  • IfcQuantityNumber: any other generic numeric quantity

  • IfcQuantityLength

  • IfcQuantityArea

  • IfcQuantityVolume

  • IfcQuantityWeight

  • IfcQuantityTime

A cost item must not mix quantities of different types.

If an IfcQuantityCount is used, then this API will automatically count all products that this cost item controls (see ifcopenshell.api.controls.assign_control) and prefill that quantity.

For all other quantity types, the quantity is left as zero and the user must either manually specify the quantity or parametrically link it using another API call.

Parameters:
  • cost_item (ifcopenshell.entity_instance) – The IfcCostItem to add the quantity to

  • ifc_class (str, optional) – The type of quantity to add

Returns:

The newly created quantity entity, chosen from the ifc_class parameter

Return type:

ifcopenshell.entity_instance

Example:

chair = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurniture")
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
ifcopenshell.api.run("control.assign_control", model,
    relating_control=cost_item, related_object=chair)

# Let's assume we want to count the amount of chairs to calculate our cost item
# Because this is an IfcQuantityCount the count will be automatically set to "1" chair
ifcopenshell.api.run("cost.add_cost_item_quantity", model,
    cost_item=item, ifc_class="IfcQuantityCount")
ifcopenshell.api.cost.add_cost_schedule(file, name=None, predefined_type='NOTDEFINED') None

Add a new cost schedule

A cost schedule is a group of cost items which typically represent a cost plan or breakdown of the project. This may be used as an estimate, bid, or actual cost.

Alternatively, a cost schedule may also represent a schedule of rates, which include cost items which capture unit rates for different elements or processes.

As such, creating a cost schedule is necessary prior to creating and managing any cost items.

Parameters:
  • name (str, optional) – The name of the cost schedule.

  • predefined_type (str, optional) – The predefined type of the cost schedule, chosen from a valid type in the IFC documentation for IfcCostScheduleTypeEnum

Returns:

The newly created IfcCostSchedule entity

Return type:

ifcopenshell.entity_instance

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
# Now that we have a cost schedule, we may add cost items to it
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
ifcopenshell.api.cost.add_cost_value(file, parent=None) None

Adds a new value or subvalue to a cost item

A cost item’s subtotal can be specified in two ways.

Option 1 is by simply manually specifying the subtotal value, which represents the full cost of that cost item. This option occurs when a cost item has no quantities associated with it.

Option 2 is by specifying a unit cost value of the cost item, which is then multiplied by the associated quantity of the cost item, to give us the subtotal. This option occurs when a cost item has quantities associated with it.

For either option 1 (full cost value) or option 2 (unit cost value), the cost value may be specified as a single number, or as a sum of subcomponents or formulas (e.g. multiplication by wastage factor, or adding taxes or other adjustments).

This function lets you add a single top level unit value to a cost item, or alternatively price subcomponents by using the “parent” parameter.

More advanced usage, which involves summing, subcategory-filtered costs, and formulas are possible but not yet documented.

Parameters:

parent (ifcopenshell.entity_instance) – A parent IfcCostItem, if specifying a price directly to a cost item, or a top-level price component. Alternatively, this can be set to a IfcCostValue, if specifying price subcomponents.

Returns:

The newly created IfcCostValue

Return type:

ifcopenshell.entity_instance

Example:

# We always need a schedule first prior to adding any cost items
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)

# Option 1: This cost item will have a full cost of 42.0
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 42.0})

# Option 2: This cost item will have a unit cost of 5.0 per unit
# area, multiplied by the quantity of area specified explicitly as
# 3.0, giving us a subtotal cost of 15.0.
item2 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item2)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})
quantity = ifcopenshell.api.run("cost.add_cost_item_quantity", model,
    cost_item=item2, ifc_class="IfcQuantityVolume")
ifcopenshell.api.run("cost.edit_cost_item_quantity", model,
    physical_quantity=quantity, "attributes": {"VolumeValue": 3.0})

# A cost value may also be specified in terms of the sum of its
# subcomponents. In this case, it's broken down into 2 subvalues.
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
subvalue1 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)
subvalue2 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)

# This specifies that the value is the sum of all subitems
# regardless of their cost category. The first subvalue is 2.0 and
# the second is 3.0, giving a total value of 5.0.
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value, attributes={"Category": "*"})
ifcopenshell.api.run("cost.edit_cost_value", model,
    cost_value=subvalue1, attributes={"AppliedValue": 2.0})
ifcopenshell.api.run("cost.edit_cost_value", model,
    cost_value=subvalue2, attributes={"AppliedValue": 3.0})
ifcopenshell.api.cost.assign_cost_item_quantity(file, cost_item=None, products=None, prop_name='') 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.

Parameters:
  • cost_item (ifcopenshell.entity_instance) – The IfcCostItem to assign parametric quantities to

  • products (list[ifcopenshell.entity_instance]) – The IfcObjects to assign parametric quantities to

  • prop_name (str, optional) – 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.

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# Let's imagine a unit cost of 5.0 per unit volume
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})

slab = ifcopenshell.api.run("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.run("pset.add_qto", model, product=slab, name="Qto_SlabBaseQuantities")
ifcopenshell.api.run("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.run("cost.assign_cost_item_quantity", model,
    cost_item=item, products=[slab], prop_name="NetVolume")
ifcopenshell.api.cost.assign_cost_value(file, cost_item=None, cost_rate=None) None

Assigns a cost value to a cost item from a schedule of rates

Instead of assigning cost values from scratch for each cost item in a cost schedule, the cost values may instead be assigned from a schedule of rates.

A schedule of rates is just another cost schedule which have cost values but no quantities. This API will allow you to “copy” the values from a cost item in the schedule of rates into another cost item in your own cost schedule. When the schedule of rates value is updated, then your cost item values will also be updated. You can think of the schedule of rates as a “template” to quickly populate your rates from.

Parameters:
Returns:

None

Return type:

None

Example:

# Let's create a schedule of rates with a single rate in it of 5.0
rate_tables = ifcopenshell.api.run("cost.add_cost_schedule", model,
    predefined_type="SCHEDULEOFRATES")
rate = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=rate)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})

# And this schedule will be for our actual cost plan / estimate / etc
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# Now the cost item has the same rate as the one from the schedule of rate's item
ifcopenshell.api.run("cost.assign_cost_value", model, cost_item=item, cost_rate=rate)
ifcopenshell.api.cost.calculate_cost_item_resource_value(file, cost_item=None) None

Calculates the total cost of all resources associated with a cost item

A cost item may have construction resources (e.g. equipment, material, etc) assigned to it. Construction resources may be assigned directly to the cost item, or assigned first to a task, and the task is then assigned to the cost item.

The cost of a resource is calculated by the total sum of all of its base costs. If no quantity is provided, that sum is considered to be the total cost. Otherwise, it is considered to be a unit cost, and is then multiplied by the resource quantity. The quantity is either stored as a base quantity (such as a volume) for a things like material resources, or as a duration as a daily rate for labour resources.

The final calculated cost is set as the cost item’s value. Any previously existing values are removed.

Parameters:

cost_item (ifccopenshell.entity_instance.entity_instance) – The IfcCostItem to calculate

Returns:

None

Return type:

None

Example:

# First, we need a cost schedule and item
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# Let's imagine we have our own formworking crew
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")

# ... and they need concrete
concrete = ifcopenshell.api.run("resource.add_resource", model,
    ifc_class="IfcConstructionMaterialResource", parent_resource=crew)
ifcopenshell.api.run("control.assign_control", model,
    relating_control=item, related_object=concrete)
# ... which has a unit price of 42.0 per m3
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=concrete)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 42.0})
# ... and a volume of 200m3
quantity = ifcopenshell.api.run("resource.add_resource_quantity", model,
    resource=concrete, ifc_class="IfcQuantityVolume")
ifcopenshell.api.run("resource.edit_resource_quantity", model,
    physical_quantity=quantity, "attributes": {"VolumeValue": 200.0})

# Let's say they also need some equipment
equipment = ifcopenshell.api.run("resource.add_resource", model,
    ifc_class="IfcConstructionEquipmentResource", parent_resource=crew)
ifcopenshell.api.run("control.assign_control", model,
    relating_control=item, related_object=equipment)
# ... with a fixed price of 50,000
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=concrete)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 42.0})

# (42 * 200) + 50000 = 58400 is our calculated cost
ifcopenshell.api.run("cost.calculate_cost_item_resource_value", model, cost_item=item)
ifcopenshell.api.cost.copy_cost_item(file, cost_item=None) None

Copies all cost items and related relationships

The following relationships are also duplicated:

  • The copy will have the same attributes and property sets as the original cost item

  • The copy will be assigned to the parent cost schedule

  • The copy will have duplicated nested cost items

Parameters:

cost_item (ifcopenshell.entity_instance) – The cost item to be duplicated

Returns:

The duplicated cost item or the list of duplicated cost items if the latter has children

Return type:

ifcopenshell.entity_instance or list of ifcopenshell.entity_instance

Example: .. code:: python

# We have a cost item cost_item = CostItem(name=”Design new feature”, deadline=”2023-03-01”)

# And now we have two duplicated_cost_item = project.duplicate_cost_item(cost_item)

ifcopenshell.api.cost.copy_cost_item_values(file, source=None, destination=None) None

Copies all cost values from one cost item to another

Any previously existing values will be removed. The entire value is copied, including all components and formulas. However they are not parametrically linked, so if one value changes, the other will not.

Parameters:
Returns:

None

Return type:

None

Example:

# Assume we have a schedule with multiple items in it
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
item2 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# One of the items has a value
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5000.0})

# Let's copy the value from one item to another
ifcopenshell.api.run("cost.copy_cost_item_values", model, source=item1, destination=item2)
ifcopenshell.api.cost.edit_cost_item(file, cost_item=None, attributes=None) None

Edits the attributes of an IfcCostItem

For more information about the attributes and data types of an IfcCostItem, consult the IFC documentation.

Parameters:
  • cost_item (ifcopenshell.entity_instance) – The IfcCostItem entity you want to edit

  • attributes (dict, optional) – a dictionary of attribute names and values.

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
ifcopenshell.api.run("cost.edit_cost_item", model, cost_item=item, attributes={"Name": "Foo"})
ifcopenshell.api.cost.edit_cost_item_quantity(file, physical_quantity=None, attributes=None) None

Edits the attributes of an IfcPhysicalQuantity

For more information about the attributes and data types of an IfcPhysicalQuantity, consult the IFC documentation.

Parameters:
  • physical_quantity (ifcopenshell.entity_instance) – The IfcPhysicalQuantity entity you want to edit

  • attributes (dict, optional) – a dictionary of attribute names and values.

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# This cost item will have a unit cost of 5 and a volume of 3
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})
quantity = ifcopenshell.api.run("cost.add_cost_item_quantity", model,
    cost_item=item, ifc_class="IfcQuantityVolume")
ifcopenshell.api.run("cost.edit_cost_item_quantity", model,
    physical_quantity=quantity, "attributes": {"VolumeValue": 3.0})
ifcopenshell.api.cost.edit_cost_schedule(file, cost_schedule=None, attributes=None) None

Edits the attributes of an IfcCostSchedule

For more information about the attributes and data types of an IfcCostSchedule, consult the IFC documentation.

Parameters:
  • cost_schedule (ifcopenshell.entity_instance) – The IfcCostSchedule entity you want to edit

  • attributes (dict, optional) – a dictionary of attribute names and values.

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
ifcopenshell.api.run("cost.edit_cost_schedule", model,
    cost_schedule=schedule, attributes={"Name": "Foo"})
ifcopenshell.api.cost.edit_cost_value(file, cost_value=None, attributes=None) None

Edits the attributes of an IfcCostValue

For more information about the attributes and data types of an IfcCostValue, consult the IFC documentation.

Parameters:
  • cost_value (ifcopenshell.entity_instance) – The IfcCostValue entity you want to edit

  • attributes (dict, optional) – a dictionary of attribute names and values.

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# This cost item will have a total cost of 42
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 42.0})
ifcopenshell.api.cost.edit_cost_value_formula(file, cost_value=None, formula=None) None

Sets a cost value based on a formula, similar to formulas in spreadsheets

Costs may be made up of many components (e.g. labour, material, waste factor, taxes, etc). This can be easily represented in the form of a formula similar thta would be used in spreadsheet applications.

For more information, see ifcopenshell.util.cost

Parameters:
  • cost_value (ifcopenshell.entity_instance) – The IfcCostValue to set the values of

  • formula (str) – The formula following the language of ifcopenshell.util.cost

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value_formula", model, cost_value=value,
    formula="5000 * 1.19")
ifcopenshell.api.cost.remove_cost_item(file, cost_item=None) None

Removes a cost item

All associated relationships with the cost item are also removed, however the related resources, products, and tasks themselves are retained.

Parameters:

cost_item (ifcopenshell.entity_instance) – The IfcCostItem entity you want to remove

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
ifcopenshell.api.run("cost.remove_cost_item", model, cost_item=item)
ifcopenshell.api.cost.remove_cost_item_quantity(file, cost_item=None, physical_quantity=None) None

Removes a quantity assigned to a cost item

If the quantity is part of a product (e.g. wall), then the quantity will still exist and merely the relationship to the cost item will be removed.

Parameters:
Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
quantity = ifcopenshell.api.run("cost.add_cost_item_quantity", model,
    cost_item=item, ifc_class="IfcQuantityVolume")
# Let's change our mind and delete it
ifcopenshell.api.run("cost.remove_cost_item", model,
    cost_item=item, physical_quantity=quantity)
ifcopenshell.api.cost.remove_cost_schedule(file, cost_schedule=None) None

Removes a cost schedule

All associated relationships with the cost schedule are also removed, including all cost items.

Parameters:

cost_schedule (ifcopenshell.entity_instance) – The IfcCostSchedule entity you want to remove

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
ifcopenshell.api.run("cost.remove_cost_schedule", model, cost_schedule=schedule)
ifcopenshell.api.cost.remove_cost_value(file, parent=None, cost_value=None) None

Removes a cost value

The cost value may be assigned either to a cost item, a construction resource, or another cost value (i.e. it is a subcomponent of a cost)

Parameters:
  • parent (ifcopenshell.entity_instance) – The IfcCostItem, IfcConstructionResource, or IfcCostValue that the IfcCostValue is assigned to.

  • cost_value – The IfcCostValue that you want to remove

Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# This cost item will have a unit cost of 5 and a volume of 3
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})

ifcopenshell.api.run("cost.remove_cost_value", model, parent=item, cost_value=value)
ifcopenshell.api.cost.unassign_cost_item_quantity(file, cost_item=None, products=None) None

Removes quantities of a cost item that are calculated on products

A cost item may have quantities that are parametrically calculated on physical products. This lets you remove those quantities. This means that any future changes in the physical product’s dimensions will not have any impact on the cost item.

Parameters:
Returns:

None

Return type:

None

Example:

schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)

# Let's imagine a unit cost of 5.0 per unit volume
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item)
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
    attributes={"AppliedValue": 5.0})

slab = ifcopenshell.api.run("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.run("pset.add_qto", model, product=slab, name="Qto_SlabBaseQuantities")
ifcopenshell.api.run("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.run("cost.assign_cost_item_quantity", model,
    cost_item=item, products=[slab], prop_name="NetVolume")

# Let's change our mind and remove the parametric connection
ifcopenshell.api.run("cost.unassign_cost_item_quantity", model,
    cost_item=item, products=[slab])