replace api.run with static methods

This commit is contained in:
Andrej
2025-06-09 10:59:22 +05:00
parent 02d359d0e6
commit 8b4683aef1
122 changed files with 1334 additions and 1370 deletions
+1 -2
View File
@@ -263,8 +263,7 @@ def get_application(ifc: ifcopenshell.file) -> ifcopenshell.entity_instance:
for element in ifc.by_type("IfcApplication"):
if element.ApplicationIdentifier == "Bonsai" and element.Version == version:
return element
return ifcopenshell.api.run(
"owner.add_application",
return ifcopenshell.api.owner.add_application(
ifc,
version=version,
application_full_name="Bonsai",
@@ -19,6 +19,7 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.util.element
import bonsai.tool as tool
import bonsai.core.aggregate as core
@@ -112,7 +113,7 @@ class BIM_OT_aggregate_unassign_object(bpy.types.Operator, tool.Ifc.Operator):
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Linked_Aggregate")
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
class BIM_OT_enable_editing_aggregate(bpy.types.Operator):
@@ -312,7 +313,7 @@ class BIM_OT_break_link_to_other_aggregates(bpy.types.Operator, tool.Ifc.Operato
for part in parts:
pset = ifcopenshell.util.element.get_pset(part, "BBIM_Linked_Aggregate")
pset = tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=part, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=part, pset=pset)
linked_aggregate_group = next(
r.RelatingGroup
@@ -385,7 +386,7 @@ class BIM_OT_disable_aggregate_mode(bpy.types.Operator):
def execute(self, context):
bpy.ops.object.select_all(action="DESELECT")
bonsai.core.aggregate.exit_aggregate_mode(tool.Aggregate)
core.exit_aggregate_mode(tool.Aggregate)
return {"FINISHED"}
@@ -404,12 +404,13 @@ class EditBoundaryAttributes(bpy.types.Operator, tool.Ifc.Operator):
assert obj
bprops = tool.Boundary.get_object_boundary_props(obj)
boundary = tool.Ifc.get_entity(obj)
assert boundary
attributes = dict()
for ifc_attribute, blender_property in EDITABLE_ATTRIBUTES.items():
obj = getattr(bprops, blender_property, None)
entity = tool.Ifc.get_entity(obj)
attributes[blender_property] = entity
ifcopenshell.api.run("boundary.edit_attributes", tool.Ifc.get(), entity=boundary, **attributes)
ifcopenshell.api.boundary.edit_attributes(tool.Ifc.get(), entity=boundary, **attributes)
bpy.ops.bim.disable_editing_boundary()
return {"FINISHED"}
@@ -19,6 +19,7 @@
import bpy
import bsdd
import bonsai.tool as tool
import ifcopenshell.api.pset
import ifcopenshell.util.element
from bonsai.core import bsdd as core
@@ -101,5 +102,5 @@ class AddBSDDProperties(bpy.types.Operator, tool.Ifc.Operator):
if pset := current_psets.get(pset_name, None):
pset = self.file.by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name=pset_name)
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties=properties)
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name=pset_name)
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties=properties)
@@ -20,6 +20,7 @@ import bpy
import json
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.api.classification
import ifcopenshell.util.classification
import ifcopenshell.util.element
@@ -47,8 +48,7 @@ class AddClassification(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
props = context.scene.BIMClassificationProperties
ifcopenshell.api.run(
"classification.add_classification",
ifcopenshell.api.classification.add_classification(
tool.Ifc.get(),
classification=IfcStore.classification_file.by_id(int(props.available_classifications)),
)
@@ -62,11 +62,9 @@ class AddManualClassification(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
props = context.scene.BIMClassificationProperties
attributes = bonsai.bim.helper.export_attributes(props.classification_attributes)
classification = ifcopenshell.api.run(
"classification.add_classification", tool.Ifc.get(), classification="Unnamed"
)
ifcopenshell.api.run(
"classification.edit_classification", tool.Ifc.get(), classification=classification, attributes=attributes
classification = ifcopenshell.api.classification.add_classification(tool.Ifc.get(), classification="Unnamed")
ifcopenshell.api.classification.edit_classification(
tool.Ifc.get(), classification=classification, attributes=attributes
)
props.is_adding = False
@@ -95,17 +93,14 @@ class AddManualClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
]
if products:
classification = tool.Ifc.get().by_id(int(props.classifications))
reference = ifcopenshell.api.run(
"classification.add_reference",
reference = ifcopenshell.api.classification.add_reference(
tool.Ifc.get(),
products=products,
classification=classification,
identification="X",
name="Unnamed",
)
ifcopenshell.api.run(
"classification.edit_reference", tool.Ifc.get(), reference=reference, attributes=attributes
)
ifcopenshell.api.classification.edit_reference(tool.Ifc.get(), reference=reference, attributes=attributes)
props.is_adding = False
@@ -133,8 +128,8 @@ class AddClassificationFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
has_classification = True
if has_classification:
continue
classification = ifcopenshell.api.run(
"classification.add_classification", tool.Ifc.get(), classification=dictionary["name"]
classification = ifcopenshell.api.classification.add_classification(
tool.Ifc.get(), classification=dictionary["name"]
)
classification.Source = dictionary["organizationNameOwner"]
classification.Edition = dictionary["version"]
@@ -239,8 +234,7 @@ class RemoveClassification(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
self.file = tool.Ifc.get()
ifcopenshell.api.run(
"classification.remove_classification",
ifcopenshell.api.classification.remove_classification(
tool.Ifc.get(),
classification=self.file.by_id(self.classification),
)
@@ -329,8 +323,7 @@ class RemoveClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
if elements_by_references:
for reference, products in elements_by_references.items():
ifcopenshell.api.run(
"classification.remove_reference",
ifcopenshell.api.classification.remove_reference(
tool.Ifc.get(),
reference=reference,
products=products,
@@ -385,8 +378,7 @@ class AddClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
if (ifc_definition_id := tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context))
]
if products:
ifcopenshell.api.run(
"classification.add_reference",
ifcopenshell.api.classification.add_reference(
tool.Ifc.get(),
reference=IfcStore.classification_file.by_id(self.reference),
products=products,
@@ -428,8 +420,8 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
break
if not classification:
classification = ifcopenshell.api.run(
"classification.add_classification", tool.Ifc.get(), classification=bsdd_classification.dictionary_name
classification = ifcopenshell.api.classification.add_classification(
tool.Ifc.get(), classification=bsdd_classification.dictionary_name
)
tool.Classification.set_location(classification, bsdd_classification.dictionary_namespace_uri)
@@ -438,8 +430,7 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
if not ifc_definition_id:
continue
element = tool.Ifc.get().by_id(ifc_definition_id)
reference = ifcopenshell.api.run(
"classification.add_reference",
reference = ifcopenshell.api.classification.add_reference(
tool.Ifc.get(),
products=[element],
classification=classification,
@@ -477,18 +468,16 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
elif is_pset:
pset = ifcopenshell.api.run(
"pset.add_pset", tool.Ifc.get(), product=element, name=classification_pset.name
pset = ifcopenshell.api.pset.add_pset(
tool.Ifc.get(), product=element, name=classification_pset.name
)
else:
pset = ifcopenshell.api.run(
"pset.add_qto", tool.Ifc.get(), product=element, name=classification_pset.name
)
pset = ifcopenshell.api.pset.add_qto(tool.Ifc.get(), product=element, name=classification_pset.name)
if is_pset:
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties=properties)
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties=properties)
else:
ifcopenshell.api.run("pset.edit_qto", tool.Ifc.get(), qto=pset, properties=properties)
ifcopenshell.api.pset.edit_qto(tool.Ifc.get(), qto=pset, properties=properties)
class ChangeClassificationLevel(bpy.types.Operator):
@@ -20,12 +20,11 @@
import bpy
import textwrap
import ifcopenshell.api
import ifcopenshell.api.nest
import bonsai.tool as tool
from bpy_extras.io_utils import ImportHelper, ExportHelper
import bonsai.tool as tool
import bonsai.core.cost as core
from pathlib import Path
from typing import get_args, TYPE_CHECKING, Literal
@@ -847,8 +846,7 @@ class ReorderCostItem(bpy.types.Operator, tool.Ifc.Operator):
cost_item: bpy.props.IntProperty()
def _execute(self, context):
ifcopenshell.api.run(
"nest.reorder_nesting",
ifcopenshell.api.nest.reorder_nesting(
tool.Ifc.get(),
**{
"item": tool.Ifc.get().by_id(self.cost_item),
@@ -312,6 +312,7 @@ class ImportIfcCsv(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
import ifccsv
props = tool.Blender.get_csv_props()
ifc_file: ifcopenshell.file
if props.should_load_from_memory:
ifc_file = tool.Ifc.get()
else:
@@ -24,6 +24,7 @@ import bmesh
import shapely
import ifcopenshell
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import bonsai.tool as tool
import bonsai.bim.module.drawing.helper as helper
@@ -24,6 +24,7 @@ import bmesh
import shutil
import hashlib
import shapely
import shapely.ops
import subprocess
import numpy as np
import multiprocessing
@@ -34,9 +35,10 @@ import ifcopenshell.api.pset
import ifcopenshell.api.style
import ifcopenshell.ifcopenshell_wrapper
import ifcopenshell.geom
import ifcopenshell.util.selector
import ifcopenshell.util.representation
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.selector
import ifcopenshell.util.unit
import bonsai.bim.helper
import bonsai.bim.handler
import bonsai.tool as tool
+4 -4
View File
@@ -119,8 +119,8 @@ def update_is_nts(self: "BIMCameraProperties", context: bpy.types.Context) -> No
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"IsNTS": self.is_nts})
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"IsNTS": self.is_nts})
def get_diagram_scales(self: "BIMCameraProperties", context: bpy.types.Context) -> list[tuple[str, str, str]]:
@@ -250,8 +250,8 @@ def update_layer(self: "BIMCameraProperties", context: bpy.types.Context, name:
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={name: value})
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={name: value})
def get_titleblocks(self, context):
@@ -22,6 +22,8 @@ import bpy
import string
import svgwrite
import openpyxl
import openpyxl.cell # Unnecessary, bug in typeshed.
import openpyxl.utils # Unnecessary, bug in typeshed.
import bonsai.tool as tool
from bonsai.bim.module.drawing.svgwriter import SvgWriter
@@ -26,6 +26,7 @@ from bpy.types import SplineBezierPoints, SplinePoints
import mathutils
import xml.etree.ElementTree as ET
import svgwrite
import svgwrite.container
import svgwrite.text
import ifcopenshell
import ifcopenshell.util.element
@@ -20,6 +20,7 @@
import os
import bpy
import ifcopenshell.util.element
import bonsai.core.geometry
import bonsai.core.type
import bonsai.core.drawing as core
import bonsai.tool as tool
@@ -22,6 +22,8 @@ import bmesh
import numpy as np
import numpy.typing as npt
import ifcopenshell
import ifcopenshell.api.group
import ifcopenshell.api.pset
import ifcopenshell.api.geometry
import ifcopenshell.api.layer
import ifcopenshell.api.material
@@ -754,10 +756,10 @@ class CopyRepresentation(bpy.types.Operator, tool.Ifc.Operator):
bm.to_mesh(obj.data)
old_rep = tool.Geometry.get_representation_by_context(element, geometric_context)
if old_rep:
ifcopenshell.api.run(
"geometry.unassign_representation", tool.Ifc.get(), product=element, representation=old_rep
ifcopenshell.api.geometry.unassign_representation(
tool.Ifc.get(), product=element, representation=old_rep
)
ifcopenshell.api.run("geometry.remove_representation", tool.Ifc.get(), representation=old_rep)
ifcopenshell.api.geometry.remove_representation(tool.Ifc.get(), representation=old_rep)
core.add_representation(
tool.Ifc,
tool.Geometry,
@@ -1183,10 +1185,9 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
pset = ifcopenshell.util.element.get_pset(part, self.pset_name)
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=part, name=self.pset_name)
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=part, name=self.pset_name)
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Index": index},
@@ -1208,8 +1209,8 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
if self.group_name in product_groups_name:
return
linked_aggregate_group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), name=self.group_name)
ifcopenshell.api.run("group.assign_group", tool.Ifc.get(), products=[element], group=linked_aggregate_group)
linked_aggregate_group = ifcopenshell.api.group.add_group(tool.Ifc.get(), name=self.group_name)
ifcopenshell.api.group.assign_group(tool.Ifc.get(), products=[element], group=linked_aggregate_group)
def custom_incremental_naming_for_element_assembly(old_to_new):
for new in old_to_new.values():
@@ -1247,12 +1248,9 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
for old, new in old_to_new.items():
pset = ifcopenshell.util.element.get_pset(old, "BBIM_Linked_Aggregate")
if pset:
new_pset = ifcopenshell.api.run(
"pset.add_pset", tool.Ifc.get(), product=new[0], name=self.pset_name
)
new_pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=new[0], name=self.pset_name)
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=new_pset,
properties={"Index": pset["Index"]},
@@ -2237,8 +2235,7 @@ class OverrideModeSetObject(bpy.types.Operator, tool.Ifc.Operator):
curves.append(profile.OuterCurve)
if profile.is_a("IfcArbitraryProfileDefWithVoids"):
curves.extend(profile.InnerCurves)
new_footprint = ifcopenshell.api.run(
"geometry.add_footprint_representation",
new_footprint = ifcopenshell.api.geometry.add_footprint_representation(
tool.Ifc.get(),
context=footprint_context,
curves=curves,
@@ -2253,8 +2250,7 @@ class OverrideModeSetObject(bpy.types.Operator, tool.Ifc.Operator):
tool.Ifc, tool.Geometry, obj=obj, representation=old_footprint
)
else:
ifcopenshell.api.run(
"geometry.assign_representation",
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(),
product=element,
representation=new_footprint,
@@ -19,7 +19,7 @@
import bpy
import ifcopenshell.api
import ifcopenshell.api.group
import ifcopenshell.util.attribute
import ifcopenshell.util.element
import bonsai.bim.helper
import bonsai.tool as tool
import json
@@ -108,10 +108,10 @@ class AddGroup(bpy.types.Operator, tool.Ifc.Operator):
group: bpy.props.IntProperty()
def _execute(self, context):
result = ifcopenshell.api.run("group.add_group", tool.Ifc.get())
result = ifcopenshell.api.group.add_group(tool.Ifc.get())
if self.group:
ifcopenshell.api.run(
"group.assign_group", tool.Ifc.get(), products=[result], group=tool.Ifc.get().by_id(self.group)
ifcopenshell.api.group.assign_group(
tool.Ifc.get(), products=[result], group=tool.Ifc.get().by_id(self.group)
)
bpy.ops.bim.load_groups()
return {"FINISHED"}
@@ -139,7 +139,7 @@ class RemoveGroup(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
self.file = tool.Ifc.get()
ifcopenshell.api.run("group.remove_group", self.file, **{"group": self.file.by_id(self.group)})
ifcopenshell.api.group.remove_group(self.file, **{"group": self.file.by_id(self.group)})
bpy.ops.bim.load_groups()
return {"FINISHED"}
@@ -23,6 +23,7 @@ import stat
from pathlib import Path
import importlib
import importlib.util
import pyradiance
@@ -34,6 +34,7 @@ import json
import math
import time
import ifcopenshell
import ifcopenshell.util.geolocation
import webbrowser
import ifcopenshell.geom
import multiprocessing
@@ -80,6 +81,7 @@ class ExportOBJ(bpy.types.Operator):
serializer_settings.set("use-element-guids", True)
settings.set("use-world-coords", True)
ifc_file: ifcopenshell.file
if should_load_from_memory:
ifc_file = tool.Ifc.get()
@@ -20,13 +20,12 @@ import bpy
import json
import ifcopenshell.api
import ifcopenshell.api.material
import ifcopenshell.api.profile
import ifcopenshell.api.style
import ifcopenshell.util.element
import ifcopenshell.util.attribute
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import bonsai.bim.helper
import bonsai.tool as tool
import bonsai.core.style
import bonsai.core.material as core
import bonsai.bim.module.model.profile as model_profile
from typing import Any, Union, TYPE_CHECKING
@@ -121,13 +120,11 @@ class AssignParameterizedProfile(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
self.file = tool.Ifc.get()
profile = ifcopenshell.api.run(
"profile.add_parameterized_profile",
profile = ifcopenshell.api.profile.add_parameterized_profile(
self.file,
**{"ifc_class": self.ifc_class},
)
ifcopenshell.api.run(
"material.assign_profile",
ifcopenshell.api.material.assign_profile(
self.file,
**{"material_profile": self.file.by_id(self.material_profile), "profile": profile},
)
@@ -472,8 +469,7 @@ class RemoveListItem(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
self.file = tool.Ifc.get()
ifcopenshell.api.run(
"material.remove_list_item",
ifcopenshell.api.material.remove_list_item(
self.file,
**{
"material_list": self.file.by_id(self.list_item_set),
@@ -683,7 +679,7 @@ class EditMaterialSetItemProfile(bpy.types.Operator, tool.Ifc.Operator):
self.props = tool.Material.get_object_material_props(obj)
attributes = bonsai.bim.helper.export_attributes(self.props.material_set_item_profile_attributes)
profile = tool.Ifc.get().by_id(self.material_set_item).Profile
ifcopenshell.api.run("profile.edit_profile", tool.Ifc.get(), profile=profile, attributes=attributes)
ifcopenshell.api.profile.edit_profile(tool.Ifc.get(), profile=profile, attributes=attributes)
self.props.active_material_set_item_id = 0
self.props.material_set_item_profile_attributes.clear()
model_profile.DumbProfileRegenerator().regenerate_from_profile_def(profile)
@@ -900,7 +896,7 @@ class EditMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
material = ifc_file.by_id(props.active_material_id)
style = ifc_file.by_id(int(props.styles))
context = ifc_file.by_id(int(props.contexts))
ifcopenshell.api.run("style.assign_material_style", ifc_file, material=material, style=style, context=context)
ifcopenshell.api.style.assign_material_style(ifc_file, material=material, style=style, context=context)
tool.Material.disable_editing_material()
core.load_materials(tool.Material, props.material_type)
# NOTE: Update all elements that has this material and
@@ -923,9 +919,7 @@ class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
material = tool.Ifc.get().by_id(props.materials[props.active_material_index].ifc_definition_id)
style = tool.Ifc.get().by_id(self.style)
context = tool.Ifc.get().by_id(self.context)
ifcopenshell.api.run(
"style.unassign_material_style", tool.Ifc.get(), material=material, style=style, context=context
)
ifcopenshell.api.style.unassign_material_style(tool.Ifc.get(), material=material, style=style, context=context)
core.load_materials(tool.Material, props.material_type)
tool.Material.update_elements_using_material(material)
+3 -3
View File
@@ -164,7 +164,7 @@ class EditArray(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Ifc.get().by_id(pset["id"])
data = tool.Ifc.get().createIfcText(json.dumps(data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": data})
tool.Blender.Modifier.Array.set_children_lock_state(element, self.item, True)
tool.Blender.Modifier.Array.constrain_children_to_parent(element)
@@ -228,11 +228,11 @@ class RemoveArray(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Ifc.get().by_id(pset["id"])
if len(data) == 1:
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
else:
del data[self.item]
data = tool.Ifc.get().createIfcText(json.dumps(data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": data})
tool.Blender.Modifier.Array.constrain_children_to_parent(element)
return {"FINISHED"}
+11 -13
View File
@@ -21,7 +21,9 @@ import bpy
import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.schema
@@ -37,6 +39,7 @@ from typing import Union, Any, Optional
import json
import collections
import collections.abc
V_ = tool.Blender.V_
@@ -80,9 +83,7 @@ def update_door_modifier_representation(obj: bpy.types.Object) -> None:
profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW")
if profile:
representation_data["context"] = profile
elevation_representation = ifcopenshell.api.run(
"geometry.add_door_representation", ifc_file, **representation_data
)
elevation_representation = ifcopenshell.api.geometry.add_door_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(profile, obj, elevation_representation)
# MODEL_VIEW representation
@@ -90,7 +91,7 @@ def update_door_modifier_representation(obj: bpy.types.Object) -> None:
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
representation_data["context"] = body
representation_data["part_of_product"] = ifcopenshell.util.representation.get_part_of_product(element, body)
model_representation = ifcopenshell.api.run("geometry.add_door_representation", ifc_file, **representation_data)
model_representation = ifcopenshell.api.geometry.add_door_representation(ifc_file, **representation_data)
representation_data["part_of_product"] = None
tool.Model.replace_object_ifc_representation(body, obj, model_representation)
if fallback_material := (int(props.lining_material) or int(props.framing_material) or int(props.glazing_material)):
@@ -113,7 +114,7 @@ def update_door_modifier_representation(obj: bpy.types.Object) -> None:
plan_body = ifcopenshell.util.representation.get_context(ifc_file, "Plan", "Body", "PLAN_VIEW")
if plan_body:
representation_data["context"] = plan_body
plan_representation = ifcopenshell.api.run("geometry.add_door_representation", ifc_file, **representation_data)
plan_representation = ifcopenshell.api.geometry.add_door_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(plan_body, obj, plan_representation)
# Annotation/PLAN_VIEW representation
@@ -134,9 +135,7 @@ def update_door_modifier_representation(obj: bpy.types.Object) -> None:
)
else:
representation_data["context"] = plan_annotation
plan_representation = ifcopenshell.api.run(
"geometry.add_door_representation", ifc_file, **representation_data
)
plan_representation = ifcopenshell.api.geometry.add_door_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(plan_annotation, obj, plan_representation)
bonsai.core.geometry.switch_representation(
@@ -539,10 +538,9 @@ class AddDoor(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Door")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Door")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(door_data, default=list))},
@@ -622,7 +620,7 @@ class FinishEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
door_data = tool.Ifc.get().createIfcText(json.dumps(door_data, default=list))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": door_data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": door_data})
def _execute(self, context):
for obj in tool.Blender.get_selected_objects():
@@ -670,7 +668,7 @@ class RemoveDoor(bpy.types.Operator, tool.Ifc.Operator):
props.is_editing = False
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
def _execute(self, context):
for obj in tool.Blender.get_selected_objects():
+17 -18
View File
@@ -19,15 +19,20 @@
import bpy
import math
import collections
import collections.abc
import bmesh
import re
import json
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.unit
import ifcopenshell.util.system
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.util.element
import ifcopenshell.util.placement
import ifcopenshell.util.representation
import ifcopenshell.util.system
import ifcopenshell.util.unit
import numpy as np
import bonsai.core.type
import bonsai.core.root
@@ -539,14 +544,10 @@ class MEPGenerator:
ifc_representation_class=None,
)
rel = ifcopenshell.api.run(
"material.assign_material", ifc_file, products=[element], type="IfcMaterialProfileSet"
)
rel = ifcopenshell.api.material.assign_material(ifc_file, products=[element], type="IfcMaterialProfileSet")
profile_set = rel.RelatingMaterial
material_profile = ifcopenshell.api.run(
"material.add_profile", ifc_file, profile_set=profile_set, material=material
)
ifcopenshell.api.run("material.assign_profile", ifc_file, material_profile=material_profile, profile=profile)
material_profile = ifcopenshell.api.material.add_profile(ifc_file, profile_set=profile_set, material=material)
ifcopenshell.api.material.assign_profile(ifc_file, material_profile=material_profile, profile=profile)
return element
def add_obstruction(self, segment, length, at_segment_start=False):
@@ -800,7 +801,7 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
f"Failed to add transition - transition length is larger the segments and the distance between them.\n"
+ f"Transition length: {full_transition_length:.2f}m, segments length: {entire_length:.2f}m",
)
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=rep)
ifcopenshell.api.geometry.remove_representation(ifc_file, representation=rep)
return {"CANCELLED"}
# calculate bunch of points to for adjustments
@@ -832,7 +833,7 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
start_port_match = fitting_data["start_port_match"] if fitting_data else True
if transition_type:
# TODO: handle the case without creating a representation in the first place?
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=rep)
ifcopenshell.api.geometry.remove_representation(ifc_file, representation=rep)
else: # create new fitting type if nothing is compatible
mesh = bpy.data.meshes.new("Transition")
obj = bpy.data.objects.new("Transition", mesh)
@@ -848,9 +849,8 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
# Will implicitly remove `mesh`.
tool.Model.replace_object_ifc_representation(body, obj, rep)
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=transition_type, name="BBIM_Fitting")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=transition_type, name="BBIM_Fitting")
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(transition_data, default=list))},
@@ -1183,7 +1183,7 @@ class MEPAddBend(bpy.types.Operator, tool.Ifc.Operator):
z_sign_type = -1 if bbim_data["flip_z_axis"] else 1
# TODO: handle the case without creating a representation in the first place?
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=rep)
ifcopenshell.api.geometry.remove_representation(ifc_file, representation=rep)
else: # create new fitting type if nothing is compatible
mesh = bpy.data.meshes.new("Bend")
obj = bpy.data.objects.new("Bend", mesh)
@@ -1199,9 +1199,8 @@ class MEPAddBend(bpy.types.Operator, tool.Ifc.Operator):
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
# Will implicitly remove `mesh`.
tool.Model.replace_object_ifc_representation(body, obj, rep)
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=bend_type, name="BBIM_Fitting")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=bend_type, name="BBIM_Fitting")
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(bend_data, default=list))},
+24 -27
View File
@@ -27,6 +27,7 @@ import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.feature
import ifcopenshell.api.root
import ifcopenshell.geom
import ifcopenshell.util.shape
import ifcopenshell.util.element
@@ -68,8 +69,8 @@ class FilledOpeningGenerator:
assert filling and element
if filling.FillsVoids:
ifcopenshell.api.run(
"feature.remove_feature", tool.Ifc.get(), feature=filling.FillsVoids[0].RelatingOpeningElement
ifcopenshell.api.feature.remove_feature(
tool.Ifc.get(), feature=filling.FillsVoids[0].RelatingOpeningElement
)
if target is None:
@@ -123,15 +124,13 @@ class FilledOpeningGenerator:
existing_opening_occurrence = self.get_existing_opening_occurrence_if_any(filling)
opening = ifcopenshell.api.run(
"root.create_entity",
opening = ifcopenshell.api.root.create_entity(
tool.Ifc.get(),
ifc_class="IfcOpeningElement",
predefined_type="OPENING",
name="Opening",
)
ifcopenshell.api.run(
"geometry.edit_object_placement",
ifcopenshell.api.geometry.edit_object_placement(
tool.Ifc.get(),
product=opening,
matrix=np.array(filling_obj.matrix_world),
@@ -149,15 +148,15 @@ class FilledOpeningGenerator:
filling, filling_obj, opening_thickness_si=opening_thickness_si
)
mapped_representation = ifcopenshell.api.run(
"geometry.map_representation", tool.Ifc.get(), representation=representation
mapped_representation = ifcopenshell.api.geometry.map_representation(
tool.Ifc.get(), representation=representation
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=opening, representation=mapped_representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=opening, representation=mapped_representation
)
ifcopenshell.api.run("feature.add_feature", tool.Ifc.get(), feature=opening, element=element)
ifcopenshell.api.run("feature.add_filling", tool.Ifc.get(), opening=opening, element=filling)
ifcopenshell.api.feature.add_feature(tool.Ifc.get(), feature=opening, element=element)
ifcopenshell.api.feature.add_filling(tool.Ifc.get(), opening=opening, element=filling)
voided_objs = [voided_obj]
# Openings affect all subelements of an aggregate
@@ -199,10 +198,8 @@ class FilledOpeningGenerator:
voided_element = opening.VoidsElements[0].RelatingBuildingElement
opening_rep = ifcopenshell.util.representation.get_representation(opening, "Model", "Body", "MODEL_VIEW")
ifcopenshell.api.run(
"geometry.unassign_representation", tool.Ifc.get(), product=opening, representation=opening_rep
)
ifcopenshell.api.run("geometry.remove_representation", tool.Ifc.get(), representation=opening_rep)
ifcopenshell.api.geometry.unassign_representation(tool.Ifc.get(), product=opening, representation=opening_rep)
ifcopenshell.api.geometry.remove_representation(tool.Ifc.get(), representation=opening_rep)
existing_opening_occurrence = self.get_existing_opening_occurrence_if_any(filling)
@@ -211,11 +208,11 @@ class FilledOpeningGenerator:
existing_opening_occurrence, "Model", "Body", "MODEL_VIEW"
)
representation = ifcopenshell.util.representation.resolve_representation(representation)
mapped_representation = ifcopenshell.api.run(
"geometry.map_representation", tool.Ifc.get(), representation=representation
mapped_representation = ifcopenshell.api.geometry.map_representation(
tool.Ifc.get(), representation=representation
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=opening, representation=mapped_representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=opening, representation=mapped_representation
)
else:
opening_obj = tool.Ifc.get_object(opening)
@@ -225,11 +222,11 @@ class FilledOpeningGenerator:
filling_obj = tool.Ifc.get_object(filling)
representation = self.generate_opening_from_filling(filling, filling_obj)
mapped_representation = ifcopenshell.api.run(
"geometry.map_representation", tool.Ifc.get(), representation=representation
mapped_representation = ifcopenshell.api.geometry.map_representation(
tool.Ifc.get(), representation=representation
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=opening, representation=mapped_representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=opening, representation=mapped_representation
)
# update voided object representation or all it's parts if it's an aggregate
@@ -396,8 +393,8 @@ class RecalculateFill(bpy.types.Operator, tool.Ifc.Operator):
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=building_obj)
for opening in openings:
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
ifcopenshell.api.run(
"geometry.edit_object_placement", tool.Ifc.get(), product=opening, matrix=obj.matrix_world
ifcopenshell.api.geometry.edit_object_placement(
tool.Ifc.get(), product=opening, matrix=obj.matrix_world
)
decomposed_building_elements = set()
@@ -737,7 +734,7 @@ class CloneOpening(Operator, tool.Ifc.Operator):
opening_placement = opening.ObjectPlacement
opening_representation = opening.Representation
new_opening = ifcopenshell.api.run("root.create_entity", tool.Ifc.get(), ifc_class="IfcOpeningElement")
new_opening = ifcopenshell.api.root.create_entity(tool.Ifc.get(), ifc_class="IfcOpeningElement")
new_opening.Representation = opening_representation
ifcopenshell.api.feature.add_feature(ifc_file, feature=new_opening, element=voided_element)
@@ -687,11 +687,8 @@ def generate_box(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[
new_settings = settings.copy()
new_settings["context"] = box_context
new_box = ifcopenshell.api.run(
"geometry.add_representation", ifc_file, should_run_listeners=False, **new_settings
)
ifcopenshell.api.run(
"geometry.assign_representation",
new_box = ifcopenshell.api.geometry.add_representation(ifc_file, should_run_listeners=False, **new_settings)
ifcopenshell.api.geometry.assign_representation(
ifc_file,
should_run_listeners=False,
**{"product": product, "representation": new_box},
+25 -38
View File
@@ -23,6 +23,8 @@ import mathutils.geometry
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.pset
import ifcopenshell.api.type
import ifcopenshell.util.type
import ifcopenshell.util.unit
import ifcopenshell.util.element
@@ -125,7 +127,7 @@ class DumbProfileGenerator:
ifc_class=ifc_class,
should_add_representation=False,
)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=self.relating_type)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=self.relating_type)
material = ifcopenshell.util.element.get_material(element)
material.CardinalPoint = self.cardinal_point
@@ -135,27 +137,23 @@ class DumbProfileGenerator:
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
if self.axis_context:
representation = ifcopenshell.api.run(
"geometry.add_axis_representation",
representation = ifcopenshell.api.geometry.add_axis_representation(
tool.Ifc.get(),
context=self.axis_context,
axis=[(0.0, 0.0, 0.0), (0.0, 0.0, self.depth)],
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=element, representation=representation
)
representation = ifcopenshell.api.run(
"geometry.add_profile_representation",
representation = ifcopenshell.api.geometry.add_profile_representation(
tool.Ifc.get(),
context=self.body_context,
profile=self.profile_set.CompositeProfile or self.profile_set.MaterialProfiles[0].Profile,
cardinal_point=self.cardinal_point,
depth=self.depth,
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
)
ifcopenshell.api.geometry.assign_representation(tool.Ifc.get(), product=element, representation=representation)
bonsai.core.geometry.switch_representation(
tool.Ifc,
tool.Geometry,
@@ -166,8 +164,8 @@ class DumbProfileGenerator:
should_sync_changes_first=False,
)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbProfile"})
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Engine": "Bonsai.DumbProfile"})
tool.Blender.select_object(obj)
@@ -323,8 +321,8 @@ class DumbProfileJoiner:
if not element1:
return
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type="ATSTART")
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type="ATEND")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type="ATSTART")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type="ATEND")
axis1 = self.get_profile_axis(profile1)
axis = copy.deepcopy(axis1)
@@ -347,7 +345,7 @@ class DumbProfileJoiner:
if connection is None:
connection = "ATEND" if connection_value > 0.5 else "ATSTART"
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type=connection)
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type=connection)
axis = copy.deepcopy(axis1)
body = copy.deepcopy(axis1)
@@ -360,7 +358,7 @@ class DumbProfileJoiner:
if not element1:
return
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type="ATEND")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type="ATEND")
axis1 = self.get_profile_axis(profile1)
axis = copy.deepcopy(axis1)
@@ -382,8 +380,7 @@ class DumbProfileJoiner:
return
connection = "ATEND" if tool.Cad.edge_percent(intersect, axis1) > 0.5 else "ATSTART"
ifcopenshell.api.run(
"geometry.connect_path",
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
related_element=element1,
relating_element=element2,
@@ -407,8 +404,7 @@ class DumbProfileJoiner:
profile1_end = "ATEND" if tool.Cad.edge_percent(intersect, axis1) > 0.5 else "ATSTART"
profile2_end = "ATEND" if tool.Cad.edge_percent(intersect, axis2) > 0.5 else "ATSTART"
ifcopenshell.api.run(
"geometry.connect_path",
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
relating_element=element1,
related_element=element2,
@@ -433,8 +429,7 @@ class DumbProfileJoiner:
profile1_end = "ATEND" if tool.Cad.edge_percent(intersect, axis1) > 0.5 else "ATSTART"
profile2_end = "ATEND" if tool.Cad.edge_percent(intersect, axis2) > 0.5 else "ATSTART"
ifcopenshell.api.run(
"geometry.connect_path",
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
relating_element=element1,
related_element=element2,
@@ -492,8 +487,8 @@ class DumbProfileJoiner:
if self.axis_context:
axis = [(new_matrix @ a) for a in self.axis]
new_axis = ifcopenshell.api.run(
"geometry.add_axis_representation", tool.Ifc.get(), context=self.axis_context, axis=axis
new_axis = ifcopenshell.api.geometry.add_axis_representation(
tool.Ifc.get(), context=self.axis_context, axis=axis
)
old_axis = ifcopenshell.util.representation.get_representation(element, "Model", "Axis", "GRAPH_VIEW")
if old_axis:
@@ -501,8 +496,8 @@ class DumbProfileJoiner:
ifcopenshell.util.element.replace_attribute(inverse, old_axis, new_axis)
bonsai.core.geometry.remove_representation(tool.Ifc, tool.Geometry, obj=obj, representation=old_axis)
else:
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=new_axis
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=element, representation=new_axis
)
def get_placement_axes(
@@ -537,9 +532,7 @@ class DumbProfileJoiner:
mesh.name = tool.Loader.get_mesh_name(new_body)
bonsai.core.geometry.remove_representation(tool.Ifc, tool.Geometry, obj=obj, representation=old_body)
else:
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=new_body
)
ifcopenshell.api.geometry.assign_representation(tool.Ifc.get(), product=element, representation=new_body)
previous_matrix = obj.matrix_world.copy()
previous_origin = obj.location.copy()
@@ -955,15 +948,9 @@ class Rotate90(bpy.types.Operator, tool.Ifc.Operator):
elif usage == "LAYER2":
layer2_objs.append(obj)
if element.ConnectedTo or element.ConnectedFrom:
ifcopenshell.api.run(
"geometry.disconnect_path", tool.Ifc.get(), element=element, connection_type="ATSTART"
)
ifcopenshell.api.run(
"geometry.disconnect_path", tool.Ifc.get(), element=element, connection_type="ATEND"
)
ifcopenshell.api.run(
"geometry.disconnect_path", tool.Ifc.get(), element=element, connection_type="ATPATH"
)
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element, connection_type="ATSTART")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element, connection_type="ATEND")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element, connection_type="ATPATH")
rotate_matrix = Matrix.Rotation(pi / 2, 4, self.axis)
obj.matrix_world @= rotate_matrix
bpy.context.view_layer.update()
@@ -21,6 +21,8 @@ import bpy
import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.pset
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import bonsai.core.root
@@ -71,10 +73,9 @@ def update_railing_modifier_ifc_data(context: bpy.types.Context) -> None:
# update pset
pset_common = tool.Pset.get_element_pset(element, "Pset_RailingCommon")
if not pset_common:
pset_common = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="Pset_RailingCommon")
pset_common = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name="Pset_RailingCommon")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
ifc_file,
pset=pset_common,
properties={
@@ -102,9 +103,7 @@ def update_railing_modifier_ifc_data(context: bpy.types.Context) -> None:
"height": props.height / si_conversion,
"looped_path": looped_path,
}
model_representation = ifcopenshell.api.run(
"geometry.add_railing_representation", ifc_file, **representation_data
)
model_representation = ifcopenshell.api.geometry.add_railing_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(body, obj, model_representation)
elif props.railing_type == "FRAMELESS_PANEL":
@@ -114,9 +113,9 @@ def update_railing_modifier_ifc_data(context: bpy.types.Context) -> None:
def update_bbim_railing_pset(element: ifcopenshell.entity_instance, railing_data: dict[str, Any]) -> None:
pset = tool.Pset.get_element_pset(element, "BBIM_Railing")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Railing")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Railing")
railing_data = tool.Ifc.get().createIfcText(json.dumps(railing_data, default=list))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": railing_data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": railing_data})
def update_railing_modifier_bmesh(context: bpy.types.Context) -> None:
@@ -598,5 +597,5 @@ class RemoveRailing(bpy.types.Operator, tool.Ifc.Operator):
props.is_editing = False
pset = tool.Pset.get_element_pset(element, "BBIM_Railing")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
return {"FINISHED"}
+4 -3
View File
@@ -21,6 +21,7 @@ import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import bonsai.core.root
@@ -440,9 +441,9 @@ def update_roof_modifier_ifc_data(context: bpy.types.Context) -> None:
def update_bbim_roof_pset(element: ifcopenshell.entity_instance, roof_data: dict[str, Any]) -> None:
pset = tool.Pset.get_element_pset(element, "BBIM_Roof")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Roof")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Roof")
roof_data = tool.Ifc.get().createIfcText(json.dumps(roof_data, default=list))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": roof_data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": roof_data})
def update_roof_modifier_bmesh(obj: bpy.types.Object) -> None:
@@ -831,7 +832,7 @@ class RemoveRoof(bpy.types.Operator, tool.Ifc.Operator):
assert element
pset = tool.Pset.get_element_pset(element, "BBIM_Roof")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
return {"FINISHED"}
+18 -21
View File
@@ -22,6 +22,9 @@ import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.api.type
import ifcopenshell.util.element
import ifcopenshell.util.placement
import ifcopenshell.util.representation
@@ -146,20 +149,17 @@ class DumbSlabGenerator:
ifc_class=ifc_class,
should_add_representation=False,
)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=self.relating_type)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=self.relating_type)
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
representation = ifcopenshell.api.run(
"geometry.add_slab_representation",
representation = ifcopenshell.api.geometry.add_slab_representation(
tool.Ifc.get(),
context=self.body_context,
depth=self.depth,
x_angle=self.x_angle,
polyline=self.polyline,
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
)
ifcopenshell.api.geometry.assign_representation(tool.Ifc.get(), product=element, representation=representation)
bonsai.core.geometry.switch_representation(
tool.Ifc,
@@ -178,18 +178,17 @@ class DumbSlabGenerator:
curves = [extrusion.SweptArea.OuterCurve]
if extrusion.SweptArea.is_a("IfcArbitraryProfileDefWithVoids"):
curves.extend(extrusion.SweptArea.InnerCurves)
representation = ifcopenshell.api.run(
"geometry.add_footprint_representation",
representation = ifcopenshell.api.geometry.add_footprint_representation(
tool.Ifc.get(),
context=self.footprint_context,
curves=curves,
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=element, representation=representation
)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer3"})
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer3"})
material = ifcopenshell.util.element.get_material(element)
material.LayerSetDirection = "AXIS3"
tool.Blender.select_object(obj)
@@ -562,9 +561,8 @@ class EditSketchExtrusionProfile(bpy.types.Operator, tool.Ifc.Operator):
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="EPset_Parametric")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Engine": "CADSketcher", "Entities": json.dumps(context.scene["sketcher"].to_dict())},
@@ -783,8 +781,8 @@ class EditExtrusionProfile(bpy.types.Operator, tool.Ifc.Operator):
curves = [profile.OuterCurve]
if profile.is_a("IfcArbitraryProfileDefWithVoids"):
curves.extend(profile.InnerCurves)
new_footprint = ifcopenshell.api.run(
"geometry.add_footprint_representation", tool.Ifc.get(), context=footprint_context, curves=curves
new_footprint = ifcopenshell.api.geometry.add_footprint_representation(
tool.Ifc.get(), context=footprint_context, curves=curves
)
old_footprint = ifcopenshell.util.representation.get_representation(element, "Plan", "FootPrint", "SKETCH_VIEW")
if old_footprint:
@@ -792,8 +790,8 @@ class EditExtrusionProfile(bpy.types.Operator, tool.Ifc.Operator):
ifcopenshell.util.element.replace_attribute(inverse, old_footprint, new_footprint)
bonsai.core.geometry.remove_representation(tool.Ifc, tool.Geometry, obj=obj, representation=old_footprint)
else:
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=new_footprint
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=element, representation=new_footprint
)
@@ -924,8 +922,7 @@ class DrawPolylineSlab(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
if not getattr(material_set_usage, "ForLayerSet", False):
return
attributes = {"OffsetFromReferenceLine": offset, "DirectionSense": direction_sense}
ifcopenshell.api.run(
"material.edit_layer_usage",
ifcopenshell.api.material.edit_layer_usage(
model,
**{"usage": material_set_usage, "attributes": attributes},
)
+7 -9
View File
@@ -20,7 +20,7 @@ import bpy
import json
import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.unit
@@ -98,10 +98,9 @@ def update_ifc_stair_props(obj: bpy.types.Object) -> None:
# update pset with ifc properties
pset_common = tool.Pset.get_element_pset(element, "Pset_StairFlightCommon")
if not pset_common:
pset_common = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="Pset_StairFlightCommon")
pset_common = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name="Pset_StairFlightCommon")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
ifc_file,
pset=pset_common,
properties={
@@ -192,10 +191,9 @@ class AddStair(bpy.types.Operator, tool.Ifc.Operator):
stair_data = props.get_props_kwargs(convert_to_project_units=True)
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="BBIM_Stair")
pset = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name="BBIM_Stair")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
ifc_file,
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(stair_data))},
@@ -250,7 +248,7 @@ class FinishEditingStair(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
data = tool.Ifc.get().createIfcText(json.dumps(data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": data})
# update IfcStairFlight properties
update_ifc_stair_props(obj)
@@ -288,6 +286,6 @@ class RemoveStair(bpy.types.Operator, tool.Ifc.Operator):
props.is_editing = False
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
return {"FINISHED"}
@@ -20,6 +20,8 @@ import bpy
import bmesh
import ifcopenshell
import ifcopenshell.api.pset
import ifcopenshell.util.element
import bonsai.tool as tool
import json
@@ -165,10 +167,9 @@ class UpdateDataFromSverchok(bpy.types.Operator, tool.Ifc.Operator):
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Sverchok")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Sverchok")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(sverchok_data))},
+4 -4
View File
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.util.date
@@ -30,11 +31,10 @@ def calculate_quantities(usecase_path, ifc_file, settings):
if not element.ScheduleDuration:
return
task = [e for e in ifc_file.get_inverse(element) if e.is_a("IfcTask")][0]
qto = ifcopenshell.api.run(
"pset.add_qto", ifc_file, should_run_listeners=False, product=task, name="Qto_TaskBaseQuantities"
qto = ifcopenshell.api.pset.add_qto(
ifc_file, should_run_listeners=False, product=task, name="Qto_TaskBaseQuantities"
)
ifcopenshell.api.run(
"pset.edit_qto",
ifcopenshell.api.pset.edit_qto(
ifc_file,
should_run_listeners=False,
qto=qto,
+23 -25
View File
@@ -24,6 +24,11 @@ import math
import numpy as np
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.feature
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.type
import ifcopenshell.api.geometry
import ifcopenshell.util.unit
import ifcopenshell.util.element
@@ -634,7 +639,7 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
material_set_usage = model.by_id(material.id())
# if material.is_a("IfcMaterialLayerSetUsage"):
attributes = {"OffsetFromReferenceLine": offset, "DirectionSense": direction_sense}
ifcopenshell.api.run("material.edit_layer_usage", model, usage=material_set_usage, attributes=attributes)
ifcopenshell.api.material.edit_layer_usage(model, usage=material_set_usage, attributes=attributes)
tool.Model.recalculate_walls([wall["obj"]])
if walls:
@@ -989,20 +994,18 @@ class DumbWallGenerator:
ifc_class=ifc_class,
should_add_representation=False,
)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=self.relating_type)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=self.relating_type)
if self.axis_context:
representation = ifcopenshell.api.run(
"geometry.add_axis_representation",
representation = ifcopenshell.api.geometry.add_axis_representation(
tool.Ifc.get(),
context=self.axis_context,
axis=[(0.0, 0.0), (self.length, 0.0)],
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(), product=element, representation=representation
)
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
representation = ifcopenshell.api.run(
"geometry.add_wall_representation",
representation = ifcopenshell.api.geometry.add_wall_representation(
tool.Ifc.get(),
context=self.body_context,
thickness=self.layers["thickness"],
@@ -1012,9 +1015,7 @@ class DumbWallGenerator:
height=self.height,
x_angle=self.x_angle,
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
)
ifcopenshell.api.geometry.assign_representation(tool.Ifc.get(), product=element, representation=representation)
bonsai.core.geometry.switch_representation(
tool.Ifc,
tool.Geometry,
@@ -1024,8 +1025,8 @@ class DumbWallGenerator:
is_global=True,
should_sync_changes_first=False,
)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer2"})
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer2"})
material = ifcopenshell.util.element.get_material(element)
material.LayerSetDirection = "AXIS2"
tool.Blender.select_object(obj)
@@ -1102,8 +1103,8 @@ class DumbWallJoiner:
if not element1:
return
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type="ATSTART")
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type="ATEND")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type="ATSTART")
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type="ATEND")
axis1 = tool.Model.get_wall_axis(wall1)
axis = copy.deepcopy(axis1["reference"])
@@ -1142,8 +1143,7 @@ class DumbWallJoiner:
description = conn.Description
if relating_element:
ifcopenshell.api.run(
"geometry.connect_path",
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
relating_element=relating_element,
related_element=element2,
@@ -1164,7 +1164,7 @@ class DumbWallJoiner:
_, opening_position = mathutils.geometry.intersect_point_line(opening_location.to_2d(), *axis1["reference"])
if opening_position > cut_percentage:
# The opening should be removed from element1.
ifcopenshell.api.run("feature.remove_feature", tool.Ifc.get(), feature=opening)
ifcopenshell.api.feature.remove_feature(tool.Ifc.get(), feature=opening)
# Now let's check element2.
for opening in [
@@ -1176,7 +1176,7 @@ class DumbWallJoiner:
_, opening_position = mathutils.geometry.intersect_point_line(opening_location.to_2d(), *axis1["reference"])
if opening_position < cut_percentage:
# The opening should be removed from element2.
ifcopenshell.api.run("feature.remove_feature", tool.Ifc.get(), feature=opening)
ifcopenshell.api.feature.remove_feature(tool.Ifc.get(), feature=opening)
# During the duplication process, filled voids are not copied. So we
# only need to check fillings on the original element1.
@@ -1202,7 +1202,7 @@ class DumbWallJoiner:
rel.RelatedBuildingElement = element2
# Remove the old opening
ifcopenshell.api.run("feature.remove_feature", tool.Ifc.get(), feature=opening)
ifcopenshell.api.feature.remove_feature(tool.Ifc.get(), feature=opening)
p1, p2 = ifcopenshell.util.representation.get_reference_line(element1)
p3 = (wall1.matrix_world.inverted() @ intersect.to_3d()).to_2d() / unit_scale
@@ -1308,15 +1308,13 @@ class DumbWallJoiner:
for rel in element1.ConnectedFrom:
if rel.is_a() == "IfcRelConnectsElements" and rel.Description == "TOP":
ifcopenshell.api.run(
"geometry.disconnect_element",
ifcopenshell.api.geometry.disconnect_element(
tool.Ifc.get(),
relating_element=rel.RelatingElement,
related_element=element1,
)
ifcopenshell.api.run(
"geometry.connect_element",
ifcopenshell.api.geometry.connect_element(
tool.Ifc.get(),
relating_element=element2,
related_element=element1,
@@ -1347,7 +1345,7 @@ class DumbWallJoiner:
if not connection:
connection = "ATEND" if intersection_point > 0.5 else "ATSTART"
ifcopenshell.api.run("geometry.disconnect_path", tool.Ifc.get(), element=element1, connection_type=connection)
ifcopenshell.api.geometry.disconnect_path(tool.Ifc.get(), element=element1, connection_type=connection)
if connection == "ATEND":
self.set_axis(element1, p1, intersect)
+9 -12
View File
@@ -23,6 +23,8 @@ import bmesh
import collections
import collections.abc
import ifcopenshell
import ifcopenshell.api.geometry
import ifcopenshell.api.pset
import bonsai.tool as tool
import bonsai.core.root
import bonsai.core.geometry
@@ -82,9 +84,7 @@ def update_window_modifier_representation(context: bpy.types.Context) -> None:
profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW")
if profile:
representation_data["context"] = profile
elevation_representation = ifcopenshell.api.run(
"geometry.add_window_representation", ifc_file, **representation_data
)
elevation_representation = ifcopenshell.api.geometry.add_window_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(profile, obj, elevation_representation)
# MODEL_VIEW representation
@@ -92,7 +92,7 @@ def update_window_modifier_representation(context: bpy.types.Context) -> None:
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
representation_data["context"] = body
representation_data["part_of_product"] = ifcopenshell.util.representation.get_part_of_product(element, body)
model_representation = ifcopenshell.api.run("geometry.add_window_representation", ifc_file, **representation_data)
model_representation = ifcopenshell.api.geometry.add_window_representation(ifc_file, **representation_data)
representation_data["part_of_product"] = None
tool.Model.replace_object_ifc_representation(body, obj, model_representation)
if fallback_material := (int(props.lining_material) or int(props.framing_material) or int(props.glazing_material)):
@@ -115,9 +115,7 @@ def update_window_modifier_representation(context: bpy.types.Context) -> None:
plan = ifcopenshell.util.representation.get_context(ifc_file, "Plan", "Body", "PLAN_VIEW")
if plan:
representation_data["context"] = plan
plan_representation = ifcopenshell.api.run(
"geometry.add_window_representation", ifc_file, **representation_data
)
plan_representation = ifcopenshell.api.geometry.add_window_representation(ifc_file, **representation_data)
tool.Model.replace_object_ifc_representation(plan, obj, plan_representation)
bonsai.core.geometry.switch_representation(
@@ -464,10 +462,9 @@ class AddWindow(bpy.types.Operator, tool.Ifc.Operator):
window_data["panel_properties"] = panel_props
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Window")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Window")
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": tool.Ifc.get().createIfcText(json.dumps(window_data, default=list))},
@@ -535,7 +532,7 @@ class FinishEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
window_data = tool.Ifc.get().createIfcText(json.dumps(window_data, default=list))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": window_data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": window_data})
return {"FINISHED"}
@@ -576,6 +573,6 @@ class RemoveWindow(bpy.types.Operator, tool.Ifc.Operator):
props.is_editing = False
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
return {"FINISHED"}
@@ -174,6 +174,7 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector, ImportHelper):
def _execute(self, context):
filepath = self.get_filepath()
ifc_file = tool.Ifc.get()
library_file: ifcopenshell.file
library_file = ifcopenshell.open(filepath)
if library_file.schema_identifier != ifc_file.schema_identifier:
self.report(
@@ -2158,8 +2159,7 @@ class AppendInspectedLinkedElement(AppendLibraryElement):
return {"CANCELLED"}
element_to_append = linked_ifc_file.by_guid(guid)
element = ifcopenshell.api.run(
"project.append_asset",
element = ifcopenshell.api.project.append_asset(
tool.Ifc.get(),
library=linked_ifc_file,
element=element_to_append,
+11 -13
View File
@@ -76,8 +76,8 @@ class DisablePsetEditing(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Ifc.get().by_id(props.active_pset_id)
ifc_definition_id = tool.Blender.get_obj_ifc_definition_id(self.obj, self.obj_type, context)
if tool.Pset.is_pset_empty(pset):
ifcopenshell.api.run(
"pset.remove_pset", tool.Ifc.get(), product=tool.Ifc.get().by_id(ifc_definition_id), pset=pset
ifcopenshell.api.pset.remove_pset(
tool.Ifc.get(), product=tool.Ifc.get().by_id(ifc_definition_id), pset=pset
)
props.active_pset_id = 0
props.active_pset_name = ""
@@ -104,10 +104,10 @@ class EditPset(bpy.types.Operator, tool.Ifc.Operator):
if pset_id:
pset = self.file.by_id(pset_id)
elif props.active_pset_type == "PSET":
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name=props.active_pset_name)
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name=props.active_pset_name)
props.active_pset_id = pset.id()
elif props.active_pset_type == "QTO":
pset = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name=props.active_pset_name)
pset = ifcopenshell.api.pset.add_qto(self.file, product=element, name=props.active_pset_name)
props.active_pset_id = pset.id()
if self.properties:
@@ -123,8 +123,7 @@ class EditPset(bpy.types.Operator, tool.Ifc.Operator):
]
if pset.is_a() in ("IfcPropertySet", "IfcMaterialProperties", "IfcProfileProperties"):
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
self.file,
pset=pset,
name=props.active_pset_name,
@@ -139,8 +138,7 @@ class EditPset(bpy.types.Operator, tool.Ifc.Operator):
properties[key] = round(value, 4)
elif not isinstance(value, int):
properties[key] = 0
ifcopenshell.api.run(
"pset.edit_qto",
ifcopenshell.api.pset.edit_qto(
self.file,
qto=pset,
name=props.active_pset_name,
@@ -175,8 +173,8 @@ class RemovePset(bpy.types.Operator, tool.Ifc.Operator):
element = tool.Ifc.get().by_id(ifc_definition_id)
pset = ifcopenshell.util.element.get_psets(element, should_inherit=False).get(pset_name, None)
if pset:
ifcopenshell.api.run(
"pset.remove_pset", tool.Ifc.get(), product=element, pset=tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.pset.remove_pset(
tool.Ifc.get(), product=element, pset=tool.Ifc.get().by_id(pset["id"])
)
@@ -364,9 +362,9 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator, tool.Ifc.Operator):
elif prop.template_type == "IfcPropertySingleValue":
value_ifc_entity = getattr(self.file, f"create{primary_measure_type}")(value)
new_pset = ifcopenshell.api.run("pset.add_pset", self.file, product=ifc_element, name=prop.pset_name)
ifcopenshell.api.run(
"pset.edit_pset", self.file, pset=new_pset, properties={prop.property_name: value_ifc_entity}
new_pset = ifcopenshell.api.pset.add_pset(self.file, product=ifc_element, name=prop.pset_name)
ifcopenshell.api.pset.edit_pset(
self.file, pset=new_pset, properties={prop.property_name: value_ifc_entity}
)
self.report({"INFO"}, "Finished applying changes")
return {"FINISHED"}
@@ -44,8 +44,8 @@ class AddPsetTemplateFile(bpy.types.Operator):
template = ifcopenshell.file()
filepath = (tool.Blender.get_data_dir_path("pset") / self.new_template_filename).with_suffix(".ifc").__str__()
pset_template = ifcopenshell.api.run("pset_template.add_pset_template", template)
ifcopenshell.api.run("pset_template.add_prop_template", template, pset_template=pset_template)
pset_template = ifcopenshell.api.pset_template.add_pset_template(template)
ifcopenshell.api.pset_template.add_prop_template(template, pset_template=pset_template)
template.write(filepath)
bonsai.bim.handler.refresh_ui_data()
bonsai.bim.schema.reload(tool.Ifc.get().schema)
@@ -82,8 +82,7 @@ class RemovePsetTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOpera
current_pset_template_id = int(props.pset_templates)
if props.active_pset_template_id == current_pset_template_id:
bpy.ops.bim.disable_editing_pset_template()
ifcopenshell.api.run(
"pset_template.remove_pset_template",
ifcopenshell.api.pset_template.remove_pset_template(
self.template_file,
**{"pset_template": self.template_file.by_id(current_pset_template_id)},
)
@@ -169,8 +168,7 @@ class EditPsetTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperato
def _execute(self, context):
props = tool.PsetTemplate.get_pset_template_props()
ifcopenshell.api.run(
"pset_template.edit_pset_template",
ifcopenshell.api.pset_template.edit_pset_template(
IfcStore.pset_template_file,
**{
"pset_template": IfcStore.pset_template_file.by_id(props.active_pset_template_id),
@@ -232,8 +230,7 @@ class AddPropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperator
def _execute(self, context):
props = tool.PsetTemplate.get_pset_template_props()
pset_template_id = props.active_pset_template_id or int(props.pset_templates)
prop_template = ifcopenshell.api.run(
"pset_template.add_prop_template",
prop_template = ifcopenshell.api.pset_template.add_prop_template(
IfcStore.pset_template_file,
pset_template=IfcStore.pset_template_file.by_id(pset_template_id),
)
@@ -251,8 +248,7 @@ class RemovePropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOpera
prop_template: bpy.props.IntProperty()
def _execute(self, context):
ifcopenshell.api.run(
"pset_template.remove_prop_template",
ifcopenshell.api.pset_template.remove_prop_template(
IfcStore.pset_template_file,
**{"prop_template": IfcStore.pset_template_file.by_id(self.prop_template)},
)
@@ -283,8 +279,7 @@ class EditPropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperato
if primary_measure_type == "-" or template_type.startswith("Q_"):
primary_measure_type = None
ifcopenshell.api.run(
"pset_template.edit_prop_template",
ifcopenshell.api.pset_template.edit_prop_template(
IfcStore.pset_template_file,
prop_template=IfcStore.pset_template_file.by_id(props.active_prop_template_id),
attributes={
+14 -14
View File
@@ -21,6 +21,8 @@ import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.util.schema
import ifcopenshell.util.element
@@ -599,27 +601,27 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
if materials:
material = materials[0] # Arbitrarily pick a material
else:
material = ifcopenshell.api.run("material.add_material", tool.Ifc.get(), name="Unknown")
rel = ifcopenshell.api.run(
"material.assign_material", tool.Ifc.get(), products=[element], type="IfcMaterialLayerSet"
material = ifcopenshell.api.material.add_material(tool.Ifc.get(), name="Unknown")
rel = ifcopenshell.api.material.assign_material(
tool.Ifc.get(), products=[element], type="IfcMaterialLayerSet"
)
layer_set = rel.RelatingMaterial
layer = ifcopenshell.api.run("material.add_layer", tool.Ifc.get(), layer_set=layer_set, material=material)
layer = ifcopenshell.api.material.add_layer(tool.Ifc.get(), layer_set=layer_set, material=material)
thickness = 0.1 # Arbitrary metric thickness for now
layer.LayerThickness = thickness / unit_scale
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="EPset_Parametric")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="EPset_Parametric")
if representation_template == "LAYERSET_AXIS2":
axis = "AXIS2"
elif representation_template == "LAYERSET_AXIS3":
axis = "AXIS3"
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"LayerSetDirection": axis})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"LayerSetDirection": axis})
elif representation_template == "PROFILESET" or representation_template.startswith("FLOW_SEGMENT_"):
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
materials = tool.Ifc.get().by_type("IfcMaterial")
if materials:
material = materials[0] # Arbitrarily pick a material
else:
material = ifcopenshell.api.run("material.add_material", tool.Ifc.get(), name="Unknown")
material = ifcopenshell.api.material.add_material(tool.Ifc.get(), name="Unknown")
if representation_template == "PROFILESET":
profile_id = tool.Blender.get_enum_safe(props, "profile")
if profile_id in ("-", None):
@@ -670,16 +672,14 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
WallThickness=default_thickness,
)
rel = ifcopenshell.api.run(
"material.assign_material", tool.Ifc.get(), products=[element], type="IfcMaterialProfileSet"
rel = ifcopenshell.api.material.assign_material(
tool.Ifc.get(), products=[element], type="IfcMaterialProfileSet"
)
profile_set = rel.RelatingMaterial
material_profile = ifcopenshell.api.run(
"material.add_profile", tool.Ifc.get(), profile_set=profile_set, material=material
)
ifcopenshell.api.run(
"material.assign_profile", tool.Ifc.get(), material_profile=material_profile, profile=profile
material_profile = ifcopenshell.api.material.add_profile(
tool.Ifc.get(), profile_set=profile_set, material=material
)
ifcopenshell.api.material.assign_profile(tool.Ifc.get(), material_profile=material_profile, profile=profile)
elif representation_template == "WINDOW":
with context.temp_override(active_object=obj, selected_objects=[]):
bpy.ops.bim.add_window()
@@ -21,7 +21,7 @@ import json
import bisect
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.guid
import ifcopenshell.api.group
import ifcopenshell.util.element
import ifcopenshell.util.selector
import bonsai.tool as tool
@@ -201,9 +201,9 @@ class SaveSearch(Operator, tool.Ifc.Operator):
group = group[0]
group.Description = description
else:
group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), name=self.name, description=description)
group = ifcopenshell.api.group.add_group(tool.Ifc.get(), name=self.name, description=description)
if results:
ifcopenshell.api.run("group.assign_group", tool.Ifc.get(), products=list(results), group=group)
ifcopenshell.api.group.assign_group(tool.Ifc.get(), products=list(results), group=group)
def draw(self, context):
row = self.layout.row()
@@ -447,7 +447,7 @@ class SaveColourscheme(Operator, tool.Ifc.Operator):
group.Description = json.dumps(description)
else:
description = json.dumps({"type": "BBIM_Search", "colourscheme": colourscheme, "colourscheme_query": query})
group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), name=self.name, description=description)
group = ifcopenshell.api.group.add_group(tool.Ifc.get(), name=self.name, description=description)
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
@@ -20,6 +20,7 @@ import bpy
import json
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.group
import ifcopenshell.api.structural
import ifcopenshell.util.attribute
@@ -136,7 +137,7 @@ class RemoveStructuralConnectionCondition(bpy.types.Operator, tool.Ifc.Operator)
file = tool.Ifc.get()
relation = file.by_id(self.connects_structural_member)
connection = relation.RelatedStructuralConnection
ifcopenshell.api.run("structural.remove_structural_connection_condition", file, **{"relation": relation})
ifcopenshell.api.structural.remove_structural_connection_condition(file, **{"relation": relation})
return {"FINISHED"}
@@ -149,7 +150,7 @@ class AddStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
file = tool.Ifc.get()
connection = file.by_id(self.connection)
ifcopenshell.api.run("structural.add_structural_boundary_condition", file, **{"connection": connection})
ifcopenshell.api.structural.add_structural_boundary_condition(file, **{"connection": connection})
return {"FINISHED"}
@@ -162,7 +163,7 @@ class RemoveStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
file = tool.Ifc.get()
connection = file.by_id(self.connection)
ifcopenshell.api.run("structural.remove_structural_boundary_condition", file, **{"connection": connection})
ifcopenshell.api.structural.remove_structural_boundary_condition(file, **{"connection": connection})
return {"FINISHED"}
@@ -233,8 +234,8 @@ class EditStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator):
else:
attributes[attribute.name] = {"value": attribute.float_value, "type": attribute.enum_value}
ifcopenshell.api.run(
"structural.edit_structural_boundary_condition", file, **{"condition": condition, "attributes": attributes}
ifcopenshell.api.structural.edit_structural_boundary_condition(
file, **{"condition": condition, "attributes": attributes}
)
bpy.ops.bim.disable_editing_structural_boundary_condition()
return {"FINISHED"}
@@ -425,8 +426,7 @@ class EditStructuralItemAxis(bpy.types.Operator, tool.Ifc.Operator):
relative_matrix = props.axis_empty.matrix_world @ obj.matrix_world.inverted()
z_axis = relative_matrix.col[2][0:3]
self.file = tool.Ifc.get()
ifcopenshell.api.run(
"structural.edit_structural_item_axis",
ifcopenshell.api.structural.edit_structural_item_axis(
self.file,
structural_item=self.file.by_id(oprops.ifc_definition_id),
axis=z_axis,
@@ -536,8 +536,7 @@ class AssignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
self.file = tool.Ifc.get()
ifcopenshell.api.run(
"aggregate.assign_object",
ifcopenshell.api.aggregate.assign_object(
self.file,
**{
"relating_object": self.file.by_id(self.work_plan),
@@ -555,8 +554,7 @@ class UnassignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
self.file = tool.Ifc.get()
ifcopenshell.api.run(
"aggregate.unassign_object",
ifcopenshell.api.aggregate.unassign_object(
self.file,
**{
"relating_object": self.file.by_id(self.work_plan),
@@ -572,7 +570,7 @@ class AddStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator):
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
ifcopenshell.api.run("structural.add_structural_load_case", tool.Ifc.get())
ifcopenshell.api.structural.add_structural_load_case(tool.Ifc.get())
return {"FINISHED"}
@@ -799,8 +797,8 @@ class AddStructuralLoad(bpy.types.Operator, tool.Ifc.Operator):
ifc_class: bpy.props.StringProperty()
def _execute(self, context):
result = ifcopenshell.api.run(
"structural.add_structural_load", tool.Ifc.get(), name="New Load", ifc_class=self.ifc_class
result = ifcopenshell.api.structural.add_structural_load(
tool.Ifc.get(), name="New Load", ifc_class=self.ifc_class
)
bpy.ops.bim.load_structural_loads()
bpy.ops.bim.enable_editing_structural_load(structural_load=result.id())
+6 -12
View File
@@ -812,16 +812,14 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
assert self.surface_style
if self.surface_style.is_a() == "IfcSurfaceStyleShading":
ifcopenshell.api.run(
"style.edit_surface_style",
ifcopenshell.api.style.edit_surface_style(
tool.Ifc.get(),
style=self.surface_style,
attributes=self.get_shading_attributes(),
)
tool.Loader.create_surface_style_shading(material, self.surface_style)
elif self.surface_style.is_a() == "IfcSurfaceStyleRendering":
ifcopenshell.api.run(
"style.edit_surface_style",
ifcopenshell.api.style.edit_surface_style(
tool.Ifc.get(),
style=self.surface_style,
attributes=self.get_rendering_attributes(),
@@ -858,8 +856,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
else:
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
assert attributes
ifcopenshell.api.run(
"style.edit_surface_style",
ifcopenshell.api.style.edit_surface_style(
tool.Ifc.get(),
style=self.surface_style,
attributes=bonsai.bim.helper.export_attributes(attributes),
@@ -868,8 +865,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
def add_new_style(self) -> None:
material = tool.Ifc.get_object(self.style)
if self.props.is_editing_class == "IfcSurfaceStyleShading":
surface_style = ifcopenshell.api.run(
"style.add_surface_style",
surface_style = ifcopenshell.api.style.add_surface_style(
tool.Ifc.get(),
style=self.style,
ifc_class="IfcSurfaceStyleShading",
@@ -877,8 +873,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
)
tool.Loader.create_surface_style_shading(material, surface_style)
elif self.props.is_editing_class == "IfcSurfaceStyleRendering":
surface_style = ifcopenshell.api.run(
"style.add_surface_style",
surface_style = ifcopenshell.api.style.add_surface_style(
tool.Ifc.get(),
style=self.style,
ifc_class="IfcSurfaceStyleRendering",
@@ -901,8 +896,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
tool.Loader.create_surface_style_with_textures(material, self.rendering_style, texture_style)
else:
attributes = tool.Style.get_style_ui_props_attributes(self.props.is_editing_class)
surface_style = ifcopenshell.api.run(
"style.add_surface_style",
surface_style = ifcopenshell.api.style.add_surface_style(
tool.Ifc.get(),
style=self.style,
ifc_class=self.props.is_editing_class,
@@ -18,6 +18,7 @@
import bpy
import ifcopenshell.api
import ifcopenshell.api.system
import ifcopenshell.util.system
import bonsai.tool as tool
import bonsai.core.system as core
@@ -406,7 +407,7 @@ class AddZone(bpy.types.Operator, tool.Ifc.Operator):
row.prop(self, "name", text="Name")
def _execute(self, context):
element = ifcopenshell.api.run("system.add_system", tool.Ifc.get(), ifc_class="IfcZone")
element = ifcopenshell.api.system.add_system(tool.Ifc.get(), ifc_class="IfcZone")
if self.name:
element.Name = self.name
bpy.ops.bim.load_zones()
@@ -446,7 +447,7 @@ class EditZone(bpy.types.Operator, tool.Ifc.Operator):
props = tool.System.get_zone_props()
zone = tool.Ifc.get().by_id(props.is_editing)
attributes = bonsai.bim.helper.export_attributes(props.attributes)
ifcopenshell.api.run("system.edit_system", tool.Ifc.get(), system=zone, attributes=attributes)
ifcopenshell.api.system.edit_system(tool.Ifc.get(), system=zone, attributes=attributes)
props.is_editing = 0
bpy.ops.bim.load_zones()
@@ -458,7 +459,7 @@ class RemoveZone(bpy.types.Operator, tool.Ifc.Operator):
zone: bpy.props.IntProperty()
def _execute(self, context):
ifcopenshell.api.run("system.remove_system", tool.Ifc.get(), system=tool.Ifc.get().by_id(self.zone))
ifcopenshell.api.system.remove_system(tool.Ifc.get(), system=tool.Ifc.get().by_id(self.zone))
bpy.ops.bim.load_zones()
@@ -18,6 +18,7 @@
import bpy
import ifcopenshell.api
import ifcopenshell.api.feature
import ifcopenshell.util.element
import ifcopenshell.util.representation
import bonsai.tool as tool
@@ -110,7 +111,7 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator):
should_add_representation=True,
context=body_context,
)
ifcopenshell.api.run("feature.add_feature", tool.Ifc.get(), feature=element2, element=element1)
ifcopenshell.api.feature.add_feature(tool.Ifc.get(), feature=element2, element=element1)
if tool.Ifc.is_moved(obj2):
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj2)
@@ -180,7 +181,7 @@ class RemoveOpening(bpy.types.Operator, tool.Ifc.Operator):
opening_obj.name = "/".join(opening_obj.name.split("/")[1:])
tool.Ifc.unlink(element=opening)
ifcopenshell.api.run("feature.remove_feature", tool.Ifc.get(), feature=opening)
ifcopenshell.api.feature.remove_feature(tool.Ifc.get(), feature=opening)
decomposed_building_elements = {element}
decomposed_building_elements.update(tool.Aggregate.get_parts_recursively(element))
@@ -221,8 +222,8 @@ class AddFilling(bpy.types.Operator, tool.Ifc.Operator):
opening_id = tool.Blender.get_object_bim_props(opening).ifc_definition_id
if not element_id or not opening_id or element_id == opening_id:
return {"FINISHED"}
ifcopenshell.api.run(
"feature.add_filling", self.file, opening=self.file.by_id(opening_id), element=self.file.by_id(element_id)
ifcopenshell.api.feature.add_filling(
self.file, opening=self.file.by_id(opening_id), element=self.file.by_id(element_id)
)
return {"FINISHED"}
@@ -237,7 +238,7 @@ class RemoveFilling(bpy.types.Operator, tool.Ifc.Operator):
filling = tool.Ifc.get().by_id(self.filling)
for rel in filling.FillsVoids:
bpy.ops.bim.remove_opening(opening_id=rel.RelatingOpeningElement.id())
ifcopenshell.api.run("feature.remove_filling", tool.Ifc.get(), element=filling)
ifcopenshell.api.feature.remove_filling(tool.Ifc.get(), element=filling)
return {"FINISHED"}
+1
View File
@@ -823,6 +823,7 @@ class ReloadIfcFile(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
import ifcdiff
old = tool.Ifc.get()
new: ifcopenshell.file
new = ifcopenshell.open(self.filepath)
ifc_diff = ifcdiff.IfcDiff(old, new, relationships=[])
+4 -2
View File
@@ -21,6 +21,8 @@ import bpy
import bonsai.core.tool
import bonsai.tool as tool
import ifcopenshell.api
import ifcopenshell.api.cost
import ifcopenshell.api.nest
import ifcopenshell.util.element
import ifcopenshell.util.date
import ifcopenshell.util.cost
@@ -627,7 +629,7 @@ class Cost(bonsai.core.tool.Cost):
items = ifcopenshell.util.cost.get_root_cost_items(cost_schedule)
for item in items:
cost_item_id = item.id()
ifcopenshell.api.run("cost.remove_cost_item", tool.Ifc.get(), cost_item=item)
ifcopenshell.api.cost.remove_cost_item(tool.Ifc.get(), cost_item=item)
tool.Cost.clean_up_cost_item_tree(cost_item_id)
@classmethod
@@ -901,7 +903,7 @@ class Cost(bonsai.core.tool.Cost):
def change_parent_cost_item(
cls, cost_item: ifcopenshell.entity_instance, new_parent: ifcopenshell.entity_instance
) -> None:
ifcopenshell.api.run("nest.change_nest", tool.Ifc.get(), item=cost_item, new_parent=new_parent)
ifcopenshell.api.nest.change_nest(tool.Ifc.get(), item=cost_item, new_parent=new_parent)
@classmethod
def disable_editing_cost_item_parent(cls) -> None:
+8 -7
View File
@@ -38,7 +38,10 @@ import bonsai.core.geometry
import bonsai.core.type
import bonsai.tool as tool
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.document
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.geom
import ifcopenshell.util.representation
import ifcopenshell.util.element
@@ -376,7 +379,7 @@ class Drawing(bonsai.core.tool.Drawing):
def delete_drawing_elements(cls, elements: Iterable[ifcopenshell.entity_instance]) -> None:
for element in elements:
obj = tool.Ifc.get_object(element)
ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element)
ifcopenshell.api.root.remove_product(tool.Ifc.get(), product=element)
if obj:
obj_data = obj.data
bpy.data.objects.remove(obj)
@@ -1187,9 +1190,8 @@ class Drawing(bonsai.core.tool.Drawing):
ifc_file = tool.Ifc.get()
pset = tool.Pset.get_element_pset(element, "EPset_Annotation")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="EPset_Annotation")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name="EPset_Annotation")
ifcopenshell.api.pset.edit_pset(
ifc_file,
pset=pset,
properties={"Classes": classes},
@@ -1203,9 +1205,8 @@ class Drawing(bonsai.core.tool.Drawing):
ifc_file = tool.Ifc.get()
pset = tool.Pset.get_element_pset(element, "EPset_Annotation")
if not pset:
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="EPset_Annotation")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name="EPset_Annotation")
ifcopenshell.api.pset.edit_pset(
ifc_file,
pset=pset,
properties={"Newline_At": newline_at},
+2 -3
View File
@@ -23,6 +23,7 @@ import bonsai.tool as tool
import bonsai.bim.helper
import bonsai.core.geometry
import ifcopenshell
import ifcopenshell.api.feature
import ifcopenshell.util.representation
from typing import TYPE_CHECKING
from collections.abc import Iterable
@@ -57,9 +58,7 @@ class Feature(bonsai.core.tool.Feature):
element_had_openings = tool.Geometry.has_openings(featured_element)
body_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body")
ifcopenshell.api.run(
"feature.add_feature", tool.Ifc.get(), feature=feature_element, element=featured_element
)
ifcopenshell.api.feature.add_feature(tool.Ifc.get(), feature=feature_element, element=featured_element)
if tool.Ifc.is_moved(feature_obj):
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=feature_obj)
+2 -1
View File
@@ -31,6 +31,7 @@ import ifcopenshell.api.boundary
import ifcopenshell.api.geometry
import ifcopenshell.api.grid
import ifcopenshell.api.profile
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.geom
@@ -2250,7 +2251,7 @@ class Geometry(bonsai.core.tool.Geometry):
pset = ifcopenshell.util.element.get_pset(new[0], "BBIM_Linked_Aggregate")
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=new[0], pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=new[0], pset=pset)
if new[0].is_a("IfcElementAssembly"):
linked_aggregate_group = [
+4
View File
@@ -31,11 +31,15 @@ from typing import TYPE_CHECKING, Union, Literal, Any
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
try:
import git
import git.exc
import git.objects
except ImportError:
print("Warning: GitPython not available.")
if TYPE_CHECKING:
import git
import git.exc
import git.objects
from bonsai.bim.module.ifcgit.prop import IfcGitProperties
+14 -15
View File
@@ -690,10 +690,10 @@ class Model(bonsai.core.tool.Model):
data.extend(boolean_ids)
data = list(set(data))
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Boolean")
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Boolean")
data = boolean_ids
data = tool.Ifc.get().createIfcText(json.dumps(data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": data})
@classmethod
def unmark_manual_booleans(cls, element: ifcopenshell.entity_instance, boolean_ids: list[int]) -> None:
@@ -712,9 +712,9 @@ class Model(bonsai.core.tool.Model):
pset = tool.Ifc.get().by_id(pset["id"])
if data:
data = tool.Ifc.get().createIfcText(json.dumps(data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=pset, properties={"Data": data})
else:
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=pset)
@classmethod
def get_flow_segment_axis(cls, obj: bpy.types.Object) -> tuple[Vector, Vector]:
@@ -880,7 +880,7 @@ class Model(bonsai.core.tool.Model):
# can be reverted later.
array_pset_data = array_pset.get("Data", None)
array_pset = tool.Ifc.get().by_id(array_pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=array_pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=element, pset=array_pset)
# remove constraints
obj = tool.Ifc.get_object(element)
@@ -899,8 +899,7 @@ class Model(bonsai.core.tool.Model):
obj = tool.Ifc.get_object(element)
array_pset = tool.Pset.get_element_pset(element, "BBIM_Array")
default_data = tool.Ifc.get().createIfcText('[{"children": []}]')
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=array_pset,
properties={"Parent": element.GlobalId, "Data": default_data},
@@ -909,7 +908,7 @@ class Model(bonsai.core.tool.Model):
tool.Model.regenerate_array(obj, array_data)
json_data = tool.Ifc.get().createIfcText(json.dumps(array_data))
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=array_pset, properties={"Data": json_data})
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), pset=array_pset, properties={"Data": json_data})
for i in range(len(array_data)):
tool.Blender.Modifier.Array.set_children_lock_state(element, i, True)
@@ -1007,7 +1006,7 @@ class Model(bonsai.core.tool.Model):
if array_i in array_layers_to_apply:
for child_element in children_elements:
pset = tool.Pset.get_element_pset(child_element, "BBIM_Array")
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=child_element, pset=pset)
ifcopenshell.api.pset.remove_pset(tool.Ifc.get(), product=child_element, pset=pset)
array["children"] = []
array["count"] = 1
@@ -1034,10 +1033,10 @@ class Model(bonsai.core.tool.Model):
old_representation = tool.Geometry.resolve_mapped_representation(old_representation)
for inverse in ifc_file.get_inverse(old_representation):
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=old_representation)
ifcopenshell.api.geometry.remove_representation(ifc_file, representation=old_representation)
else:
ifcopenshell.api.run(
"geometry.assign_representation", ifc_file, product=ifc_element, representation=new_representation
ifcopenshell.api.geometry.assign_representation(
ifc_file, product=ifc_element, representation=new_representation
)
bonsai.core.geometry.switch_representation(
tool.Ifc,
@@ -1559,8 +1558,8 @@ class Model(bonsai.core.tool.Model):
opening, "Model", "Body", "MODEL_VIEW"
)
old_representation = tool.Geometry.resolve_mapped_representation(old_representation)
ifcopenshell.api.run(
"geometry.unassign_representation", ifc_file, product=opening, representation=old_representation
ifcopenshell.api.geometry.unassign_representation(
ifc_file, product=opening, representation=old_representation
)
new_representation = FilledOpeningGenerator().generate_opening_from_filling(
@@ -1570,7 +1569,7 @@ class Model(bonsai.core.tool.Model):
for inverse in ifc_file.get_inverse(old_representation):
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=old_representation)
ifcopenshell.api.geometry.remove_representation(ifc_file, representation=old_representation)
has_replaced_opening_representation = True
+1
View File
@@ -24,6 +24,7 @@ import ifcopenshell.util.attribute
import ifcopenshell.util.element
import bonsai.core.tool
import bonsai.tool as tool
import bonsai.bim
from pathlib import Path
from typing import Literal, final, TYPE_CHECKING
from bonsai.bim.ifc import IfcStore
+11 -13
View File
@@ -20,6 +20,9 @@ from __future__ import annotations
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.feature
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.util.representation
import ifcopenshell.util.element
@@ -285,11 +288,8 @@ class Root(bonsai.core.tool.Root):
filling_obj = tool.Ifc.get_object(new_subelement)
existing_opening_occurrence = subelement.FillsVoids[0].RelatingOpeningElement
opening = ifcopenshell.api.run(
"root.copy_class", tool.Ifc.get(), product=existing_opening_occurrence
)
ifcopenshell.api.run(
"geometry.edit_object_placement",
opening = ifcopenshell.api.root.copy_class(tool.Ifc.get(), product=existing_opening_occurrence)
ifcopenshell.api.geometry.edit_object_placement(
tool.Ifc.get(),
product=opening,
matrix=ifcopenshell.util.placement.get_local_placement(opening.ObjectPlacement),
@@ -300,17 +300,16 @@ class Root(bonsai.core.tool.Root):
existing_opening_occurrence, "Model", "Body", "MODEL_VIEW"
)
representation = ifcopenshell.util.representation.resolve_representation(representation)
mapped_representation = ifcopenshell.api.run(
"geometry.map_representation", tool.Ifc.get(), representation=representation
mapped_representation = ifcopenshell.api.geometry.map_representation(
tool.Ifc.get(), representation=representation
)
ifcopenshell.api.run(
"geometry.assign_representation",
ifcopenshell.api.geometry.assign_representation(
tool.Ifc.get(),
product=opening,
representation=mapped_representation,
)
ifcopenshell.api.run("feature.add_feature", tool.Ifc.get(), feature=opening, element=element)
ifcopenshell.api.run("feature.add_filling", tool.Ifc.get(), opening=opening, element=filling)
ifcopenshell.api.feature.add_feature(tool.Ifc.get(), feature=opening, element=element)
ifcopenshell.api.feature.add_filling(tool.Ifc.get(), opening=opening, element=filling)
voided_objs = [voided_obj]
# Openings affect all subelements of an aggregate
@@ -344,8 +343,7 @@ class Root(bonsai.core.tool.Root):
new_related_element = old_to_new.get(data["related_element"])[0]
except:
continue
ifcopenshell.api.run(
"geometry.connect_path",
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
relating_element=new_relating_element,
related_element=new_related_element,
@@ -273,9 +273,11 @@ Here's an example of it in action:
.. code-block:: python
import ifcopenshell.api
ifcopenshell.api.run("grid.create_grid_axis", model, ...)
ifcopenshell.api.run("structural.add_structural_load", model, ...)
import ifcopenshell.api.grid
import ifcopenshell.api.structural
ifcopenshell.api.grid.create_grid_axis(model, ...)
ifcopenshell.api.structural.add_structural_load(model, ...)
Because the API performs all the IFC manipulations to achieve a usecase, no
further interaction is required in a typical native IFC authoring environment.
@@ -62,7 +62,7 @@ Instead, stuff happens in Blender operators.
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
ifcopenshell.api.run("foo.bar", tool.Ifc.get())
ifcopenshell.api.foo.bar( tool.Ifc.get())
return {"FINISHED"}
When your operator manipulates (creates, removes, or edits) IFC data directly or
+4 -2
View File
@@ -274,8 +274,10 @@ if BPY_IS_LOADED:
f"Couldn't find locale path in the source directory, creating dummy directory: {source_locale_path}.",
)
from ui_translate.settings import settings as ui_translate_settings
from ui_translate.update_ui import UI_OT_i18n_updatetranslation_init_settings
from ui_translate.settings import settings as ui_translate_settings # pyright: ignore[reportMissingImports]
from ui_translate.update_ui import ( # pyright: ignore[reportMissingImports]
UI_OT_i18n_updatetranslation_init_settings,
)
i18n_settings = context.window_manager.i18n_update_settings
if not i18n_settings.is_init:
+1 -1
View File
@@ -17,7 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import xml.sax, json, copy, pathlib
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup # pyright: ignore[reportMissingModuleSource]
import sys
sys.setrecursionlimit(100)
+3 -2
View File
@@ -23,8 +23,9 @@ import sys
# sys.path.append('C:\Program Files\Python37\Lib\site-packages')
import lxml
import bspy
from bspy import Gbxml
import lxml.etree
import bspy # pyright: ignore[reportMissingImports]
from bspy import Gbxml # pyright: ignore[reportMissingImports]
class GbxmlExporter:
+43 -47
View File
@@ -22,6 +22,14 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.project
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.unit
import bonsai.tool as tool
@@ -32,32 +40,26 @@ class LibraryGenerator:
self.materials = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProject", name="Australian Library"
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name="Australian Library"
)
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name="Australian Library"
self.library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary", name="Australian Library")
ifcopenshell.api.project.assign_declaration(self.file, definitions=[self.library], relating_context=self.project
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.project
)
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", self.file, context_type="Plan")
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
plan = ifcopenshell.api.context.add_context(self.file, context_type="Plan")
self.representations = {
"model_body": ifcopenshell.api.run(
"context.add_context",
"model_body": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"plan_body": ifcopenshell.api.run(
"context.add_context",
"plan_body": ifcopenshell.api.context.add_context(
self.file,
context_type="Plan",
context_identifier="Annotation",
@@ -81,7 +83,7 @@ class LibraryGenerator:
}
for name, data in self.materials.items():
self.materials[name]["ifc"] = ifcopenshell.api.run("material.add_material", self.file, name=name)
self.materials[name]["ifc"] = ifcopenshell.api.material.add_material(self.file, name=name)
self.materials[name]["ifc"].Category = data["Category"]
self.layer_types = {
@@ -121,12 +123,12 @@ class LibraryGenerator:
self.layer_types[name]["ifc"] = self.create_layer_set_type(name, data)
product = self.create_layer_type("IfcCoveringType", "DEMO20", 0.02)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=product, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"LayerSetDirection": "AXIS2"})
pset = ifcopenshell.api.pset.add_pset( self.file, product=product, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset( self.file, pset=pset, properties={"LayerSetDirection": "AXIS2"})
product = self.create_layer_type("IfcCoveringType", "DEMO30", 0.03)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=product, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"LayerSetDirection": "AXIS3"})
pset = ifcopenshell.api.pset.add_pset( self.file, product=product, name="EPset_Parametric")
ifcopenshell.api.pset.edit_pset( self.file, pset=pset, properties={"LayerSetDirection": "AXIS3"})
self.create_layer_type("IfcRampType", "DEMO200", 0.2)
@@ -186,44 +188,41 @@ class LibraryGenerator:
self.file.write("bonsai-au-library.ifc")
def create_layer_set_type(self, name, data):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=data["type"], name=name)
element = ifcopenshell.api.root.create_entity( self.file, ifc_class=data["type"], name=name)
element.Description = data["Description"]
rel = ifcopenshell.api.run("material.assign_material", self.file, products=[element], type="IfcMaterialLayerSet")
rel = ifcopenshell.api.material.assign_material( self.file, products=[element], type="IfcMaterialLayerSet")
layer_set = rel.RelatingMaterial
for layer_data in data["Layers"]:
layer = ifcopenshell.api.run(
"material.add_layer", self.file, layer_set=layer_set, material=self.materials[layer_data[1]]["ifc"]
layer = ifcopenshell.api.material.add_layer( self.file, layer_set=layer_set, material=self.materials[layer_data[1]]["ifc"]
)
layer.Name = layer_data[0]
layer.LayerThickness = layer_data[2]
ifcopenshell.api.run("project.assign_declaration", self.file, definitions=[element], relating_context=self.library)
ifcopenshell.api.project.assign_declaration( self.file, definitions=[element], relating_context=self.library)
return element
def create_layer_type(self, ifc_class, name, thickness):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.run("material.assign_material", self.file, products=[element], type="IfcMaterialLayerSet")
element = ifcopenshell.api.root.create_entity( self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.material.assign_material( self.file, products=[element], type="IfcMaterialLayerSet")
layer_set = rel.RelatingMaterial
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=layer_set, material=self.materials["TBD"]["ifc"])
layer = ifcopenshell.api.material.add_layer( self.file, layer_set=layer_set, material=self.materials["TBD"]["ifc"])
layer.LayerThickness = thickness
ifcopenshell.api.run("project.assign_declaration", self.file, definitions=[element], relating_context=self.library)
ifcopenshell.api.project.assign_declaration( self.file, definitions=[element], relating_context=self.library)
return element
def create_profile_type(self, ifc_class, name, profile):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.run("material.assign_material", self.file, products=[element], type="IfcMaterialProfileSet")
element = ifcopenshell.api.root.create_entity( self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.material.assign_material( self.file, products=[element], type="IfcMaterialProfileSet")
profile_set = rel.RelatingMaterial
material_profile = ifcopenshell.api.run(
"material.add_profile", self.file, profile_set=profile_set, material=self.materials["TBD"]["ifc"]
material_profile = ifcopenshell.api.material.add_profile( self.file, profile_set=profile_set, material=self.materials["TBD"]["ifc"]
)
ifcopenshell.api.run("material.assign_profile", self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.run("project.assign_declaration", self.file, definitions=[element], relating_context=self.library)
ifcopenshell.api.material.assign_profile( self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.project.assign_declaration( self.file, definitions=[element], relating_context=self.library)
def create_type(self, ifc_class, name, representations):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity( self.file, ifc_class=ifc_class, name=name)
for rep_name, obj_name in representations.items():
obj = bpy.data.objects.get(obj_name)
representation = ifcopenshell.api.run(
"geometry.add_representation",
representation = ifcopenshell.api.geometry.add_representation(
self.file,
context=self.representations[rep_name],
blender_object=obj,
@@ -232,9 +231,8 @@ class LibraryGenerator:
)
styles = []
for slot in obj.material_slots:
style = ifcopenshell.api.run("style.add_style", self.file, name=slot.material.name)
ifcopenshell.api.run(
"style.add_surface_style",
style = ifcopenshell.api.style.add_style( self.file, name=slot.material.name)
ifcopenshell.api.style.add_surface_style(
self.file,
style=style,
ifc_class="IfcSurfaceStyleRendering",
@@ -242,13 +240,11 @@ class LibraryGenerator:
)
styles.append(style)
if styles:
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, shape_representation=representation, styles=styles
ifcopenshell.api.style.assign_representation_styles( self.file, shape_representation=representation, styles=styles
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation
ifcopenshell.api.geometry.assign_representation( self.file, product=element, representation=representation
)
ifcopenshell.api.run("project.assign_declaration", self.file, definitions=[element], relating_context=self.library)
ifcopenshell.api.project.assign_declaration( self.file, definitions=[element], relating_context=self.library)
LibraryGenerator().generate()
@@ -20,6 +20,12 @@ import os
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.unit
import bonsai.tool as tool
from pathlib import Path
@@ -36,46 +42,40 @@ class LibraryGenerator:
self.materials = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name=library_name
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary", name=library_name)
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[self.library], relating_context=self.project
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.project
)
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", self.file, context_type="Plan")
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
plan = ifcopenshell.api.context.add_context(self.file, context_type="Plan")
self.representations = {
"Model/Body/MODEL_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/MODEL_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"Plan/Body/PLAN_VIEW": ifcopenshell.api.run(
"context.add_context",
"Plan/Body/PLAN_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Plan",
context_identifier="Body",
target_view="PLAN_VIEW",
parent=plan,
),
"Model/Body/PLAN_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/PLAN_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="PLAN_VIEW",
parent=model,
),
"Model/Body/SECTION_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/SECTION_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
@@ -100,13 +100,12 @@ class LibraryGenerator:
self.file.write(output_filename)
def create_type(self, ifc_class, name, representations):
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class=ifc_class, predefined_type="ENTOURAGE", name=name
element = ifcopenshell.api.root.create_entity(
self.file, ifc_class=ifc_class, predefined_type="ENTOURAGE", name=name
)
for rep_name, obj_name in representations.items():
obj = bpy.data.objects.get(obj_name)
representation = ifcopenshell.api.run(
"geometry.add_representation",
representation = ifcopenshell.api.geometry.add_representation(
self.file,
context=self.representations[rep_name],
blender_object=obj,
@@ -115,9 +114,8 @@ class LibraryGenerator:
)
styles = []
for slot in obj.material_slots:
style = ifcopenshell.api.run("style.add_style", self.file, name=slot.material.name)
ifcopenshell.api.run(
"style.add_surface_style",
style = ifcopenshell.api.style.add_style(self.file, name=slot.material.name)
ifcopenshell.api.style.add_surface_style(
self.file,
style=style,
ifc_class="IfcSurfaceStyleShading",
@@ -125,15 +123,11 @@ class LibraryGenerator:
)
styles.append(style)
if styles:
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, shape_representation=representation, styles=styles
ifcopenshell.api.style.assign_representation_styles(
self.file, shape_representation=representation, styles=styles
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
if __name__ == "__main__":
@@ -19,6 +19,13 @@
import numpy as np
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.unit
import ifcopenshell.util.element
from math import cos, tan, pi
from pathlib import Path
@@ -37,30 +44,26 @@ class LibraryGenerator:
self.materials = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name=library_name
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary", name=library_name)
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[self.library], relating_context=self.project
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.project
)
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", self.file, context_type="Plan")
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
plan = ifcopenshell.api.context.add_context(self.file, context_type="Plan")
self.representations = {
"model_body": ifcopenshell.api.run(
"context.add_context",
"model_body": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"plan_body": ifcopenshell.api.run(
"context.add_context",
"plan_body": ifcopenshell.api.context.add_context(
self.file,
context_type="Plan",
context_identifier="Body",
@@ -1847,78 +1850,58 @@ class LibraryGenerator:
self.file.write(output_filename)
def create_explicit_type(self, ifc_class, name, representation_3d, representation_2d, **params):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
for param, value in params.items():
setattr(element, param, value)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation_3d
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation_2d
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation_3d)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation_2d)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
return element
def create_layer_set_type(self, name, data):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=data["type"], name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=data["type"], name=name)
element.Description = data["Description"]
rel = ifcopenshell.api.run(
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSet"
)
rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSet")
layer_set = rel.RelatingMaterial
for layer_data in data["Layers"]:
layer = ifcopenshell.api.run(
"material.add_layer", self.file, layer_set=layer_set, material=self.materials[layer_data[1]]["ifc"]
layer = ifcopenshell.api.material.add_layer(
self.file, layer_set=layer_set, material=self.materials[layer_data[1]]["ifc"]
)
layer.Name = layer_data[0]
layer.LayerThickness = layer_data[2]
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
return element
def create_layer_type(self, ifc_class, name, thickness):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.run(
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSet"
)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSet")
layer_set = rel.RelatingMaterial
layer = ifcopenshell.api.run(
"material.add_layer", self.file, layer_set=layer_set, material=self.materials["TBD"]["ifc"]
layer = ifcopenshell.api.material.add_layer(
self.file, layer_set=layer_set, material=self.materials["TBD"]["ifc"]
)
layer.LayerThickness = thickness
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
return element
def create_profile_type(self, ifc_class, name, profile):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.run(
"material.assign_material", self.file, products=[element], type="IfcMaterialProfileSet"
)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialProfileSet")
profile_set = rel.RelatingMaterial
material_profile = ifcopenshell.api.run(
"material.add_profile",
material_profile = ifcopenshell.api.material.add_profile(
self.file,
profile_set=profile_set,
material=self.material,
# material=self.materials["TBD"]["ifc"]
)
ifcopenshell.api.run("material.assign_profile", self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.material.assign_profile(self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
def create_type(self, ifc_class, name, representations):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
for rep_name, obj_name in representations.items():
obj = bpy.data.objects.get(obj_name)
representation = ifcopenshell.api.run(
"geometry.add_representation",
representation = ifcopenshell.api.geometry.add_representation(
self.file,
context=self.representations[rep_name],
blender_object=obj,
@@ -1927,9 +1910,8 @@ class LibraryGenerator:
)
styles = []
for slot in obj.material_slots:
style = ifcopenshell.api.run("style.add_style", self.file, name=slot.material.name)
ifcopenshell.api.run(
"style.add_surface_style",
style = ifcopenshell.api.style.add_style(self.file, name=slot.material.name)
ifcopenshell.api.style.add_surface_style(
self.file,
style=style,
ifc_class="IfcSurfaceStyleRendering",
@@ -1937,15 +1919,11 @@ class LibraryGenerator:
)
styles.append(style)
if styles:
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, shape_representation=representation, styles=styles
ifcopenshell.api.style.assign_representation_styles(
self.file, shape_representation=representation, styles=styles
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
if __name__ == "__main__":
@@ -22,6 +22,13 @@ import csv
import random
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.unit
import ifcopenshell.util.unit
import bonsai.tool as tool
from math import cos, sin, tan, pi
from pathlib import Path
@@ -313,46 +320,40 @@ class LibraryGenerator:
self.materials = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name=library_name
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name=library_name)
self.library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary", name=library_name)
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[self.library], relating_context=self.project
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.project
)
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", self.file, context_type="Plan")
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
plan = ifcopenshell.api.context.add_context(self.file, context_type="Plan")
self.representations = {
"Model/Body/MODEL_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/MODEL_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"Plan/Body/PLAN_VIEW": ifcopenshell.api.run(
"context.add_context",
"Plan/Body/PLAN_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Plan",
context_identifier="Body",
target_view="PLAN_VIEW",
parent=plan,
),
"Model/Body/PLAN_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/PLAN_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="PLAN_VIEW",
parent=model,
),
"Model/Body/SECTION_VIEW": ifcopenshell.api.run(
"context.add_context",
"Model/Body/SECTION_VIEW": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
@@ -435,27 +436,20 @@ class LibraryGenerator:
}
def create_explicit_type(self, ifc_class, name, representation_3d, representation_2d, **params):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
for param, value in params.items():
setattr(element, param, value)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation_3d
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation_2d
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation_3d)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation_2d)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
return element
def create_type(self, ifc_class, name, representations):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
for rep_name, obj_name in representations.items():
obj = bpy.data.objects.get(obj_name)
representation = ifcopenshell.api.run(
"geometry.add_representation",
representation = ifcopenshell.api.geometry.add_representation(
self.file,
context=self.representations[rep_name],
blender_object=obj,
@@ -464,9 +458,8 @@ class LibraryGenerator:
)
styles = []
for slot in obj.material_slots:
style = ifcopenshell.api.run("style.add_style", self.file, name=slot.material.name)
ifcopenshell.api.run(
"style.add_surface_style",
style = ifcopenshell.api.style.add_style(self.file, name=slot.material.name)
ifcopenshell.api.style.add_surface_style(
self.file,
style=style,
ifc_class="IfcSurfaceStyleShading",
@@ -474,15 +467,11 @@ class LibraryGenerator:
)
styles.append(style)
if styles:
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, shape_representation=representation, styles=styles
ifcopenshell.api.style.assign_representation_styles(
self.file, shape_representation=representation, styles=styles
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
if __name__ == "__main__":
+24 -26
View File
@@ -19,6 +19,12 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.unit
import bonsai.tool as tool
@@ -27,27 +33,25 @@ class LibraryGenerator:
ifcopenshell.api.pre_listeners = {}
ifcopenshell.api.post_listeners = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Bonsai Demo")
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name="Bonsai Demo Library"
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name="Bonsai Demo")
self.library = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcProjectLibrary", name="Bonsai Demo Library"
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.library
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[self.library], relating_context=self.library
)
ifcopenshell.api.run("unit.assign_unit", self.file, length={"is_metric": True, "raw": "METERS"})
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
ifcopenshell.api.unit.assign_unit(self.file, length={"is_metric": True, "raw": "METERS"})
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
self.representations = {
"body": ifcopenshell.api.run(
"context.add_context",
"body": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"clearance": ifcopenshell.api.run(
"context.add_context",
"clearance": ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Clearance",
@@ -67,11 +71,10 @@ class LibraryGenerator:
self.file.write("bonsai-site-library.ifc")
def create_type(self, ifc_class, name, representations):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class=ifc_class, name=name)
for rep_name, obj_name in representations.items():
obj = bpy.data.objects.get(obj_name)
representation = ifcopenshell.api.run(
"geometry.add_representation",
representation = ifcopenshell.api.geometry.add_representation(
self.file,
context=self.representations[rep_name],
blender_object=obj,
@@ -80,9 +83,8 @@ class LibraryGenerator:
)
styles = []
for slot in obj.material_slots:
style = ifcopenshell.api.run("style.add_style", self.file, name=slot.material.name)
ifcopenshell.api.run(
"style.add_surface_style",
style = ifcopenshell.api.style.add_style(self.file, name=slot.material.name)
ifcopenshell.api.style.add_surface_style(
self.file,
style=style,
ifc_class="IfcSurfaceStyleRendering",
@@ -90,15 +92,11 @@ class LibraryGenerator:
)
styles.append(style)
if styles:
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, shape_representation=representation, styles=styles
ifcopenshell.api.style.assign_representation_styles(
self.file, shape_representation=representation, styles=styles
)
ifcopenshell.api.run(
"geometry.assign_representation", self.file, product=element, representation=representation
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element], relating_context=self.library
)
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=representation)
ifcopenshell.api.project.assign_declaration(self.file, definitions=[element], relating_context=self.library)
LibraryGenerator().generate()
@@ -21,7 +21,11 @@
import ifcopenshell
import ifcopenshell.api
import boltspy as bolts
import ifcopenshell.api.material
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.unit
import boltspy as bolts # pyright: ignore[reportMissingImports]
from math import cos, pi
from pathlib import Path
from ifcopenshell.util.shape_builder import ShapeBuilder, V, ifc_safe_vector_type
@@ -35,29 +39,26 @@ class LibraryGenerator:
self.materials = {}
self.file = ifcopenshell.api.run("project.create_file")
self.project = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProject", name=f"{parse_profiles_type} Steel Profiles Library"
self.file = ifcopenshell.api.project.create_file()
self.project = ifcopenshell.api.root.create_entity( self.file, ifc_class="IfcProject", name=f"{parse_profiles_type} Steel Profiles Library"
)
self.library = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProjectLibrary", name=f"{parse_profiles_type} Steel Profiles Library"
self.library = ifcopenshell.api.root.create_entity( self.file, ifc_class="IfcProjectLibrary", name=f"{parse_profiles_type} Steel Profiles Library"
)
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[self.library], relating_context=self.project
ifcopenshell.api.project.assign_declaration( self.file, definitions=[self.library], relating_context=self.project
)
dim_exponents = self.file.createIfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0)
length_unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
length_unit = ifcopenshell.api.unit.add_si_unit( self.file, unit_type="LENGTHUNIT", prefix="MILLI")
builder = ShapeBuilder(self.file)
# define angle unit to use degrees for IfcPlaneAngleMeasure:
# https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/lexical/IfcPlaneAngleMeasure.htm
angle_unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="PLANEANGLEUNIT")
angle_unit = ifcopenshell.api.unit.add_si_unit( self.file, unit_type="PLANEANGLEUNIT")
value_component = self.file.createIfcReal(pi/180)
angle_unit = self.file.createIfcMeasureWithUnit(ValueComponent=value_component, UnitComponent=angle_unit)
angle_unit = self.file.createIfcConversionBasedUnit(Name="degree", Dimensions=dim_exponents, UnitType="PLANEANGLEUNIT", ConversionFactor=angle_unit)
ifcopenshell.api.run("unit.assign_unit", self.file, units=[length_unit, angle_unit])
ifcopenshell.api.unit.assign_unit( self.file, units=[length_unit, angle_unit])
self.material = ifcopenshell.api.run("material.add_material", self.file, name="Unknown")
self.material = ifcopenshell.api.material.add_material( self.file, name="Unknown")
# NOTE: parameters could be optional (example: welded i-beams don't have FilletRadius)
profiles_translation = {
@@ -174,15 +175,14 @@ class LibraryGenerator:
print('-----------------------')
def create_profile_type(self, ifc_class, name, profile):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.run("material.assign_material", self.file, products=[element], type="IfcMaterialProfileSet")
element = ifcopenshell.api.root.create_entity( self.file, ifc_class=ifc_class, name=name)
rel = ifcopenshell.api.material.assign_material( self.file, products=[element], type="IfcMaterialProfileSet")
profile_set = rel.RelatingMaterial
material_profile = ifcopenshell.api.run(
"material.add_profile", self.file, profile_set=profile_set, material=self.material
material_profile = ifcopenshell.api.material.add_profile( self.file, profile_set=profile_set, material=self.material
# material=self.materials["TBD"]["ifc"]
)
ifcopenshell.api.run("material.assign_profile", self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.run("project.assign_declaration", self.file, definitions=[element], relating_context=self.library)
ifcopenshell.api.material.assign_profile( self.file, material_profile=material_profile, profile=profile)
ifcopenshell.api.project.assign_declaration( self.file, definitions=[element], relating_context=self.library)
def create_double_l_profile(self, profile, resulting_profile_name=None, profiles_gap=0, mode = "LLBB"):
def create_derived_profile(profile, mirrored=False):
@@ -18,6 +18,8 @@
import ifcopenshell
import ifcopenshell.api.pset
import ifcopenshell.util.element
import bonsai.tool as tool
import bpy
@@ -67,9 +69,8 @@ def update_geometry_data():
if pset:
pset = tool.Ifc.get().by_id(pset["id"])
else:
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Geonodes")
ifcopenshell.api.run(
"pset.edit_pset",
pset = ifcopenshell.api.pset.add_pset(tool.Ifc.get(), product=element, name="BBIM_Geonodes")
ifcopenshell.api.pset.edit_pset(
tool.Ifc.get(),
pset=pset,
properties={"Data": json.dumps(geo_data, default=list)},
+29 -27
View File
@@ -19,9 +19,16 @@
# This can be packaged with `pyinstaller --onefile --hidden-import numpy --collect-all ifcopenshell --clean obj2ifc.py`
import argparse
import pymeshlab
import pymeshlab # pyright: ignore[reportMissingImports]
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import ifcopenshell.api.owner.settings
import ifcopenshell.guid
from pathlib import Path
@@ -86,9 +93,7 @@ class Obj2Ifc:
Name=mesh.label() or self.basename,
Representation=representation,
)
ifcopenshell.api.run(
"spatial.assign_container", self.file, products=[product], relating_structure=self.storey
)
ifcopenshell.api.spatial.assign_container(self.file, products=[product], relating_structure=self.storey)
product.ObjectPlacement = self.placement
self.file.write(self.outfile)
@@ -99,42 +104,39 @@ class Obj2Ifc:
return [coordinates[0], -coordinates[2], coordinates[1]]
def create_ifc_file(self, version):
self.file = ifcopenshell.api.run("project.create_file", version=version)
person = ifcopenshell.api.run("owner.add_person", self.file)
self.file = ifcopenshell.api.project.create_file(version=version)
person = ifcopenshell.api.owner.add_person(self.file)
person[0] = person.GivenName = None
person.FamilyName = "user"
org = ifcopenshell.api.run("owner.add_organisation", self.file)
org = ifcopenshell.api.owner.add_organisation(self.file)
org[0] = None
org.Name = "template"
user = ifcopenshell.api.run("owner.add_person_and_organisation", self.file, person=person, organisation=org)
application = ifcopenshell.api.run("owner.add_application", self.file)
user = ifcopenshell.api.owner.add_person_and_organisation(self.file, person=person, organisation=org)
application = ifcopenshell.api.owner.add_application(self.file)
ifcopenshell.api.owner.settings.get_user = lambda ifc: user
ifcopenshell.api.owner.settings.get_application = lambda ifc: application
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name=self.basename)
lengthunit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[lengthunit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
self.context = ifcopenshell.api.run(
"context.add_context",
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name=self.basename)
lengthunit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(self.file, units=[lengthunit])
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
self.context = ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
)
site = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite", name="My Site")
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding", name="My Building")
self.storey = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[site], relating_object=project)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[self.storey], relating_object=building)
site = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSite", name="My Site")
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding", name="My Building")
self.storey = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuildingStorey", name="My Storey")
ifcopenshell.api.aggregate.assign_object(self.file, products=[site], relating_object=project)
ifcopenshell.api.aggregate.assign_object(self.file, products=[building], relating_object=site)
ifcopenshell.api.aggregate.assign_object(self.file, products=[self.storey], relating_object=building)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=self.storey)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=site)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=building)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=self.storey)
self.origin = self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
@@ -142,7 +144,7 @@ class Obj2Ifc:
self.file.createIfcDirection((1.0, 0.0, 0.0)),
)
self.placement = self.file.createIfcLocalPlacement(self.storey.ObjectPlacement, self.origin)
self.history = ifcopenshell.api.run("owner.create_owner_history", self.file)
self.history = ifcopenshell.api.owner.create_owner_history(self.file)
if __name__ == "__main__":
+29 -27
View File
@@ -19,9 +19,16 @@
# This can be packaged with `pyinstaller --onefile --hidden-import numpy --collect-all ifcopenshell --clean obj2ifc.py`
import argparse
import pywavefront
import pywavefront # pyright: ignore[reportMissingImports]
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import ifcopenshell.api.owner.settings
import ifcopenshell.guid
from pathlib import Path
@@ -80,9 +87,7 @@ class Obj2Ifc:
Name=mesh.name or self.basename,
Representation=representation,
)
ifcopenshell.api.run(
"spatial.assign_container", self.file, products=[product], relating_structure=self.storey
)
ifcopenshell.api.spatial.assign_container(self.file, products=[product], relating_structure=self.storey)
product.ObjectPlacement = self.placement
self.file.write(self.outfile)
@@ -92,42 +97,39 @@ class Obj2Ifc:
return [coordinates[0], -coordinates[2], coordinates[1]]
def create_ifc_file(self, version):
self.file = ifcopenshell.api.run("project.create_file", version=version)
person = ifcopenshell.api.run("owner.add_person", self.file)
self.file = ifcopenshell.api.project.create_file(version=version)
person = ifcopenshell.api.owner.add_person(self.file)
person[0] = person.GivenName = None
person.FamilyName = "user"
org = ifcopenshell.api.run("owner.add_organisation", self.file)
org = ifcopenshell.api.owner.add_organisation(self.file)
org[0] = None
org.Name = "template"
user = ifcopenshell.api.run("owner.add_person_and_organisation", self.file, person=person, organisation=org)
application = ifcopenshell.api.run("owner.add_application", self.file)
user = ifcopenshell.api.owner.add_person_and_organisation(self.file, person=person, organisation=org)
application = ifcopenshell.api.owner.add_application(self.file)
ifcopenshell.api.owner.settings.get_user = lambda ifc: user
ifcopenshell.api.owner.settings.get_application = lambda ifc: application
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name=self.basename)
lengthunit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[lengthunit])
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
self.context = ifcopenshell.api.run(
"context.add_context",
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name=self.basename)
lengthunit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(self.file, units=[lengthunit])
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
self.context = ifcopenshell.api.context.add_context(
self.file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
)
site = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite", name="My Site")
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding", name="My Building")
self.storey = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[site], relating_object=project)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[self.storey], relating_object=building)
site = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSite", name="My Site")
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding", name="My Building")
self.storey = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuildingStorey", name="My Storey")
ifcopenshell.api.aggregate.assign_object(self.file, products=[site], relating_object=project)
ifcopenshell.api.aggregate.assign_object(self.file, products=[building], relating_object=site)
ifcopenshell.api.aggregate.assign_object(self.file, products=[self.storey], relating_object=building)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=self.storey)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=site)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=building)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=self.storey)
self.origin = self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
@@ -135,7 +137,7 @@ class Obj2Ifc:
self.file.createIfcDirection((1.0, 0.0, 0.0)),
)
self.placement = self.file.createIfcLocalPlacement(self.storey.ObjectPlacement, self.origin)
self.history = ifcopenshell.api.run("owner.create_owner_history", self.file)
self.history = ifcopenshell.api.owner.create_owner_history(self.file)
if __name__ == "__main__":
+3 -2
View File
@@ -29,6 +29,8 @@ It works on the active ifc file (if exists).
import bonsai.tool as tool
import ifcopenshell
import ifcopenshell.api.pset
import ifcopenshell.util.element
import sys
@@ -53,8 +55,7 @@ for annotation in annotations:
wrong_sep = "\\"
if platform == "win32":
wrong_sep = "/"
ifcopenshell.api.run(
"pset.edit_pset",
ifcopenshell.api.pset.edit_pset(
file,
pset=pset_ifc,
properties={
+35 -34
View File
@@ -1,4 +1,9 @@
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.unit
from ifcopenshell.util.shape_builder import ShapeBuilder
from mathutils import Vector
@@ -76,30 +81,28 @@ def generate_desk_test():
def mirror_placement_test():
ifc_file = ifcopenshell.api.run("project.create_file")
project = ifcopenshell.api.run(
"root.create_entity", ifc_file, ifc_class="IfcProject", name=f"Non-structural assets library"
ifc_file = ifcopenshell.api.project.create_file()
project = ifcopenshell.api.root.create_entity(
ifc_file, ifc_class="IfcProject", name=f"Non-structural assets library"
)
library = ifcopenshell.api.run(
"root.create_entity", ifc_file, ifc_class="IfcProjectLibrary", name=f"Non-structural assets library"
library = ifcopenshell.api.root.create_entity(
ifc_file, ifc_class="IfcProjectLibrary", name=f"Non-structural assets library"
)
ifcopenshell.api.run("project.assign_declaration", ifc_file, definitions=[library], relating_context=project)
unit = ifcopenshell.api.run("unit.add_si_unit", ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc_file, units=[unit])
model = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Plan")
ifcopenshell.api.project.assign_declaration(ifc_file, definitions=[library], relating_context=project)
unit = ifcopenshell.api.unit.add_si_unit(ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc_file, units=[unit])
model = ifcopenshell.api.context.add_context(ifc_file, context_type="Model")
plan = ifcopenshell.api.context.add_context(ifc_file, context_type="Plan")
representations = {
"body": ifcopenshell.api.run(
"context.add_context",
"body": ifcopenshell.api.context.add_context(
ifc_file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"annotation": ifcopenshell.api.run(
"context.add_context",
"annotation": ifcopenshell.api.context.add_context(
ifc_file,
context_type="Plan",
context_identifier="Annotation",
@@ -136,38 +139,36 @@ def mirror_placement_test():
representation_3d = builder.get_representation(context=representations["body"], items=items_3d)
element = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcFurnitureType", name="test")
ifcopenshell.api.run("geometry.assign_representation", ifc_file, product=element, representation=representation_3d)
ifcopenshell.api.run("project.assign_declaration", ifc_file, definitions=[element], relating_context=library)
element = ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcFurnitureType", name="test")
ifcopenshell.api.geometry.assign_representation(ifc_file, product=element, representation=representation_3d)
ifcopenshell.api.project.assign_declaration(ifc_file, definitions=[element], relating_context=library)
ifc_file.write("tmp.ifc")
def curve_between_two_points_test():
ifc_file = ifcopenshell.api.run("project.create_file")
project = ifcopenshell.api.run(
"root.create_entity", ifc_file, ifc_class="IfcProject", name=f"Non-structural assets library"
ifc_file = ifcopenshell.api.project.create_file()
project = ifcopenshell.api.root.create_entity(
ifc_file, ifc_class="IfcProject", name=f"Non-structural assets library"
)
library = ifcopenshell.api.run(
"root.create_entity", ifc_file, ifc_class="IfcProjectLibrary", name=f"Non-structural assets library"
library = ifcopenshell.api.root.create_entity(
ifc_file, ifc_class="IfcProjectLibrary", name=f"Non-structural assets library"
)
ifcopenshell.api.run("project.assign_declaration", ifc_file, definitions=[library], relating_context=project)
unit = ifcopenshell.api.run("unit.add_si_unit", ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc_file, units=[unit])
model = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Model")
plan = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Plan")
ifcopenshell.api.project.assign_declaration(ifc_file, definitions=[library], relating_context=project)
unit = ifcopenshell.api.unit.add_si_unit(ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc_file, units=[unit])
model = ifcopenshell.api.context.add_context(ifc_file, context_type="Model")
plan = ifcopenshell.api.context.add_context(ifc_file, context_type="Plan")
representations = {
"body": ifcopenshell.api.run(
"context.add_context",
"body": ifcopenshell.api.context.add_context(
ifc_file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
),
"annotation": ifcopenshell.api.run(
"context.add_context",
"annotation": ifcopenshell.api.context.add_context(
ifc_file,
context_type="Plan",
context_identifier="Annotation",
@@ -199,9 +200,9 @@ def curve_between_two_points_test():
representation_2d = builder.get_representation(context=representations["annotation"], items=items_2d)
print(representation_2d)
element = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcFurnitureType", name="test")
ifcopenshell.api.run("geometry.assign_representation", ifc_file, product=element, representation=representation_2d)
ifcopenshell.api.run("project.assign_declaration", ifc_file, definitions=[element], relating_context=library)
element = ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcFurnitureType", name="test")
ifcopenshell.api.geometry.assign_representation(ifc_file, product=element, representation=representation_2d)
ifcopenshell.api.project.assign_declaration(ifc_file, definitions=[element], relating_context=library)
ifc_file.write("tmp.ifc")
@@ -1,10 +1,11 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.geom
import multiprocessing
class BlenderImporter:
file: ifcopenshell.file
def __init__(self):
self.file = ifcopenshell.open("/home/dion/untitled.ifc")
self.cache_path = "cache.h5"
+1
View File
@@ -15,6 +15,7 @@ class LineworkContexts(NamedTuple):
class Drawer:
def execute(self):
ifc: ifcopenshell.file
ifc = ifcopenshell.open(sys.argv[1])
self.camera_element = ifc.by_guid(sys.argv[2])
# Don't use draw.main() just whilst we're prototyping and experimenting
+8 -6
View File
@@ -1,15 +1,17 @@
import numpy as np
import ifcopenshell
import ifcopenshell.api.aggregate
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.api.style
import ifcopenshell.api.type
import ifcopenshell.api.unit
import ifcopenshell.api.project
import ifcopenshell.api.context
import ifcopenshell.api.spatial
import ifcopenshell.api.material
import ifcopenshell.api.geometry
import ifcopenshell.util.placement
import ifcopenshell.util.shape_builder
import ifcopenshell.util.element
# https://stackoverflow.com/a/9184560/9627415
# Possible optimisation to linalg.norm?
+3 -2
View File
@@ -18,10 +18,11 @@
import bpy
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import ifcopenshell.api.context
import ifcopenshell.util.shape_builder
import bonsai.core.tool
import bonsai.tool as tool
@@ -140,5 +141,5 @@ class TestGetContainer(NewFile):
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
container = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
ifcopenshell.api.spatial.assign_container(ifc, products=[element], relating_structure=container)
assert subject.get_container(element) == container
+7 -5
View File
@@ -23,6 +23,8 @@ import brickschema.persistent
from brickschema.namespaces import REF, A
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.root
import ifcopenshell.guid
import bonsai.core.tool
import bonsai.tool as tool
@@ -325,11 +327,11 @@ class TestGetConvertableBrickSystems(NewFile):
class TestGetParentSpace(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[element], relating_object=project)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcSpace")
project = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.aggregate.assign_object(ifc, products=[subelement], relating_object=element)
ifcopenshell.api.aggregate.assign_object(ifc, products=[element], relating_object=project)
assert subject.get_parent_space(subelement) == element
assert subject.get_parent_space(element) is None
+6 -5
View File
@@ -19,6 +19,7 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.document
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -170,7 +171,7 @@ class TestImportProjectDocuments(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
document = ifcopenshell.api.document.add_information(ifc)
subject.import_project_documents()
props = tool.Document.get_document_props()
assert len(props.documents) == 1
@@ -185,8 +186,8 @@ class TestImportReferences(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
reference = ifcopenshell.api.run("document.add_reference", ifc, information=document)
document = ifcopenshell.api.document.add_information(ifc)
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
subject.import_references(document)
props = tool.Document.get_document_props()
assert len(props.documents) == 1
@@ -201,8 +202,8 @@ class TestImportSubdocuments(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
subdocument = ifcopenshell.api.run("document.add_information", ifc, parent=document)
document = ifcopenshell.api.document.add_information(ifc)
subdocument = ifcopenshell.api.document.add_information(ifc, parent=document)
subject.import_subdocuments(document)
props = tool.Document.get_document_props()
assert len(props.documents) == 1
+17 -14
View File
@@ -22,6 +22,9 @@ import numpy as np
import bpy
import mathutils
import ifcopenshell
import ifcopenshell.api.drawing
import ifcopenshell.api.group
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.guid
import ifcopenshell.util.element
@@ -341,9 +344,9 @@ class TestGetDrawingGroup(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
group = ifcopenshell.api.run("group.add_group", ifc)
group = ifcopenshell.api.group.add_group(ifc)
group.ObjectType = "DRAWING"
ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group)
ifcopenshell.api.group.assign_group(ifc, products=[element], group=group)
assert subject.get_drawing_group(element) == group
@@ -352,8 +355,8 @@ class TestGetDrawingTargetView(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
assert subject.get_drawing_target_view(element) == "PLAN_VIEW"
@@ -362,8 +365,8 @@ class TestGetGroupElements(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
group = ifcopenshell.api.run("group.add_group", ifc)
ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group)
group = ifcopenshell.api.group.add_group(ifc)
ifcopenshell.api.group.assign_group(ifc, products=[element], group=group)
assert subject.get_group_elements(group) == (element,)
@@ -515,7 +518,7 @@ class TestGetAssignedProduct(NewFile):
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
label = ifc.createIfcAnnotation()
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
assert subject.get_assigned_product(label) == wall
@@ -524,8 +527,8 @@ class TestImportDrawings(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
drawing = ifc.createIfcAnnotation(Name="FOOBAR", ObjectType="DRAWING")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=drawing, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
pset = ifcopenshell.api.pset.add_pset(ifc, product=drawing, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
subject.import_drawings()
props = tool.Drawing.get_document_props()
for d in props.drawings:
@@ -635,7 +638,7 @@ class TestImportAssignedProduct(NewFile):
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
label = ifc.createIfcAnnotation()
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
wall_obj = bpy.data.objects.new("Object", None)
label_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(wall, wall_obj)
@@ -794,7 +797,7 @@ class TestUpdateTextValue(NewFile):
ifc = tool.Ifc.get()
wall = ifc.createIfcWall(Name="Baz")
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Name}} Bar"
@@ -808,10 +811,10 @@ class TestUpdateTextValue(NewFile):
obj = bpy.data.objects["Object"]
ifc = tool.Ifc.get()
wall = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, name="Custom_Pset", product=wall)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Key": "Baz"})
pset = ifcopenshell.api.pset.add_pset(ifc, name="Custom_Pset", product=wall)
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Key": "Baz"})
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Custom_Pset.Key}} Bar"
+9 -8
View File
@@ -21,6 +21,7 @@ import math
import numpy as np
import ifcopenshell
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.type
import bonsai.core.tool
import bonsai.tool as tool
@@ -202,7 +203,7 @@ class TestGetElementType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_element_type(element) == type
@@ -212,7 +213,7 @@ class TestGetElementsOfType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_elements_of_type(type) == (element,)
@@ -328,9 +329,9 @@ class TestRemoveConnection(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element1 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
rel = ifcopenshell.api.run("geometry.connect_path", ifc, relating_element=element1, related_element=element2)
element1 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
rel = ifcopenshell.api.geometry.connect_path(ifc, relating_element=element1, related_element=element2)
subject.remove_connection(rel)
assert not tool.Ifc.get().by_type("IfcRelConnectsPathElements")
@@ -445,17 +446,17 @@ class TestSelectConnection(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element1 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element1 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj1 = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj1)
tool.Ifc.link(element1, obj1)
element2 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj2 = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj2)
tool.Ifc.link(element2, obj2)
rel = ifcopenshell.api.run("geometry.connect_path", ifc, relating_element=element1, related_element=element2)
rel = ifcopenshell.api.geometry.connect_path(ifc, relating_element=element1, related_element=element2)
subject.select_connection(rel)
assert obj1 in bpy.context.selected_objects
+39 -35
View File
@@ -20,6 +20,10 @@ import bpy
import math
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.georeference
import ifcopenshell.api.root
import ifcopenshell.api.unit
import bonsai.core.tool
import bonsai.tool as tool
from mathutils import Vector
@@ -36,8 +40,8 @@ class TestImportProjectedCRS(NewFile):
def test_importing_nothing_with_no_georeferencing(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_projected_crs()
props = tool.Georeference.get_georeference_props()
assert len(props.projected_crs) == 0
@@ -45,9 +49,9 @@ class TestImportProjectedCRS(NewFile):
def test_importing_projected_crs(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
projected_crs = ifc.by_type("IfcProjectedCRS")[0]
projected_crs.Name = "Name"
projected_crs.Description = "Description"
@@ -55,7 +59,7 @@ class TestImportProjectedCRS(NewFile):
projected_crs.VerticalDatum = "VerticalDatum"
projected_crs.MapProjection = "MapProjection"
projected_crs.MapZone = "MapZone"
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT")
projected_crs.MapUnit = unit
subject.import_projected_crs()
props = tool.Georeference.get_georeference_props()
@@ -79,8 +83,8 @@ class TestImportCoordinateOperation(NewFile):
def test_importing_nothing_with_no_georeferencing(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_coordinate_operation()
props = tool.Georeference.get_georeference_props()
assert len(props.coordinate_operation) == 0
@@ -88,9 +92,9 @@ class TestImportCoordinateOperation(NewFile):
def test_importing_coordinate_operation(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1
map_conversion.Northings = 2
@@ -120,8 +124,8 @@ class TestImportTrueNorth(NewFile):
def test_detecting_no_true_north(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_true_north()
props = tool.Georeference.get_georeference_props()
assert props.true_north_abscissa == "0"
@@ -131,8 +135,8 @@ class TestImportTrueNorth(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
context = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
context = ifcopenshell.api.context.add_context(ifc, context_type="Model")
context.TrueNorth = ifc.createIfcDirection((1.0, 2.0, 0.0))
subject.import_true_north()
props = tool.Georeference.get_georeference_props()
@@ -216,10 +220,10 @@ class TestGetCursorLocation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
assert bpy.context.scene
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
assert subject.get_cursor_location() == [1000.0, 2000.0, 3000.0]
@@ -228,13 +232,13 @@ class TestGetCursorLocation(NewFile):
class TestXyz2Enh(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
def test_using_the_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
@@ -244,9 +248,9 @@ class TestXyz2Enh(NewFile):
def test_using_the_map_conversion(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1.0
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 0.0, 0.0)
@@ -257,9 +261,9 @@ class TestXyz2Enh(NewFile):
props.blender_offset_x = "1.0"
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Northings = 1.0
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 1.0, 0.0)
@@ -268,13 +272,13 @@ class TestXyz2Enh(NewFile):
class TestEnh2Xyz(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
def test_using_the_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
@@ -284,9 +288,9 @@ class TestEnh2Xyz(NewFile):
def test_using_the_map_conversion(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1.0
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, 0.0, 0.0)
@@ -297,9 +301,9 @@ class TestEnh2Xyz(NewFile):
props.blender_offset_x = "1.0"
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Northings = 1.0
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, -1.0, 0.0)
+4 -3
View File
@@ -21,6 +21,7 @@ import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.style
import bonsai.core.tool
import bonsai.tool as tool
@@ -64,9 +65,9 @@ class TestGetElementsByMaterial(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.assign_material", ifc, products=[element], material=material)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
material = ifcopenshell.api.material.add_material(ifc)
ifcopenshell.api.material.assign_material(ifc, products=[element], material=material)
assert subject.get_elements_by_material(material) == {element}
+18 -15
View File
@@ -20,6 +20,9 @@ import bpy
import math
import numpy
import ifcopenshell
import ifcopenshell.api.aggregate
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import test.bim.bootstrap
import bonsai.core.tool
import bonsai.tool as tool
@@ -39,7 +42,7 @@ class TestGetObjectStorey(test.bim.bootstrap.NewFile):
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=storey)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=storey)
assert subject.get_object_storey(obj) == storey
def test_only_returning_a_building_storey(self):
@@ -49,7 +52,7 @@ class TestGetObjectStorey(test.bim.bootstrap.NewFile):
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
building = ifc.createIfcBuilding()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=building)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=building)
assert subject.get_object_storey(obj) is None
def test_returning_nothing_if_uncontained(self):
@@ -65,8 +68,8 @@ class TestGetStoreyElevation(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
tool.Ifc.set(ifc)
@@ -77,23 +80,23 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey2], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) == 2.0
def test_getting_a_double_storey_height(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
@@ -102,9 +105,9 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
storey2.Elevation = 5000
storey3 = ifc.createIfcBuildingStorey()
storey3.Elevation = 9000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey3], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey2], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey3], relating_object=building)
assert subject.get_storey_height_in_si(storey, 2) == 6.0
def test_only_considering_storeys_in_the_same_building(self):
@@ -115,7 +118,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) is None
def test_returning_none_if_the_storey_height_is_undefined(self):
@@ -123,7 +126,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) is None
+2 -1
View File
@@ -18,13 +18,14 @@
import bpy
import ifcopenshell
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.type
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import ifcopenshell.util.shape_builder
import bonsai.core.tool
import bonsai.tool as tool
import numpy as np
+3 -1
View File
@@ -18,6 +18,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.spatial
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -72,5 +74,5 @@ class TestGetContainer(NewFile):
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
container = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
ifcopenshell.api.spatial.assign_container(ifc, products=[element], relating_structure=container)
assert subject.get_container(element) == container
+1
View File
@@ -36,5 +36,6 @@ class TestRunMigratePatch(NewFile):
infile = os.path.join(cwd, "..", "files", "ifc2x3.ifc")
outfile = os.path.join(cwd, "..", "files", "temp", "ifc2x3-migrated.ifc")
subject.run_migrate_patch(infile, outfile, "IFC4")
ifc: ifcopenshell.file
ifc = ifcopenshell.open(outfile)
assert ifc.schema == "IFC4"
+5 -4
View File
@@ -18,8 +18,10 @@
import bpy
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.document
import ifcopenshell.api.root
import ifcopenshell.api.unit
import bonsai.core.tool
import bonsai.tool as tool
import tempfile
@@ -106,9 +108,8 @@ class TestSetDefaultContext(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifc.createIfcProject()
model = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
body = ifcopenshell.api.run(
"context.add_context",
model = ifcopenshell.api.context.add_context(ifc, context_type="Model")
body = ifcopenshell.api.context.add_context(
ifc,
parent=model,
context_type="Model",
@@ -125,7 +126,7 @@ class TestSetDefaultModelingDimensions(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifc.createIfcProject()
ifcopenshell.api.run("unit.assign_unit", ifc)
ifcopenshell.api.unit.assign_unit(ifc)
subject.set_default_modeling_dimensions()
props = tool.Model.get_model_props()
assert props.extrusion_depth == 3
+6 -4
View File
@@ -18,6 +18,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import bonsai.core.tool
import bonsai.tool as tool
from bonsai.tool.pset import Pset as subject
@@ -34,7 +36,7 @@ class TestGetElementPset(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo")
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="Foo")
assert subject.get_element_pset(element, "Foo") == pset
@@ -43,9 +45,9 @@ class TestIsPsetEmpty(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo")
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="Foo")
assert subject.is_pset_empty(pset) is True
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": "Bar"})
assert subject.is_pset_empty(pset) is False
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": None})
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": None})
assert subject.is_pset_empty(pset) is True
+15 -12
View File
@@ -19,6 +19,11 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.cost
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.util.pset
import test.bim.bootstrap
import bonsai.core.tool
@@ -58,7 +63,7 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
self.ifc = ifcopenshell.file()
tool.Ifc.set(self.ifc)
ifcopenshell.api.run("root.create_entity", self.ifc, ifc_class="IfcProject", name="My Project")
ifcopenshell.api.root.create_entity(self.ifc, ifc_class="IfcProject", name="My Project")
ifc_import_settings = import_ifc.IfcImportSettings.factory(
bpy.context, tool.Ifc.get_path(), logging.getLogger("ImportIFC")
)
@@ -67,12 +72,12 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
ifc_importer.create_project()
def setup_units(self, units):
ifcopenshell.api.run("unit.assign_unit", self.ifc, **units)
ifcopenshell.api.unit.assign_unit(self.ifc, **units)
def calculate_quantities(self, obj):
import ifc5d.qto
context = ifcopenshell.api.run("context.add_context", self.ifc, context_type="Model")
context = ifcopenshell.api.context.add_context(self.ifc, context_type="Model")
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), size=2)
obj = bpy.context.active_object
element = bonsai.core.root.assign_class(
@@ -183,7 +188,7 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
wall_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
tool.Ifc.link(wall, wall_obj)
product = tool.Ifc.get_entity(wall_obj)
pset_qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_Basefoo")
pset_qto = ifcopenshell.api.pset.add_qto(ifc, product=wall, name="Qto_Basefoo")
assert subject.get_base_qto(product).id() == pset_qto.get_info()["id"]
assert subject.get_base_qto(product).Name == pset_qto.Name
@@ -202,14 +207,12 @@ class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
schedule = ifcopenshell.api.run("cost.add_cost_schedule", ifc)
item = ifcopenshell.api.run("cost.add_cost_item", ifc, cost_schedule=schedule)
ifcopenshell.api.run("cost.edit_cost_item", ifc, cost_item=item, attributes={"Name": "Foo"})
qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_WallBaseQuantities")
ifcopenshell.api.run("pset.edit_qto", ifc, qto=qto, properties={"NetVolume": 42.0})
ifcopenshell.api.run(
"cost.assign_cost_item_quantity", ifc, cost_item=item, products=[wall], prop_name="NetVolume"
)
schedule = ifcopenshell.api.cost.add_cost_schedule(ifc)
item = ifcopenshell.api.cost.add_cost_item(ifc, cost_schedule=schedule)
ifcopenshell.api.cost.edit_cost_item(ifc, cost_item=item, attributes={"Name": "Foo"})
qto = ifcopenshell.api.pset.add_qto(ifc, product=wall, name="Qto_WallBaseQuantities")
ifcopenshell.api.pset.edit_qto(ifc, qto=qto, properties={"NetVolume": 42.0})
ifcopenshell.api.cost.assign_cost_item_quantity(ifc, cost_item=item, products=[wall], prop_name="NetVolume")
assert subject.get_related_cost_item_quantities(wall)[0]["cost_item_name"] == "Foo"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_name"] == "NetVolume"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_value"] == 42
+5 -3
View File
@@ -19,6 +19,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.feature
import ifcopenshell.api.type
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -74,8 +76,8 @@ class TestGetDecompositionRelationships(NewFile):
element = ifc.createIfcWall()
opening = ifc.createIfcOpeningElement()
fill = ifc.createIfcWindow()
ifcopenshell.api.run("feature.add_feature", ifc, feature=opening, element=element)
ifcopenshell.api.run("feature.add_filling", ifc, opening=opening, element=fill)
ifcopenshell.api.feature.add_feature(ifc, feature=opening, element=element)
ifcopenshell.api.feature.add_filling(ifc, opening=opening, element=fill)
obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(fill, obj)
@@ -99,7 +101,7 @@ class TestGetElementType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_element_type(element) == type
+6 -4
View File
@@ -20,6 +20,8 @@ import numpy as np
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import bonsai.core.tool
import bonsai.tool as tool
from bonsai.tool.spatial import Spatial as subject
@@ -158,7 +160,7 @@ class TestGetContainer(NewFile):
ifc = ifcopenshell.file()
site = ifc.createIfcSite()
wall = ifc.createIfcWall()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=site)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=site)
assert subject.get_container(wall) == site
@@ -167,7 +169,7 @@ class TestGetDecomposedElements(NewFile):
ifc = ifcopenshell.file()
site = ifc.createIfcSite()
wall = ifc.createIfcWall()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=site)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=site)
assert subject.get_decomposed_elements(site) == {wall}
@@ -227,7 +229,7 @@ class TestSelectProducts(NewFile):
def test_select_products(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
product = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(product, obj)
@@ -240,7 +242,7 @@ class TestGenerateSpace(NewFile):
bpy.ops.bim.create_project()
ifc = tool.Ifc.get()
scene = bpy.context.scene
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
product = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4))
obj = bpy.data.objects["Cube"]
scene.collection.objects.link(obj)
+2 -1
View File
@@ -20,6 +20,7 @@ import os
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.util.representation
import bonsai.core.tool
import bonsai.tool as tool
@@ -105,7 +106,7 @@ class TestGetElementsByStyle(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
style = ifc.createIfcSurfaceStyle()
item = ifc.createIfcExtrudedAreaSolid()
ifc.createIfcStyledItem(Item=item, Styles=[style])
+5 -3
View File
@@ -20,6 +20,8 @@ import bpy
import numpy as np
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.util.geolocation
import test.bim.bootstrap
@@ -42,9 +44,9 @@ class TestGetGlobalMatrix(test.bim.bootstrap.NewFile):
def test_applying_an_object_placement_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
+12 -12
View File
@@ -19,6 +19,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.system
import ifcopenshell.util.unit
import bonsai.core.tool
import bonsai.tool as tool
@@ -150,9 +152,9 @@ class TestExportSystemAttributes(NewFile):
class TestGetConnectedPort(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
port1 = ifcopenshell.api.run("system.add_port", ifc)
port2 = ifcopenshell.api.run("system.add_port", ifc)
ifcopenshell.api.run("system.connect_port", ifc, port1=port1, port2=port2)
port1 = ifcopenshell.api.system.add_port(ifc)
port2 = ifcopenshell.api.system.add_port(ifc)
ifcopenshell.api.system.connect_port(ifc, port1=port1, port2=port2)
assert subject.get_connected_port(port1) == port2
assert subject.get_connected_port(port2) == port1
@@ -163,7 +165,7 @@ class TestGetPorts(NewFile):
tool.Ifc().set(ifc)
element = ifc.createIfcDuctSegment()
port = ifc.createIfcDistributionPort()
ifcopenshell.api.run("system.assign_port", ifc, element=element, port=port)
ifcopenshell.api.system.assign_port(ifc, element=element, port=port)
assert subject.get_ports(element) == [port]
@@ -268,9 +270,9 @@ class TestSelectSystemProducts(NewFile):
assert bpy.context.scene
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
ifcopenshell.api.run("system.assign_system", ifc, products=[element], system=system)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcPump")
system = ifcopenshell.api.system.add_system(ifc, ifc_class="IfcSystem")
ifcopenshell.api.system.assign_system(ifc, products=[element], system=system)
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
@@ -282,7 +284,7 @@ class TestSetActiveSystem(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
system = ifcopenshell.api.system.add_system(ifc, ifc_class="IfcSystem")
subject.set_active_edited_system(system)
props = tool.System.get_system_props()
assert props.edited_system_id == system.id()
@@ -298,14 +300,12 @@ class TestFlowElementAndControls(NewFile):
assert len(subject.get_flow_element_controls(flow_element)) == 0
assert subject.get_flow_control_flow_element(flow_control) == None
ifcopenshell.api.run(
"system.assign_flow_control",
ifcopenshell.api.system.assign_flow_control(
ifc,
related_flow_control=flow_control,
relating_flow_element=flow_element,
)
ifcopenshell.api.run(
"system.assign_flow_control",
ifcopenshell.api.system.assign_flow_control(
ifc,
related_flow_control=flow_control1,
relating_flow_element=flow_element,
+1 -1
View File
@@ -122,7 +122,7 @@ class TestGetModelTypes(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
type_classes = ("IfcWallType", "IfcDoorStyle", "IfcWindowStyle", "IfcTypeProduct")
types = [ifcopenshell.api.run("root.create_entity", ifc, ifc_class=c) for c in type_classes]
types = [ifcopenshell.api.root.create_entity(ifc, ifc_class=c) for c in type_classes]
assert set(subject.get_model_types()) == set(types)