import ifcopenshell import ifcopenshell.api ifcPath = r"C:\Users\sondr\OneDrive\Documents\ifcExamples\newTest.ifc" #-------------- Create the IFC template ------------------------ O = 0., 0., 0.; X = 1., 0., 0.; Y = 0., 1., 0.; Z = 0., 0., 1. def create_ifclocalplacement(f, point=O, dir1=Z, dir2=X, relative_to=None): axis2placement = create_ifcaxis2placement(f, point, dir1, dir2) ifclocalplacement2 = f.createIfcLocalPlacement(relative_to, axis2placement) return ifclocalplacement2 def create_ifcaxis2placement(f, point=O, dir1=Z, dir2=X): point = f.createIfcCartesianPoint(point) dir1 = f.createIfcDirection(dir1) dir2 = f.createIfcDirection(dir2) axis2placement = f.createIfcAxis2Placement3D(point, dir1, dir2) return axis2placement ifc_file = ifcopenshell.api.run("project.create_file", version="IFC4") person = ifcopenshell.api.run("owner.add_person", ifc_file, identification="SBE", family_name="SBE@AAJ", given_name="SBE") org = ifcopenshell.api.run("owner.add_organisation", ifc_file, identification="AAJ", name="AAJ") user = ifcopenshell.api.run("owner.add_person_and_organisation", ifc_file, person=person, organisation=org) application = ifcopenshell.api.run("owner.add_application", ifc_file) project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject", name="TEST") lengthunit = ifcopenshell.api.run("unit.add_si_unit", ifc_file, unit_type="LENGTHUNIT", name="METRE") unitAssignment = ifcopenshell.api.run("unit.assign_unit", ifc_file, units=[lengthunit]) model = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Model") context = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW",parent=model,) site = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcSite", name="My Site") building = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuilding", name="My Building") storey = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey", name="My Storey") aggregation1 = ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=site, relating_object=project) aggregation2 = ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=building, relating_object=site) aggregation3 = ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=storey, relating_object=building) origin = ifc_file.createIfcAxis2Placement3D(ifc_file.createIfcCartesianPoint((0.0, 0.0, 0.0)), ifc_file.createIfcDirection((0.0, 0.0, 1.0)),ifc_file.createIfcDirection((1.0, 0.0, 0.0)),) placement = ifc_file.createIfcLocalPlacement(None, origin) history = ifcopenshell.api.run("owner.create_owner_history", ifc_file) #---------------------------------------------------------------------------------- # Create a NURBS Brep: edgeStartEndLists = [[((0.0, 0.0, 0.0), (4.999999999999998, 10.0, 0.0)), ((4.999999999999998, 10.0, 0.0), (8.868778280542987, 6.8325791855203635, 10.0)), ((8.868778280542987, 6.8325791855203635, 10.0), (5.0, 0.0, 10.0)), ((5.0, 0.0, 10.0), (0.0, 0.0, 0.0))], [((0.0, 0.0, 0.0), (3.0, 0.0, 0.0)), ((3.0, 0.0, 0.0), (7.999999999999998, 10.0, 0.0)), ((7.999999999999998, 10.0, 0.0), (4.999999999999998, 10.0, 0.0)), ((0.0, 0.0, 0.0), (4.999999999999998, 10.0, 0.0))], [((7.999999999999998, 10.0, 0.0), (4.999999999999998, 10.0, 0.0)), ((7.999999999999998, 10.0, 0.0), (11.868778280542987, 6.8325791855203635, 10.0)), ((11.868778280542987, 6.8325791855203635, 10.0), (8.868778280542987, 6.8325791855203635, 10.0)), ((4.999999999999998, 10.0, 0.0), (8.868778280542987, 6.8325791855203635, 10.0))], [((11.868778280542987, 6.8325791855203635, 10.0), (8.868778280542987, 6.8325791855203635, 10.0)), ((11.868778280542987, 6.8325791855203635, 10.0), (8.0, 0.0, 10.0)), ((8.0, 0.0, 10.0), (5.0, 0.0, 10.0)), ((8.868778280542987, 6.8325791855203635, 10.0), (5.0, 0.0, 10.0))], [((8.0, 0.0, 10.0), (5.0, 0.0, 10.0)), ((8.0, 0.0, 10.0), (3.0, 0.0, 0.0)), ((0.0, 0.0, 0.0), (3.0, 0.0, 0.0)), ((5.0, 0.0, 10.0), (0.0, 0.0, 0.0))], [((3.0, 0.0, 0.0), (7.999999999999998, 10.0, 0.0)), ((7.999999999999998, 10.0, 0.0), (11.868778280542987, 6.8325791855203635, 10.0)), ((11.868778280542987, 6.8325791855203635, 10.0), (8.0, 0.0, 10.0)), ((8.0, 0.0, 10.0), (3.0, 0.0, 0.0))]] edgeDegreeLists = [[3, 2, 3, 2], [1, 3, 1, 3], [1, 2, 1, 2], [1, 3, 1, 3], [1, 2, 1, 2], [3, 2, 3, 2]] edgeKnotsLists = [[[0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954], [0.0, 0.0, 11.659355111491468, 11.659355111491468], [-11.402640718630954, -11.402640718630954, -11.402640718630954, -5.70132035931548, -0.0, -0.0, -0.0], [-11.659355111491468, -11.659355111491468, -0.0, -0.0]], [[0.0, 3.0], [0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954], [-3.0, -0.0], [0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954]], [[-3.0, -0.0], [0.0, 0.0, 11.659355111491468, 11.659355111491468], [-3.0, -0.0], [0.0, 0.0, 11.659355111491468, 11.659355111491468]], [[-3.0, -0.0], [-11.402640718630954, -11.402640718630954, -11.402640718630954, -5.70132035931548, -0.0, -0.0, -0.0], [-3.0, -0.0], [-11.402640718630954, -11.402640718630954, -11.402640718630954, -5.70132035931548, -0.0, -0.0, -0.0]], [[-3.0, -0.0], [-11.659355111491468, -11.659355111491468, -0.0, -0.0], [0.0, 3.0], [-11.659355111491468, -11.659355111491468, -0.0, -0.0]], [[0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954], [0.0, 0.0, 11.659355111491468, 11.659355111491468], [-11.402640718630954, -11.402640718630954, -11.402640718630954, -5.70132035931548, -0.0, -0.0, -0.0], [-11.659355111491468, -11.659355111491468, -0.0, -0.0]]] edgeKnotMultLists = [[[3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2], [3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2]], [[1, 1], [3, 3, 3, 1, 3, 3, 3], [1, 1], [3, 3, 3, 1, 3, 3, 3]], [[1, 1], [2, 2, 2, 2], [1, 1], [2, 2, 2, 2]], [[1, 1], [3, 3, 3, 1, 3, 3, 3], [1, 1], [3, 3, 3, 1, 3, 3, 3]], [[1, 1], [2, 2, 2, 2], [1, 1], [2, 2, 2, 2]], [[3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2], [3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2]]] edgePointsLists = [[[(0.0, 0.0, 0.0), (0.22763929401898655, 1.8868786438649503, 0.0), (1.3404968459824675, 5.579735213473094, 0.0), (3.6270782988369246, 8.68576097199976, 0.0), (4.999999999999999, 10.000000000000002, 0.0)], [(4.999999999999999, 10.000000000000002, 0.0), (4.233384547267437, 8.905030799280457, 5.586557152473831), (8.868778280542989, 6.832579185520365, 10.000000000000002)], [(8.868778280542989, 6.832579185520365, 10.000000000000002), (7.858295131654848, 5.960526354159582, 9.999999999999993), (6.142148836357774, 3.8648641779206794, 10.000000000000005), (5.227959817755026, 1.315136087995092, 9.999999999999986), (5.0, 0.0, 10.0)], [(5.0, 0.0, 10.0), (-0.20094571939579642, 0.0, 5.58655715247383), (0.0, 0.0, 0.0)]], [[(0.0, 0.0, 0.0), (3.0, 0.0, 0.0)], [(3.0, 0.0, 0.0), (3.227639294018982, 1.8868786438649503, 0.0), (4.34049684598247, 5.579735213473094, 0.0), (6.627078298836922, 8.68576097199976, 0.0), (8.0, 10.000000000000002, 0.0)], [(8.0, 10.000000000000002, 0.0), (4.999999999999999, 10.000000000000002, 0.0)], [(0.0, 0.0, 0.0), (0.22763929401898655, 1.8868786438649503, 0.0), (1.3404968459824675, 5.579735213473094, 0.0), (3.6270782988369246, 8.68576097199976, 0.0), (4.999999999999999, 10.000000000000002, 0.0)]], [[(8.0, 10.000000000000002, 0.0), (4.999999999999999, 10.000000000000002, 0.0)], [(8.0, 10.000000000000002, 0.0), (6.866705007799885, 8.905030799280457, 5.586557152473831), (11.868778280542989, 6.832579185520365, 10.000000000000002)], [(11.868778280542989, 6.832579185520365, 10.000000000000002), (8.868778280542989, 6.832579185520365, 10.000000000000002)], [(4.999999999999999, 10.000000000000002, 0.0), (4.233384547267437, 8.905030799280457, 5.586557152473831), (8.868778280542989, 6.832579185520365, 10.000000000000002)]], [[(11.868778280542989, 6.832579185520365, 10.000000000000002), (8.868778280542989, 6.832579185520365, 10.000000000000002)], [(11.868778280542989, 6.832579185520365, 10.000000000000002), (10.858295131654847, 5.960526354159583, 9.999999999999995), (9.142148836357775, 3.8648641779206794, 10.000000000000005), (8.227959817755021, 1.315136087995092, 9.999999999999986), (8.0, 0.0, 10.0)], [(8.0, 0.0, 10.0), (5.0, 0.0, 10.0)], [(8.868778280542989, 6.832579185520365, 10.000000000000002), (7.858295131654848, 5.960526354159582, 9.999999999999993), (6.142148836357774, 3.8648641779206794, 10.000000000000005), (5.227959817755026, 1.315136087995092, 9.999999999999986), (5.0, 0.0, 10.0)]], [[(8.0, 0.0, 10.0), (5.0, 0.0, 10.0)], [(8.0, 0.0, 10.0), (2.432374741136651, 0.0, 5.58655715247383), (3.0, 0.0, 0.0)], [(0.0, 0.0, 0.0), (3.0, 0.0, 0.0)], [(5.0, 0.0, 10.0), (-0.20094571939579642, 0.0, 5.58655715247383), (0.0, 0.0, 0.0)]], [[(3.0, 0.0, 0.0), (3.227639294018982, 1.8868786438649503, 0.0), (4.34049684598247, 5.579735213473094, 0.0), (6.627078298836922, 8.68576097199976, 0.0), (8.0, 10.000000000000002, 0.0)], [(8.0, 10.000000000000002, 0.0), (6.866705007799885, 8.905030799280457, 5.586557152473831), (11.868778280542989, 6.832579185520365, 10.000000000000002)], [(11.868778280542989, 6.832579185520365, 10.000000000000002), (10.858295131654847, 5.960526354159583, 9.999999999999995), (9.142148836357775, 3.8648641779206794, 10.000000000000005), (8.227959817755021, 1.315136087995092, 9.999999999999986), (8.0, 0.0, 10.0)], [(8.0, 0.0, 10.0), (2.432374741136651, 0.0, 5.58655715247383), (3.0, 0.0, 0.0)]]] faceDegreeULists = [3, 1, 1, 1, 1, 3] faceDegreeVLists = [2, 3, 2, 3, 2, 2] faceKnotsULists = [[0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954], [0.0, 3.0], [0.0, 3.0], [0.0, 3.0], [0.0, 3.0], [0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954]] faceKnotsVLists = [[0.0, 0.0, 11.659355111491468, 11.659355111491468], [0.0, 0.0, 0.0, 5.70132035931548, 11.402640718630954, 11.402640718630954, 11.402640718630954], [0.0, 0.0, 11.659355111491468, 11.659355111491468], [-11.402640718630954, -11.402640718630954, -11.402640718630954, -5.70132035931548, -0.0, -0.0, -0.0], [-11.659355111491468, -11.659355111491468, -0.0, -0.0], [0.0, 0.0, 11.659355111491468, 11.659355111491468]] faceKnotMultULists = [[3, 3, 3, 1, 3, 3, 3], [1, 1], [1, 1], [1, 1], [1, 1], [3, 3, 3, 1, 3, 3, 3]] faceKnotMultVLists = [[2, 2, 2, 2], [3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2], [3, 3, 3, 1, 3, 3, 3], [2, 2, 2, 2], [2, 2, 2, 2]] facePointsLists = [[[(0.0, 0.0, 0.0), (-0.20094571939579642, 0.0, 5.58655715247383), (5.0, 0.0, 10.0), (0.2276392940189867, 1.8868786438649503, 0.0), (-0.0011428641165542874, 1.6792298903167882, 5.5865571524738185)], [(5.227959817755026, 1.315136087995092, 9.999999999999986), (1.340496845982468, 5.579735213473094, 0.0), (0.9836783079027707, 4.96666283277938, 5.586557152473837), (6.142148836357774, 3.8648641779206794, 10.000000000000005), (3.627078298836925, 8.68576097199976, 0.0)], [(3.0137041833487923, 7.733655540447901, 5.586557152473825), (7.858295131654848, 5.960526354159582, 9.999999999999993), (5.0, 10.000000000000002, 0.0), (4.233384547267438, 8.905030799280459, 5.586557152473831), (8.868778280542989, 6.832579185520365, 10.000000000000002)]], [[(0.0, 0.0, 0.0), (0.2276392940189867, 1.8868786438649503, 0.0)], [(1.340496845982468, 5.579735213473094, 0.0), (3.6270782988369255, 8.68576097199976, 0.0)], [(5.0, 10.000000000000002, 0.0), (3.0, 0.0, 0.0)], [(3.227639294018982, 1.8868786438649503, 0.0), (4.34049684598247, 5.579735213473094, 0.0)], [(6.627078298836922, 8.68576097199976, 0.0), (8.0, 10.000000000000002, 0.0)]], [[(5.0, 10.000000000000002, 0.0), (4.233384547267437, 8.905030799280457, 5.586557152473831)], [(8.868778280542989, 6.832579185520365, 10.000000000000002), (8.0, 10.000000000000002, 0.0)], [(6.866705007799885, 8.905030799280457, 5.586557152473831), (11.868778280542989, 6.832579185520365, 10.000000000000002)]], [[(8.868778280542989, 6.832579185520365, 10.000000000000002), (7.858295131654849, 5.960526354159583, 9.999999999999995)], [(6.142148836357774, 3.8648641779206794, 10.000000000000005), (5.227959817755026, 1.315136087995092, 9.999999999999986)], [(5.0, 0.0, 10.0), (11.868778280542989, 6.832579185520365, 10.000000000000002)], [(10.858295131654847, 5.960526354159583, 9.999999999999995), (9.142148836357775, 3.8648641779206794, 10.000000000000005)], [(8.227959817755021, 1.315136087995092, 9.999999999999986), (8.0, 0.0, 10.0)]], [[(5.0, 0.0, 10.0), (-0.20094571939579642, 0.0, 5.58655715247383)], [(0.0, 0.0, 0.0), (8.0, 0.0, 10.0)], [(2.432374741136651, 0.0, 5.58655715247383), (3.0, 0.0, 0.0)]], [[(3.0, 0.0, 0.0), (2.432374741136651, 0.0, 5.58655715247383), (8.0, 0.0, 10.0), (3.2276392940189824, 1.8868786438649503, 0.0), (2.6321775964158887, 1.6792298903167882, 5.5865571524738185)], [(8.227959817755021, 1.315136087995092, 9.999999999999986), (4.34049684598247, 5.579735213473094, 0.0), (3.6169987684352214, 4.96666283277938, 5.586557152473837), (9.142148836357777, 3.8648641779206794, 10.000000000000005), (6.627078298836922, 8.68576097199976, 0.0)], [(5.647024643881236, 7.733655540447901, 5.586557152473825), (10.858295131654845, 5.960526354159582, 9.999999999999993), (8.0, 10.000000000000002, 0.0), (6.866705007799886, 8.905030799280459, 5.586557152473831), (11.86877828054299, 6.832579185520365, 10.000000000000002)]]] bSurfs = []; bEdges = []; for faceInd in range(len(faceDegreeULists)): attributes = {} attributes["UDegree"] = faceDegreeULists[faceInd] attributes["VDegree"] = faceDegreeVLists[faceInd] attributes["ControlPointsList"] = [[ifc_file.createIfcCartesianPoint(point) for point in points] for points in facePointsLists[faceInd]] attributes["UMultiplicities"] = faceKnotMultULists[faceInd] attributes["VMultiplicities"] = faceKnotMultVLists[faceInd] attributes["UKnots"] = faceKnotsULists[faceInd] attributes["VKnots"] = faceKnotsVLists[faceInd] bSurf = ifc_file.create_entity("IfcBSplineSurfaceWithKnots", **attributes) bSurfs.append(bSurf) tempEdges = [] for edgeInd in range(len(edgePointsLists[faceInd])): attributes = {} attributes["ControlPointsList"] = [ifc_file.createIfcCartesianPoint(pnt) for pnt in edgePointsLists[faceInd][edgeInd]] attributes["Knots"] = edgeKnotsLists[faceInd][edgeInd] attributes["KnotMultiplicities"] = edgeKnotMultLists[faceInd][edgeInd] attributes["Degree"] = edgeDegreeLists[faceInd][edgeInd] bEdge = ifc_file.create_entity("IfcBSplineCurveWithKnots", **attributes) tempEdges.append(bEdge) startPoint ,endPoint = edgeStartEndLists[faceInd][edgeInd] bEdges.append(tempEdges) advancedFaces = [] for surfInd,surf in enumerate(bSurfs): orientedEdges = [] for edgeInd,edge in enumerate(bEdges[surfInd]): startPoint, endPoint = edgeStartEndLists[surfInd][edgeInd] edgeEnd = ifc_file.create_entity("IfcVertexPoint", VertexGeometry=ifc_file.create_entity("IfcCartesianPoint", endPoint)) edgeStart = ifc_file.create_entity("IfcVertexPoint", VertexGeometry=ifc_file.create_entity("IfcCartesianPoint", startPoint)) edgeCurve = ifc_file.create_entity("IfcEdgeCurve", EdgeStart=edgeStart, EdgeEnd=edgeEnd, EdgeGeometry=edge) orientedEdge = ifc_file.create_entity("IfcOrientedEdge", EdgeElement=edgeCurve, Orientation=True) orientedEdges.append(orientedEdge) edgeLoop = ifc_file.create_entity("IfcEdgeLoop", EdgeList=orientedEdges) faceOuterBound = ifc_file.create_entity("IfcFaceOuterBound", Bound=edgeLoop, Orientation=True) advancedFace = ifc_file.create_entity("IfcAdvancedFace", Bounds=(faceOuterBound,), FaceSurface=surf, SameSense=True) advancedFaces.append(advancedFace) closedShell = ifc_file.create_entity("IfcClosedShell", CfsFaces=advancedFaces) advancedBrep = ifc_file.create_entity("IfcAdvancedBrep", Outer=closedShell) # Assign the advanced brep representation to an instanced entity: wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall") shapeRep = ifc_file.createIfcShapeRepresentation(ContextOfItems=context, RepresentationIdentifier='Body', RepresentationType='AdvancedBrep', Items=[advancedBrep]) ifcopenshell.api.run("geometry.assign_representation", ifc_file, product=wall, representation=shapeRep) containment = ifcopenshell.api.run("spatial.assign_container", ifc_file, product=wall, relating_structure=storey) wall.ObjectPlacement = create_ifclocalplacement(ifc_file, point=O, dir1=Z, dir2=X, relative_to=None) # Write the geometry to ifc file: ifc_file.write(ifcPath)