Let us create a pink ifc column using profile representation
# Create column using profile representation
import bpy
import ifcopenshell
from ifcopenshell.api import run
import numpy
# Create a blank model
model = ifcopenshell.file()
# All projects must have one IFC Project element
project = run("root.create_entity", 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
# Assigning without arguments defaults to metric units
run("unit.assign_unit", model)
# Let's create a modeling geometry context, so we can store 3D geometry (note: IFC supports 2D too!)
context = run("context.add_context", model, context_type="Model")
# In particular, in this example we want to store the 3D "body" geometry of objects, i.e. the body shape
body = run("context.add_context", model, context_type="Model",
context_identifier="Body", target_view="MODEL_VIEW", parent=context)
# Create a site, building, and storey. Many hierarchies are possible.
site = run("root.create_entity", model, ifc_class="IfcSite", name="My Site")
building = run("root.create_entity", model, ifc_class="IfcBuilding", name="Building A")
storey = run("root.create_entity", model, ifc_class="IfcBuildingStorey", name="Ground Floor")
# 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
run("aggregate.assign_object", model, relating_object=project, product=site)
run("aggregate.assign_object", model, relating_object=site, product=building)
run("aggregate.assign_object", model, relating_object=building, product=storey)
# in this part we define some values for our position matrix
x=1
y=2
z=0
rot = 90
# opening offset o and the elevation zw
o=1
zw = 0
# Geometry properties - length, height, tickness, window/opening length, window/heigth length,
l=5
h=0.5
t=0.25
lw=0.9
hw =2.1
# Create a 4x4 identity matrix. This matrix is at the origin with no rotation.
matrix = numpy.eye(4)
matrixw = numpy.eye(4)
# Rotate the matix (rot) degrees (ex. 90 degrees) anti-clockwise around the Z axis (i.e. in plan).
# Anti-clockwise is positive. Clockwise is negative.
matrix = ifcopenshell.util.placement.rotation(rot, "Z") @ matrix
matrixw = ifcopenshell.util.placement.rotation(rot, "Z") @ matrixw
# Set the X, Y, Z coordinates. Notice how we rotate first then translate.
# This is because the rotation origin is always at 0, 0, 0.
matrix[:,3][0:3] = (x, y, z)
if rot==0:
matrixw[:,3][0:3] = (x+o, y, zw)
elif rot==90:
matrixw[:,3][0:3] = (x, y+o, zw)
#Let us create a ifccolumn
column = run("root.create_entity", model, ifc_class="IfcColumn", name="ColumnE"+str(1))
# Rectangles (or squares) are typically used for concrete columns and beams
profile = model.create_entity("IfcRectangleProfileDef", ProfileName="300x300", ProfileType="AREA",
XDim=300, YDim=300)
# A profile-based representation, 1 meter long
representation = run("geometry.add_profile_representation", model, context=body, profile=profile, depth=2.8)
# Assign our new body geometry back to our column
run("geometry.assign_representation", model, product=column, representation=representation)
# Assign the column to our coordinates defined by the matrix
run("geometry.edit_object_placement", model, product=column, matrix=matrix, is_si=True)
# Let's prepare a concrete material. Note that our concrete material
# does not have any colours (styles) at this point.
concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete")
# Assign our concrete material to our beam
ifcopenshell.api.run("material.assign_material", model, product=column, type="IfcMaterial", material=concrete)
# Create a new surface style
style = ifcopenshell.api.run("style.add_style", model)
# Create a simple pink column shading colour and transparency.
ifcopenshell.api.run("style.add_surface_style", model,
style=style, ifc_class="IfcSurfaceStyleShading", attributes={
"SurfaceColour": { "Name": None, "Red": 0.50, "Green": 0.1, "Blue": 0.80},
"Transparency": 0.5, # 0 is opaque, 1 is transparent
})
# Now any element (like our column) with a concrete material will have
# a pink colour applied.
ifcopenshell.api.run("style.assign_material_style", model, material=concrete, style=style, context=body)
# Assign the column to the spacial structure (storey)
rel_contained_in_spatial_structure = model.createIfcRelContainedInSpatialStructure(GlobalId = ifcopenshell.guid.new(), RelatedElements = [column], RelatingStructure=storey)
# Write out to a file
model.write("C:\\Users\\ionut.ciuntuc\\Desktop\\teste\\TestIFCOpenShell.ifc")
bpy.ops.bim.load_project(filepath="C:\\Users\\ionut.ciuntuc\\Desktop\\teste\\TestIFCOpenShell.ifc", use_relative_path=False, should_start_fresh_session=False)