mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
replace api.run with static methods
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user