import bpyimport ifcopenshellfrom ifcopenshell.api import runimport numpy# Create a blank modelmodel = ifcopenshell.file()# All projects must have one IFC Project elementproject = 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 unitsrun("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 shapebody = 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 buildingrun("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 matrixx=1y=2z=0rot = 90# opening offset o and the elevation zwo=1zw = 0# Geometry properties - length, height, tickness, window/opening length, window/heigth length, l=5h=0.5t=0.25lw=0.9hw =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") @ matrixmatrixw = 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))#Just for showXD = 500YD = 500builder = ifcopenshell.util.shape_builder.ShapeBuilder(model)outer_curve = builder.polyline([(0.,0.), (2000.,300.), (4000.,0.), (4000.,550.), (2000.,1050.), (0.,250.)], arc_points=[1, 2, 4, 5], closed=True)profile = builder.profile(outer_curve, name="Arbitrary")# A profile-based representation, 1 meter longrepresentation = run("geometry.add_profile_representation", model, context=body, profile=profile, depth=2.8) # Assign our new body geometry back to our columnrun("geometry.assign_representation", model, product=column, representation=representation) # Assign the column to our coordinates defined by the matrixrun("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 beamifcopenshell.api.run("material.assign_material", model, product=column, type="IfcMaterial", material=concrete)# Create a new surface stylestyle = 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 filemodel.write("C:\\Users\\ciunt\\OneDrive\\Desktop\\test.ifc")bpy.ops.bim.load_project(filepath="C:\\Users\\ciunt\\OneDrive\\Desktop\\test.ifc", use_relative_path=False, should_start_fresh_session=False)