Tak, mogę pomóc w przygotowaniu kodu generującego model 3D konstrukcji stalowej w formacie IFC (Industry Foundation Classes). Poniżej znajdziesz kompletny przykład w języku Python z użyciem biblioteki ifcopenshell, który tworzy prostą konstrukcję stalową (słupy i belki) i eksportuje ją do pliku .ifc.
Wymagania wstępne:
Zainstaluj bibliotekę:
bash
pip install ifcopenshell
Przykładowy kod:
python
import ifcopenshell
import ifcopenshell.util.placement
import numpy as np
from mathutils import Matrix
# Utwórz pusty plik IFC (schema IFC4)
file = ifcopenshell.file(schema="IFC4")
# Podstawowe jednostki
length_unit = file.createIfcSIUnit("LENGTHUNIT", None, "METRE")
area_unit = file.createIfcSIUnit("AREAUNIT", None, "SQUARE_METRE")
volume_unit = file.createIfcSIUnit("VOLUMEUNIT", None, "CUBIC_METRE")
unit_assignment = file.createIfcUnitAssignment((length_unit, area_unit, volume_unit))
# Kontekst projektu
project = file.createIfcProject(
GlobalId=ifcopenshell.guid.new(),
Name="Moja Konstrukcja Stalowa",
UnitsInContext=unit_assignment
)
# Kontekst geometrii
model_context = file.createIfcGeometricRepresentationContext(
None, "Model", 3, 1.0E-5, None, None
)
# Tworzenie układu współrzędnych
local_placement = ifcopenshell.util.placement.axis2placement(
file, location=(0.0, 0.0, 0.0)
)
# Tworzenie obiektu budynku
building = file.createIfcBuilding(
GlobalId=ifcopenshell.guid.new(),
Name="Budynoek",
ObjectPlacement=local_placement
)
file.createIfcRelAggregates(ifcopenshell.guid.new(), None, None, project, [building])
# Tworzenie piętra
building_storey = file.createIfcBuildingStorey(
GlobalId=ifcopenshell.guid.new(),
Name="Piętro 0",
ObjectPlacement=local_placement,
Elevation=0.0
)
file.createIfcRelAggregates(ifcopenshell.guid.new(), None, None, building, [building_storey])
# Definicja materiału (stal)
steel = file.createIfcMaterial("STAL S355")
material_layer = file.createIfcMaterialLayer(steel, 0.02, None)
layer_set = file.createIfcMaterialLayerSet([material_layer], "Stalowy zestaw")
layer_set_usage = file.createIfcMaterialLayerSetUsage(layer_set, "AXIS2", "POSITIVE", 0.0)
# Definicja profilu stalowego (prostokątna rura)
profile_def = file.createIfcRectangleProfileDef(
"AREA",
"RURA 100x50x5",
file.createIfcAxis2Placement2D(
file.createIfcCartesianPoint((0.0, 0.0)),
100.0, # Szerokość (mm)
50.0 # Wysokość (mm)
)
)
# Tworzenie elementów konstrukcyjnych
def create_steel_element(name, start_point, end_point, profile_def, material):
# Utwórz krzywą (linię)
line = file.createIfcLine(
file.createIfcCartesianPoint(start_point),
file.createIfcDirection((end_point[0]-start_point[0], end_point[1]-start_point[1], end_point[2]-start_point[2]))
)
curve = file.createIfcTrimmedCurve(line, (0.0,), (1.0,), True)
axis_representation = file.createIfcShapeRepresentation(
model_context,
"Axis",
"Curve3D",
[curve]
)
# Utwórz reprezentację profilu
profile_rep = file.createIfcShapeRepresentation(
model_context,
"Body",
"SweptSolid",
[file.createIfcExtrudedAreaSolid(
profile_def,
file.createIfcAxis2Placement3D(
file.createIfcCartesianPoint((0,0,0)),
file.createIfcDirection((0,0,1)),
file.createIfcDirection((1,0,0))
),
file.createIfcDirection((0,0,1)),
3000.0 # Długość (mm)
)]
)
# Połącz reprezentacje
product_shape = file.createIfcProductDefinitionShape(
None, None, [axis_representation, profile_rep]
)
# Utwórz element
element = file.createIfcBuildingElementProxy(
GlobalId=ifcopenshell.guid.new(),
Name=name,
ObjectPlacement=ifcopenshell.util.placement.axis2placement(
file, location=start_point, axis=(1,0,0), ref_direction=(0,1,0)
),
Representation=product_shape
)
# Przypisz materiał
rel_associates = file.createIfcRelAssociatesMaterial(
ifcopenshell.guid.new(),
None,
None,
[element],
material
)
return element
# Definicja punktów konstrukcji
points = [
(0.0, 0.0, 0.0), # Słup 1
(5000.0, 0.0, 0.0), # Słup 2
(0.0, 5000.0, 0.0), # Słup 3
(5000.0, 5000.0, 0.0) # Słup 4
]
# Tworzenie słupów
columns = []
for i, point in enumerate(points):
column = create_steel_element(
f"Słup {i+1}",
point,
(point[0], point[1], 4000.0), # Wysokość 4000 mm
profile_def,
layer_set_usage
)
columns.append(column)
# Tworzenie belek
beams = []
beam_points = [
(points[0], points[1]), # Belka między słupem 1 a 2
(points[2], points[3]), # Belka między słupem 3 a 4
(points[0], points[2]), # Belka między słupem 1 a 3
(points[1], points[3]) # Belka między słupem 2 a 4
]
for i, (start, end) in enumerate(beam_points):
beam = create_steel_element(
f"Belka {i+1}",
start,
end,
profile_def,
layer_set_usage
)
beams.append(beam)
# Dodaj wszystkie elementy do piętra
elements = columns + beams
for element in elements:
file.createIfcRelContainedInSpatialStructure(
ifcopenshell.guid.new(),
None,
None,
[element],
building_storey
)
# Zapisz plik IFC
file.write("konstrukcja_stalowa.ifc")
print("Plik IFC wygenerowany: konstrukcja_stalowa.ifc")
Co robi ten kod?
Tworzy projekt IFC z podstawowymi jednostkami (metry).
Definiuje:
Materiał: stal S355,
Profil: prostokątna rura 100x50 mm.
Generuje:
4 słupy (wysokość 4 m),
4 belki (łączące słupy).
Eksportuje model do pliku konstrukcja_stalowa.ifc.