mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -22,46 +22,49 @@ import ifcopenshell.util.placement
|
||||
from mathutils import Matrix # For now, we depend on Blender
|
||||
|
||||
|
||||
def create_axis_curve(file, axis_curve=None, grid_axis=None) -> None:
|
||||
"""Adds curve geometry to a grid axis to represent the axis extents
|
||||
|
||||
This currently depends on the Blender geometry kernel to function.
|
||||
|
||||
An IFC grid will have a minimum of two axes (typically perpendicular). Each
|
||||
axis will then have a line which represents the extents of the axis.
|
||||
|
||||
:param axis_curve: The Blender object that contains a mesh data block with a
|
||||
single edge.
|
||||
:type axis_curve: bpy.types.Object
|
||||
:param grid_axis: The IfcGridAxis element to add geometry to.
|
||||
:type grid_axis: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# A pretty standard rectangular grid, with only two axes.
|
||||
grid = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcGrid")
|
||||
axis_a = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
||||
axis_1 = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# Assume you have these Blender objects in your active Blender session
|
||||
obj1 = bpy.data.objects.get("AxisA")
|
||||
obj2 = bpy.data.objects.get("Axis1")
|
||||
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj1, grid_axis=axis_a)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj2, grid_axis=axis_1)
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {
|
||||
"axis_curve": axis_curve, # A Blender object
|
||||
"grid_axis": grid_axis,
|
||||
}
|
||||
return usecase.execute()
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, axis_curve=None, grid_axis=None):
|
||||
"""Adds curve geometry to a grid axis to represent the axis extents
|
||||
|
||||
This currently depends on the Blender geometry kernel to function.
|
||||
|
||||
An IFC grid will have a minimum of two axes (typically perpendicular). Each
|
||||
axis will then have a line which represents the extents of the axis.
|
||||
|
||||
:param axis_curve: The Blender object that contains a mesh data block with a
|
||||
single edge.
|
||||
:type axis_curve: bpy.types.Object
|
||||
:param grid_axis: The IfcGridAxis element to add geometry to.
|
||||
:type grid_axis: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# A pretty standard rectangular grid, with only two axes.
|
||||
grid = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcGrid")
|
||||
axis_a = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
||||
axis_1 = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# Assume you have these Blender objects in your active Blender session
|
||||
obj1 = bpy.data.objects.get("AxisA")
|
||||
obj2 = bpy.data.objects.get("Axis1")
|
||||
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj1, grid_axis=axis_a)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj2, grid_axis=axis_1)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"axis_curve": axis_curve, # A Blender object
|
||||
"grid_axis": grid_axis,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
existing_curve = self.settings["grid_axis"].AxisCurve
|
||||
if existing_curve and len(self.file.get_inverse(existing_curve)) == 1:
|
||||
|
||||
Reference in New Issue
Block a user