mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.owner
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
@@ -72,15 +72,15 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam
|
||||
.. code:: python
|
||||
|
||||
# Let's imagine we have a new wall type.
|
||||
wall_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWallType")
|
||||
wall_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
|
||||
|
||||
# Note that this only creates and assigns an empty property set. We
|
||||
# still need to add properties into the property set. Having blank
|
||||
# property sets are invalid.
|
||||
pset = ifcopenshell.api.run("pset.add_pset", model, product=wall_type, name="Pset_WallCommon")
|
||||
pset = ifcopenshell.api.pset.add_pset(model, product=wall_type, name="Pset_WallCommon")
|
||||
|
||||
# Add a fire rating property standardised by buildingSMART.
|
||||
ifcopenshell.api.run("pset.edit_pset", model, pset=pset, properties={"FireRating": "2HR"})
|
||||
ifcopenshell.api.pset.edit_pset(model, pset=pset, properties={"FireRating": "2HR"})
|
||||
"""
|
||||
settings = {"product": product, "name": name}
|
||||
|
||||
@@ -93,7 +93,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam
|
||||
"IfcPropertySet",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"Name": settings["name"],
|
||||
}
|
||||
)
|
||||
@@ -101,7 +101,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam
|
||||
"IfcRelDefinesByProperties",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"RelatedObjects": [settings["product"]],
|
||||
"RelatingPropertyDefinition": pset,
|
||||
}
|
||||
@@ -116,7 +116,7 @@ def add_pset(file: ifcopenshell.file, product: ifcopenshell.entity_instance, nam
|
||||
"IfcPropertySet",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"Name": settings["name"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.owner
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
@@ -64,17 +64,17 @@ def add_qto(file: ifcopenshell.file, product: ifcopenshell.entity_instance, name
|
||||
.. code:: python
|
||||
|
||||
# Let's imagine we have a new wall.
|
||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
|
||||
# Note that this only creates and assigns an empty quantity set. We
|
||||
# still need to add quantities into the property set. Having blank
|
||||
# quantity sets are invalid.
|
||||
qto = ifcopenshell.api.run("pset.add_qto", model, product=wall_type, name="Qto_WallBaseQuantities")
|
||||
qto = ifcopenshell.api.pset.add_qto(model, product=wall_type, name="Qto_WallBaseQuantities")
|
||||
|
||||
# Add a side area property standardised by buildingSMART. This
|
||||
# allows quantity take-off to occur, even though no geometry has
|
||||
# even been modelled!
|
||||
ifcopenshell.api.run("pset.edit_qto", model, qto=qto, properties={"NetSideArea": 4.2})
|
||||
ifcopenshell.api.pset.edit_qto(model, qto=qto, properties={"NetSideArea": 4.2})
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
@@ -97,7 +97,7 @@ class Usecase:
|
||||
"IfcRelDefinesByProperties",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(self.file),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingPropertyDefinition": qto,
|
||||
}
|
||||
@@ -117,6 +117,6 @@ class Usecase:
|
||||
return self.file.create_entity(
|
||||
"IfcElementQuantity",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
|
||||
Name=self.settings["name"],
|
||||
)
|
||||
|
||||
@@ -90,10 +90,10 @@ def edit_pset(
|
||||
.. code:: python
|
||||
|
||||
# Let's imagine we have a new wall type.
|
||||
wall_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWallType")
|
||||
wall_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
|
||||
|
||||
# This is a standard buildingSMART property set.
|
||||
pset = ifcopenshell.api.run("pset.add_pset", model, product=wall_type, name="Pset_WallCommon")
|
||||
pset = ifcopenshell.api.pset.add_pset(model, product=wall_type, name="Pset_WallCommon")
|
||||
|
||||
# In this scenario, we don't specify any pset_template because it is
|
||||
# part of the built-in buildingSMART templates, and so the
|
||||
@@ -101,47 +101,47 @@ def edit_pset(
|
||||
# transmittance value will automatically be an
|
||||
# IfcThermalTransmittanceMeasure. Neither of these properties exist
|
||||
# yet, so they will be created.
|
||||
ifcopenshell.api.run("pset.edit_pset", model,
|
||||
ifcopenshell.api.pset.edit_pset(model,
|
||||
pset=pset, properties={"FireRating": "2HR", "ThermalTransmittance": 42.3})
|
||||
|
||||
# We can edit existing properties. In this case, "FireRating" is
|
||||
# edited from "2HR" to "1HR". Combustible is new, and will be added.
|
||||
# The existing "ThermalTransmittance" property will be left
|
||||
# unchanged.
|
||||
ifcopenshell.api.run("pset.edit_pset", model,
|
||||
ifcopenshell.api.pset.edit_pset(model,
|
||||
pset=pset, properties={"FireRating": "1HR", "Combustible": False})
|
||||
|
||||
# Setting to None will change the value but not delete the property.
|
||||
ifcopenshell.api.run("pset.edit_pset", model, pset=pset, properties={"Combustible": None})
|
||||
ifcopenshell.api.pset.edit_pset(model, pset=pset, properties={"Combustible": None})
|
||||
|
||||
# If you actually want to delete the property, enable purging.
|
||||
ifcopenshell.api.run("pset.edit_pset", model, pset=pset,
|
||||
ifcopenshell.api.pset.edit_pset(model, pset=pset,
|
||||
properties={"Combustible": None}, should_purge=True)
|
||||
|
||||
# What if we wanted to manage our own properties? Let's create our
|
||||
# own "Company Standard" property set templates. Notice how we
|
||||
# prefix our property set with "Foo_", if our company name was "Foo"
|
||||
# this would make sense.
|
||||
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="Foo_bar")
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="Foo_bar")
|
||||
|
||||
# Let's imagine we want all model authors to specify two properties,
|
||||
# one being a length measurement and another being a boolean.
|
||||
prop1 = ifcopenshell.api.run("pset_template.add_prop_template", model,
|
||||
prop1 = ifcopenshell.api.pset_template.add_prop_template(model,
|
||||
pset_template=template, name="DemoA", primary_measure_type="IfcLengthMeasure")
|
||||
prop2 = ifcopenshell.api.run("pset_template.add_prop_template", model,
|
||||
prop2 = ifcopenshell.api.pset_template.add_prop_template(model,
|
||||
pset_template=template, name="DemoB", primary_measure_type="IfcBoolean")
|
||||
|
||||
# Now we can use our property set template to add our properties,
|
||||
# and the data types will always match our template.
|
||||
pset = ifcopenshell.api.run("pset.add_pset", model, product=wall_type, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", model,
|
||||
pset = ifcopenshell.api.pset.add_pset(model, product=wall_type, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(model,
|
||||
pset=pset, properties={"DemoA": 42.3, "DemoB": True}, pset_template=template)
|
||||
|
||||
# Here's a third scenario where we want to add arbitrary properties
|
||||
# that are not standardised by anything, not even our own custom
|
||||
# templates.
|
||||
pset = ifcopenshell.api.run("pset.add_pset", model, product=wall_type, name="Custom_Pset")
|
||||
ifcopenshell.api.run("pset.edit_pset", model,
|
||||
pset = ifcopenshell.api.pset.add_pset(model, product=wall_type, name="Custom_Pset")
|
||||
ifcopenshell.api.pset.edit_pset(model,
|
||||
pset=pset, properties={
|
||||
# Basic Python data types are mapped to a sensible default
|
||||
"SomeLabel": "Foo",
|
||||
@@ -152,7 +152,7 @@ def edit_pset(
|
||||
|
||||
# Editing existing properties will retain their current data types
|
||||
# if possible. So this will still be a length measure.
|
||||
ifcopenshell.api.run("pset.edit_pset", model, pset=pset, properties={"ExplicitLength": 12.3})
|
||||
ifcopenshell.api.pset.edit_pset(model, pset=pset, properties={"ExplicitLength": 12.3})
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
|
||||
@@ -66,45 +66,45 @@ def edit_qto(
|
||||
.. code:: python
|
||||
|
||||
# Let's imagine we have a new wall type.
|
||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
|
||||
# This is a standard buildingSMART property set.
|
||||
qto = ifcopenshell.api.run("pset.add_qto", model, product=wall, name="Qto_WallBaseQuantities")
|
||||
qto = ifcopenshell.api.pset.add_qto(model, product=wall, name="Qto_WallBaseQuantities")
|
||||
|
||||
# In this scenario, we don't specify any pset_template because it is
|
||||
# part of the built-in buildingSMART templates, and so the Length
|
||||
# will automatically be an IfcLengthMeasure, and the NetVolume will
|
||||
# automatically be an IfcVolumeMeasure. Neither of these properties
|
||||
# exist yet, so they will be created.
|
||||
ifcopenshell.api.run("pset.edit_qto", model, qto=qto, properties={"Length": 12, "NetVolume": 7.2})
|
||||
ifcopenshell.api.pset.edit_qto(model, qto=qto, properties={"Length": 12, "NetVolume": 7.2})
|
||||
|
||||
# Setting to None will delete the quantity.
|
||||
ifcopenshell.api.run("pset.edit_qto", model, qto=qto, properties={"Length": None})
|
||||
ifcopenshell.api.pset.edit_qto(model, qto=qto, properties={"Length": None})
|
||||
|
||||
# What if we wanted to manage our own properties? Let's create our
|
||||
# own "Company Standard" property set templates. Notice how we
|
||||
# prefix our property set with "Foo_", if our company name was "Foo"
|
||||
# this would make sense. In this example, we say that our template
|
||||
# only applies to walls and is for quantities.
|
||||
template = ifcopenshell.api.run("pset_template.add_pset_template", model,
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model,
|
||||
name="Foo_Wall", template_type="QTO_OCCURRENCEDRIVEN", applicable_entity="IfcWall")
|
||||
|
||||
# Let's imagine we want all model authors to specify a length
|
||||
# measurement for the portion of a wall that is overhanging.
|
||||
prop = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
|
||||
prop = ifcopenshell.api.pset_template.add_prop_template(model, pset_template=template,
|
||||
name="OverhangLength", template_type="Q_LENGTH", primary_measure_type="IfcLengthMeasure")
|
||||
|
||||
# Now we can use our property set template to add our properties,
|
||||
# and the data types will always match our template.
|
||||
qto = ifcopenshell.api.run("pset.add_qto", model, product=wall, name="Foo_Wall")
|
||||
ifcopenshell.api.run("pset.edit_qto", model,
|
||||
qto = ifcopenshell.api.pset.add_qto(model, product=wall, name="Foo_Wall")
|
||||
ifcopenshell.api.pset.edit_qto(model,
|
||||
qto=qto, properties={"OverhangLength": 42.3}, pset_template=template)
|
||||
|
||||
# Here's a third scenario where we want to add arbitrary quantities
|
||||
# that are not standardised by anything, not even our own custom
|
||||
# templates.
|
||||
qto = ifcopenshell.api.run("pset.add_qto", model, product=wall, name="Custom_Qto")
|
||||
ifcopenshell.api.run("pset.edit_qto", model,
|
||||
qto = ifcopenshell.api.pset.add_qto(model, product=wall, name="Custom_Qto")
|
||||
ifcopenshell.api.pset.edit_qto(model,
|
||||
qto=qto, properties={
|
||||
"SomeLength": model.createIfcLengthMeasure(42.3),
|
||||
"SomeArea": model.createIfcAreaMeasure(21.0)
|
||||
@@ -112,7 +112,7 @@ def edit_qto(
|
||||
|
||||
# Editing existing quantities will retain their current data types
|
||||
# if possible. So this will still be a length measure.
|
||||
ifcopenshell.api.run("pset.edit_qto", model, qto=qto, properties={"SomeLength": 12.3})
|
||||
ifcopenshell.api.pset.edit_qto(model, qto=qto, properties={"SomeLength": 12.3})
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
|
||||
@@ -39,11 +39,11 @@ def remove_pset(
|
||||
.. code:: python
|
||||
|
||||
# Let's imagine we have a new wall type with a property set.
|
||||
wall_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWallType")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", model, product=wall_type, name="Pset_WallCommon")
|
||||
wall_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
|
||||
pset = ifcopenshell.api.pset.add_pset(model, product=wall_type, name="Pset_WallCommon")
|
||||
|
||||
# Remove it!
|
||||
ifcopenshell.api.run("pset.remove_pset", model, product=wall_type, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(model, product=wall_type, pset=pset)
|
||||
"""
|
||||
settings = {"product": product, "pset": pset}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user