mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
Fix missing imports and don't use api.run
This commit is contained in:
@@ -25,6 +25,7 @@ import zipfile
|
|||||||
import tempfile
|
import tempfile
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.placement
|
import ifcopenshell.util.placement
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import numpy as np
|
|||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api.pset
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
import ifcopenshell.ifcopenshell_wrapper as W
|
import ifcopenshell.ifcopenshell_wrapper as W
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
@@ -1237,8 +1238,7 @@ class IfcImporter:
|
|||||||
if not pset:
|
if not pset:
|
||||||
return
|
return
|
||||||
if "Aggregate_Index" not in pset.keys():
|
if "Aggregate_Index" not in pset.keys():
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.pset.edit_pset(
|
||||||
"pset.edit_pset",
|
|
||||||
self.file,
|
self.file,
|
||||||
pset=self.file.by_id(pset["id"]),
|
pset=self.file.by_id(pset["id"]),
|
||||||
properties={"Aggregate_Index": aggregate_index, "Name": name},
|
properties={"Aggregate_Index": aggregate_index, "Name": name},
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import ifcopenshell
|
|||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.api.group
|
import ifcopenshell.api.group
|
||||||
import ifcopenshell.api.pset
|
import ifcopenshell.api.pset
|
||||||
|
import ifcopenshell.api.root
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import bonsai.core.aggregate as core
|
import bonsai.core.aggregate as core
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import math
|
import math
|
||||||
|
import ifcopenshell.util.element
|
||||||
import mathutils.geometry
|
import mathutils.geometry
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import bonsai.core.geometry
|
|||||||
import bonsai.core.geometry as core
|
import bonsai.core.geometry as core
|
||||||
import bonsai.core.aggregate
|
import bonsai.core.aggregate
|
||||||
import bonsai.core.nest
|
import bonsai.core.nest
|
||||||
|
import bonsai.core.spatial
|
||||||
import bonsai.core.style
|
import bonsai.core.style
|
||||||
import bonsai.core.root
|
import bonsai.core.root
|
||||||
import bonsai.core.drawing
|
import bonsai.core.drawing
|
||||||
|
|||||||
@@ -38,12 +38,15 @@ import bonsai.core.geometry
|
|||||||
import bonsai.core.type
|
import bonsai.core.type
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.geometry
|
||||||
import ifcopenshell.api.context
|
import ifcopenshell.api.context
|
||||||
import ifcopenshell.api.drawing
|
import ifcopenshell.api.drawing
|
||||||
import ifcopenshell.api.document
|
import ifcopenshell.api.document
|
||||||
import ifcopenshell.api.pset
|
import ifcopenshell.api.pset
|
||||||
import ifcopenshell.api.root
|
import ifcopenshell.api.root
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
|
import ifcopenshell.util.placement
|
||||||
|
import ifcopenshell.util.unit
|
||||||
import ifcopenshell.util.representation
|
import ifcopenshell.util.representation
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.selector
|
import ifcopenshell.util.selector
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import ifcopenshell.api.classification
|
|||||||
import ifcopenshell.api.group
|
import ifcopenshell.api.group
|
||||||
import ifcopenshell.api.material
|
import ifcopenshell.api.material
|
||||||
import ifcopenshell.api.nest
|
import ifcopenshell.api.nest
|
||||||
|
import ifcopenshell.api.owner.settings
|
||||||
import ifcopenshell.api.pset
|
import ifcopenshell.api.pset
|
||||||
import ifcopenshell.api.root
|
import ifcopenshell.api.root
|
||||||
import ifcopenshell.api.spatial
|
import ifcopenshell.api.spatial
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api.aggregate
|
||||||
|
import ifcopenshell.api.context
|
||||||
import ifcopenshell.api.feature
|
import ifcopenshell.api.feature
|
||||||
|
import ifcopenshell.api.geometry
|
||||||
|
import ifcopenshell.api.root
|
||||||
|
import ifcopenshell.api.spatial
|
||||||
|
import ifcopenshell.api.type
|
||||||
|
import ifcopenshell.api.unit
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.representation
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -33,9 +41,8 @@ class Context:
|
|||||||
if body:
|
if body:
|
||||||
self.body = body[0]
|
self.body = body[0]
|
||||||
else:
|
else:
|
||||||
context = ifcopenshell.api.run("context.add_context", self.model, context_type="Model")
|
context = ifcopenshell.api.context.add_context(self.model, context_type="Model")
|
||||||
self.body = ifcopenshell.api.run(
|
self.body = ifcopenshell.api.context.add_context(
|
||||||
"context.add_context",
|
|
||||||
self.model,
|
self.model,
|
||||||
context_type="Model",
|
context_type="Model",
|
||||||
context_identifier="Body",
|
context_identifier="Body",
|
||||||
@@ -48,9 +55,8 @@ class Context:
|
|||||||
if body:
|
if body:
|
||||||
self.axis = axis[0]
|
self.axis = axis[0]
|
||||||
else:
|
else:
|
||||||
context = ifcopenshell.api.run("context.add_context", self.model, context_type="Model")
|
context = ifcopenshell.api.context.add_context(self.model, context_type="Model")
|
||||||
self.axis = ifcopenshell.api.run(
|
self.axis = ifcopenshell.api.context.add_context(
|
||||||
"context.add_context",
|
|
||||||
self.model,
|
self.model,
|
||||||
context_type="Model",
|
context_type="Model",
|
||||||
context_identifier="Axis",
|
context_identifier="Axis",
|
||||||
@@ -63,23 +69,21 @@ class Context:
|
|||||||
# Create a blank model
|
# Create a blank model
|
||||||
self.model = ifcopenshell.file()
|
self.model = ifcopenshell.file()
|
||||||
# All projects must have one IFC Project element
|
# All projects must have one IFC Project element
|
||||||
project = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcProject", name="My Project")
|
project = ifcopenshell.api.root.create_entity(self.model, ifc_class="IfcProject", name="My Project")
|
||||||
# Geometry is optional in IFC, but because we want to use geometry in this example, let's define units
|
# Geometry is optional in IFC, but because we want to use geometry in this example, let's define units
|
||||||
# Assigning without arguments defaults to metric units
|
# Assigning without arguments defaults to metric units
|
||||||
ifcopenshell.api.run("unit.assign_unit", self.model)
|
ifcopenshell.api.unit.assign_unit(self.model)
|
||||||
# Let's create a modeling geometry context, so we can store 3D geometry (note: IFC supports 2D too!)
|
# Let's create a modeling geometry context, so we can store 3D geometry (note: IFC supports 2D too!)
|
||||||
context = ifcopenshell.api.run("context.add_context", self.model, context_type="Model")
|
context = ifcopenshell.api.context.add_context(self.model, context_type="Model")
|
||||||
# In particular, in this example we want to store the 3D "body" geometry of objects, i.e. the body shape
|
# In particular, in this example we want to store the 3D "body" geometry of objects, i.e. the body shape
|
||||||
self.body = ifcopenshell.api.run(
|
self.body = ifcopenshell.api.context.add_context(
|
||||||
"context.add_context",
|
|
||||||
self.model,
|
self.model,
|
||||||
context_type="Model",
|
context_type="Model",
|
||||||
context_identifier="Body",
|
context_identifier="Body",
|
||||||
target_view="MODEL_VIEW",
|
target_view="MODEL_VIEW",
|
||||||
parent=context,
|
parent=context,
|
||||||
)
|
)
|
||||||
self.axis = ifcopenshell.api.run(
|
self.axis = ifcopenshell.api.context.add_context(
|
||||||
"context.add_context",
|
|
||||||
self.model,
|
self.model,
|
||||||
context_type="Model",
|
context_type="Model",
|
||||||
context_identifier="Axis",
|
context_identifier="Axis",
|
||||||
@@ -87,30 +91,26 @@ class Context:
|
|||||||
parent=context,
|
parent=context,
|
||||||
)
|
)
|
||||||
# Create a site, building, and storey. Many hierarchies are possible.
|
# Create a site, building, and storey. Many hierarchies are possible.
|
||||||
site = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcSite", name="My Site")
|
site = ifcopenshell.api.root.create_entity(self.model, ifc_class="IfcSite", name="My Site")
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcBuilding", name="Building A")
|
building = ifcopenshell.api.root.create_entity(self.model, ifc_class="IfcBuilding", name="Building A")
|
||||||
self.storey = ifcopenshell.api.run(
|
self.storey = ifcopenshell.api.root.create_entity(
|
||||||
"root.create_entity",
|
|
||||||
self.model,
|
self.model,
|
||||||
ifc_class="IfcBuildingStorey",
|
ifc_class="IfcBuildingStorey",
|
||||||
name="Ground Floor",
|
name="Ground Floor",
|
||||||
)
|
)
|
||||||
# Since the site is our top level location, assign it to the project
|
# Since the site is our top level location, assign it to the project
|
||||||
# Then place our building on the site, and our storey in the building
|
# Then place our building on the site, and our storey in the building
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.aggregate.assign_object(
|
||||||
"aggregate.assign_object",
|
|
||||||
self.model,
|
self.model,
|
||||||
relating_object=project,
|
relating_object=project,
|
||||||
products=[site],
|
products=[site],
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.aggregate.assign_object(
|
||||||
"aggregate.assign_object",
|
|
||||||
self.model,
|
self.model,
|
||||||
relating_object=site,
|
relating_object=site,
|
||||||
products=[building],
|
products=[building],
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.aggregate.assign_object(
|
||||||
"aggregate.assign_object",
|
|
||||||
self.model,
|
self.model,
|
||||||
relating_object=building,
|
relating_object=building,
|
||||||
products=[self.storey],
|
products=[self.storey],
|
||||||
@@ -120,30 +120,26 @@ class Context:
|
|||||||
p1 = np.array([p1[0], p1[1]])
|
p1 = np.array([p1[0], p1[1]])
|
||||||
p2 = np.array([p2[0], p2[1]])
|
p2 = np.array([p2[0], p2[1]])
|
||||||
|
|
||||||
wall = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcWall")
|
wall = ifcopenshell.api.root.create_entity(self.model, ifc_class="IfcWall")
|
||||||
length = float(np.linalg.norm(p2 - p1))
|
length = float(np.linalg.norm(p2 - p1))
|
||||||
representation = ifcopenshell.api.run(
|
representation = ifcopenshell.api.geometry.add_wall_representation(
|
||||||
"geometry.add_wall_representation",
|
|
||||||
self.model,
|
self.model,
|
||||||
context=self.body,
|
context=self.body,
|
||||||
length=length,
|
length=length,
|
||||||
height=height,
|
height=height,
|
||||||
thickness=thickness,
|
thickness=thickness,
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.geometry.assign_representation(
|
||||||
"geometry.assign_representation",
|
|
||||||
self.model,
|
self.model,
|
||||||
product=wall,
|
product=wall,
|
||||||
representation=representation,
|
representation=representation,
|
||||||
)
|
)
|
||||||
representation = ifcopenshell.api.run(
|
representation = ifcopenshell.api.geometry.add_axis_representation(
|
||||||
"geometry.add_axis_representation",
|
|
||||||
self.model,
|
self.model,
|
||||||
context=self.axis,
|
context=self.axis,
|
||||||
axis=[(0.0, 0.0), (length, 0.0)],
|
axis=[(0.0, 0.0), (length, 0.0)],
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.geometry.assign_representation(
|
||||||
"geometry.assign_representation",
|
|
||||||
self.model,
|
self.model,
|
||||||
product=wall,
|
product=wall,
|
||||||
representation=representation,
|
representation=representation,
|
||||||
@@ -158,16 +154,14 @@ class Context:
|
|||||||
[0, 0, 0, 1],
|
[0, 0, 0, 1],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.model, product=wall, matrix=matrix)
|
ifcopenshell.api.geometry.edit_object_placement(self.model, product=wall, matrix=matrix)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.spatial.assign_container(
|
||||||
"spatial.assign_container",
|
|
||||||
self.model,
|
self.model,
|
||||||
relating_structure=container,
|
relating_structure=container,
|
||||||
products=[wall],
|
products=[wall],
|
||||||
)
|
)
|
||||||
if wall_type:
|
if wall_type:
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.type.assign_type(
|
||||||
"type.assign_type",
|
|
||||||
self.model,
|
self.model,
|
||||||
related_object=wall,
|
related_object=wall,
|
||||||
relating_type=wall_type,
|
relating_type=wall_type,
|
||||||
@@ -196,20 +190,19 @@ class Context:
|
|||||||
body = ifcopenshell.util.representation.get_context(self.model, "Model", "Body", "MODEL_VIEW")
|
body = ifcopenshell.util.representation.get_context(self.model, "Model", "Body", "MODEL_VIEW")
|
||||||
representation_data = props.to_dict(si_conversion=si_conversion)
|
representation_data = props.to_dict(si_conversion=si_conversion)
|
||||||
representation_data["context"] = body
|
representation_data["context"] = body
|
||||||
door_representation = ifcopenshell.api.run(
|
if ty == "door":
|
||||||
f"geometry.add_{ty}_representation", self.model, **representation_data
|
door_representation = ifcopenshell.api.geometry.add_door_representation(self.model, **representation_data)
|
||||||
)
|
else:
|
||||||
door = ifcopenshell.api.run("root.create_entity", self.model, ifc_class=f"ifc{ty}")
|
door_representation = ifcopenshell.api.geometry.add_window_representation(self.model, **representation_data)
|
||||||
|
door = ifcopenshell.api.root.create_entity(self.model, ifc_class=f"ifc{ty}")
|
||||||
door.OverallWidth = props.overall_width / si_conversion
|
door.OverallWidth = props.overall_width / si_conversion
|
||||||
door.OverallHeight = props.overall_height / si_conversion
|
door.OverallHeight = props.overall_height / si_conversion
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.geometry.assign_representation(
|
||||||
"geometry.assign_representation",
|
|
||||||
self.model,
|
self.model,
|
||||||
product=door,
|
product=door,
|
||||||
representation=door_representation,
|
representation=door_representation,
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.spatial.assign_container(
|
||||||
"spatial.assign_container",
|
|
||||||
self.model,
|
self.model,
|
||||||
relating_structure=self.storey,
|
relating_structure=self.storey,
|
||||||
products=[door],
|
products=[door],
|
||||||
@@ -238,8 +231,7 @@ class Context:
|
|||||||
v_dot_v = np.dot(v, v)
|
v_dot_v = np.dot(v, v)
|
||||||
t = AP_dot_v / v_dot_v * np.linalg.norm(v) / si_conversion
|
t = AP_dot_v / v_dot_v * np.linalg.norm(v) / si_conversion
|
||||||
|
|
||||||
opening = ifcopenshell.api.run(
|
opening = ifcopenshell.api.root.create_entity(
|
||||||
"root.create_entity",
|
|
||||||
self.model,
|
self.model,
|
||||||
ifc_class="IfcOpeningElement",
|
ifc_class="IfcOpeningElement",
|
||||||
predefined_type="OPENING",
|
predefined_type="OPENING",
|
||||||
|
|||||||
Reference in New Issue
Block a user