mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-20 04:04:00 +00:00
replace api.run with static methods
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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)},
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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={
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user