import os import ifcopenshell import ifcopenshell.api import ifcopenshell.api.owner.settings #resultFilePath = r"C:\Users\sbe\Documents\IFC" + r"\IFC4_wName.ifc" resultFilePath = os.getcwd() + r"\IFC4_wName.ifc" def create_ifc_file(ifcSite=None, ifcBuilding=None, projectName=None): file = ifcopenshell.api.run("project.create_file", "IFC4") person = ifcopenshell.api.run("owner.add_person", file) person[0] = person.GivenName = None person.FamilyName = "user" org = ifcopenshell.api.run("owner.add_organisation", file) org[0] = None; org.Name = "template" user = ifcopenshell.api.run("owner.add_person_and_organisation", file, person=person, organisation=org) application = ifcopenshell.api.run("owner.add_application", file) ifcopenshell.api.owner.settings.get_user = lambda ifc: user ifcopenshell.api.owner.settings.get_application = lambda ifc: application history = ifcopenshell.api.run("owner.create_owner_history", file) # The project is needed in the ifc file, if not defined amongst layers it is still created below: if projectName == None: project = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcProject", name="IfcProject/MyProject") else: project = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcProject", name=projectName) lengthunit = ifcopenshell.api.run("unit.add_si_unit", file, unit_type="LENGTHUNIT", name="METRE") ifcopenshell.api.run("unit.assign_unit", file, units=[lengthunit]) return file file = create_ifc_file() model = ifcopenshell.api.run("context.add_context", file, context_type="Model") context = ifcopenshell.api.run("context.add_context",file,context_type="Model",context_identifier="Body",target_view="MODEL_VIEW",parent=model,) origin = file.createIfcAxis2Placement3D(file.createIfcCartesianPoint((0.0, 0.0, 0.0)),file.createIfcDirection((0.0, 0.0, 1.0)),file.createIfcDirection((1.0, 0.0, 0.0)),) placement = file.createIfcLocalPlacement(None, origin) def getNurbsCurve(degree, knotMult, knotValues, ctrlPoints, weights): attributes = {"ControlPointsList":[file.createIfcCartesianPoint(pnt) for pnt in ctrlPoints], "Knots":knotValues, "KnotMultiplicities":knotMult, "Degree":degree, "ClosedCurve":True, "SelfIntersect":False, "CurveForm":"UNSPECIFIED", "KnotSpec":"UNSPECIFIED", "WeightsData":weights, } return file.create_entity("IfcRationalBSplineCurveWithKnots", **attributes) #NURBS CIRCLE, A simple case with only 1 edge curve degreeU = 1; degreeV = 1; knotMultU = [2, 2]; knotMultV = [2, 2] knotsU = [-11.832977196472893, 28.660416692217932]; knotsV = [-31.682680083086037, 8.8107138056047809] weights = [[1.0, 1.0], [1.0, 1.0]] controlPointsList = [[(-0.34434392948259074, -29.603233801818135, 0.0), (40.149049959208234, -29.603233801818135, 0.0)], [(-0.34434392948259074, 10.890160086872683, 0.0), (40.149049959208234, 10.890160086872683, 0.0)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":True, "VClosed":True, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED" } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) #bSurf.get_info() srfFace = bSurf; # CORRESPONDING EDGE: degree = 2 knotMult = [3,2,2,2,3] knotValues = [0.0, 22.301568055240388, 44.603136110480776, 66.904704165721171, 89.206272220961552] ctrlPoints = [(11.488633266990302, 2.0794462812679022, 0.0), (0.052650128249674841, -6.3342734666046212, 0.0), (8.466369876122199, -17.770256605345246, 0.0), (16.880089623994714, -29.20623974408587, 0.0), (28.316072762735349, -20.79251999621335, 0.0), (39.75205590147597, -12.378800248340829, 0.0), (31.33833615360345, -0.94281710960020249, 0.0), (22.924616405730934, 10.49316602914042, 0.0), (11.488633266990302, 2.0794462812679022, 0.0)] weights = [1.0, 0.70710678118654757, 1.0, 0.70710678118654757, 1.0, 0.70710678118654757, 1.0, 0.70710678118654757, 1.0] startPoint = file.createIfcCartesianPoint((11.488633266990302, 2.0794462812679022, 0.0)) startPointVertex = file.createIfcVertexPoint(startPoint) ##(11.488633266990302, 2.0794462812679022, 0.0) #startPointVertex.get_info() endPoint = file.createIfcCartesianPoint((11.488633266990302, 2.0794462812679022, 0.0)) endPointVertex = file.createIfcVertexPoint(endPoint) ##(11.488633266990302, 2.0794462812679022, 0.0) nurbsCrv = getNurbsCurve(degree, knotMult, knotValues, ctrlPoints, weights) edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurbsCrv, EdgeStart=startPointVertex, EdgeEnd=endPointVertex, SameSense=True) orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges = [orientedEdge,] srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=False) closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) shapeRepr1 = shapeRepresentation #------------- Include the edgeCurve just to illustrate that it works... -------------------------------------------------------------------------------- sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurbsCrv, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #--------------------------------------------------------------------------------------------- # file.write(resultFilePath) # print(resultFilePath) # import ifcopenshell.validate # ifc_file = ifcopenshell.open(resultFilePath) # json_logger = ifcopenshell.validate.json_logger() # ifcopenshell.validate.validate(ifc_file, json_logger) # json_logger.statements #------------------------------------------------------------------------------ # Arc extruded in 1 direction, creating a surface degreeU = 2; degreeV = 1; knotMultU = [3, 3]; knotMultV = [2, 2] knotsU = [0.0, 14.285762043329834]; knotsV = [0.0, 22.864732864703612] weights = [[1.0, 0.87583955460601559, 1.0], [1.0, 0.87583955460601559, 1.0]] controlPointsList = [[(0.0, -7.4334221038615178, 10.143142476697736), (0.0, -0.49251678698132584, 6.5516275162190327), (0.0, 6.2513837765984688, 10.500671896545263)], [(22.864732864703612, -7.4334221038615178, 10.143142476697736), (22.864732864703615, -0.49251678698132584, 6.5516275162190327), (22.864732864703612, 6.2513837765984688, 10.500671896545263)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":False, "VClosed":False, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED", } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) srfFace = bSurf; #--------------------------------------------------------------------------------------------- # Create all edges for the given surface: degree = [2, 1, 2, 1] knotMult = [[3,3], [2,2], [3,3], [2,2]] knotValues = [[0.0, 14.285762043329834], [0.0, 22.864732864703612], [-14.285762043329834, 0.0], [-22.864732864703612, 0.0]] ctrlPoints = [[(0.0, -7.4334221038615178, 10.143142476697736), (0.0, -0.49251678698132584, 6.5516275162190327), (0.0, 6.2513837765984688, 10.500671896545263)], [(0.0, 6.2513837765984688, 10.500671896545263), (22.864732864703612, 6.2513837765984688, 10.500671896545263)], [(22.864732864703612, 6.2513837765984688, 10.500671896545263), (22.864732864703615, -0.49251678698132584, 6.5516275162190327), (22.864732864703612, -7.4334221038615178, 10.143142476697736)], [(22.864732864703612, -7.4334221038615178, 10.143142476697736), (0.0, -7.4334221038615178, 10.143142476697736)]] weights = [[1.0,0.87583955460601559,1.0], [1.0,1.0], [1.0, 0.87583955460601559, 1.0], [1.0,1.0]] startPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (0.0, -7.4334221038615178, 10.143142476697736), (0.0, 6.2513837765984688, 10.500671896545263), (22.864732864703612, 6.2513837765984688, 10.500671896545263), (22.864732864703612, -7.4334221038615178, 10.143142476697736) ]] endPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (0.0, 6.2513837765984688, 10.500671896545263), (22.864732864703612, 6.2513837765984688, 10.500671896545263), (22.864732864703612, -7.4334221038615178, 10.143142476697736), (0.0, -7.4334221038615178, 10.143142476697736) ]] startPointVertices = [file.createIfcVertexPoint(pnt) for pnt in startPoints] ##(11.488633266990302, 2.0794462812679022, 0.0) endPointVertices = [file.createIfcVertexPoint(pnt) for pnt in endPoints] nurbs = [] edges = [] for (deg,knotM, knotV, ctrlPnt, weight) in zip(degree, knotMult, knotValues, ctrlPoints, weights): nurbs.append(getNurbsCurve(deg, knotM, knotV, ctrlPnt, weight)) orientedEdges = [] for (nurb, startPnt, endPnt) in zip(nurbs, startPointVertices, endPointVertices): edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurb, EdgeStart=startPnt, EdgeEnd=endPnt, SameSense=True) orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges.append(orientedEdge) srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=True) closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) for nurb in nurbs: sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurb, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) # RECTANGLE WITH 4 edges degreeU = 1; degreeV = 1; knotMultU = [2, 2]; knotMultV = [2, 2] knotsU = [-10.0, 10.0]; knotsV = [-10.0,10.0] weights = [[1.0, 1.0], [1.0, 1.0]] controlPointsList = [[(-10., -10., 5.), (10., -10., 5.)], [(-10., 10., 5.), (10., 10., 5.)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":True, "VClosed":True, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED", } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) srfFace = bSurf; #--------------------------------------------------------------------------------------------- # Create all edges for the given surface: degree = [1, 1, 1, 1] knotMult = [[2,2], [2,2], [2,2], [2,2]] knotValues = [[-10.0,10.0], [-10.0,10.0], [-10.0,10.0], [-10.0,10.0]] ctrlPoints = [[(-10.0, -10.0, 5.0), (10.0, -10.0, 5.0)], [(10.0, -10.0, 5.0), (10.0, 10.0, 5.0)], [(10.0, 10.0, 5.0), (-10.0, 10.0, 5.0)], [(-10.0, 10.0, 5.0), (-10.0, -10.0, 5.0)]] weights = [[1.0,1.0], [1.0,1.0], [1.0,1.0], [1.0,1.0]] startPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (-10.0, -10.0, 5.0),(10.0, -10.0, 5.0), (10.0, 10.0, 5.0), (-10.0, 10.0, 5.0)]] endPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (10.0, -10.0, 5.0),(10.0, 10.0, 5.0), (-10.0, 10.0, 5.0), (-10.0, -10.0, 5.0)]] startPointVertices = [file.createIfcVertexPoint(pnt) for pnt in startPoints] ##(11.488633266990302, 2.0794462812679022, 0.0) endPointVertices = [file.createIfcVertexPoint(pnt) for pnt in endPoints] nurbs = [] edges = [] for (deg,knotM, knotV, ctrlPnt, weight) in zip(degree, knotMult, knotValues, ctrlPoints, weights): nurbs.append(getNurbsCurve(deg, knotM, knotV, ctrlPnt, weight)) orientedEdges = [] for (nurb, startPnt, endPnt) in zip(nurbs, startPointVertices, endPointVertices): edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurb, EdgeStart=startPnt, EdgeEnd=endPnt, SameSense=False) orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges.append(orientedEdge) srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=False) closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) for nurb in nurbs: sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurb, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) # EASY SURFACE, 2 EDGE CURVES, one of them is linear: degreeU = 1; degreeV = 1; knotMultU = [2, 2]; knotMultV = [2, 2] knotsU = [-19.319120348231433, 6.0860376603847222]; knotsV = [-0.49994701608653319, 50.494648624739668] weights = [[1.0, 1.0], [1.0, 1.0]] controlPointsList = [[(18.64289800012757, 18.317485834697358, 0.0), (-3.8454290401673705, 6.4981288144744331, 0.0)], [(-5.0815492863807492, 63.457261925425357, 0.0), (-27.56987632667569, 51.637904905202433, 0.0)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":True, "VClosed":True, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED", } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) srfFace = bSurf; #--------------------------------------------------------------------------------------------- # Create all edges for the given surface: degree = [2, 1] knotMult = [[3, 3], [2, 2]] knotValues = [[0.0, 106.18972219084674], [0.0, 19.070050171676368]] ctrlPoints = [[(1.3092624979662482, 9.7721105751457777, 0.0), (-27.116809911707026, 51.311234130001395, 0.0), (18.189831585158906, 18.644156609898388, 0.0)], [(18.189831585158906, 18.644156609898388, 0.0), (1.3092624979662482, 9.7721105751457777, 0.0)]] weights = [[1.0, 1.0, 1.0], [1.0, 1.0]] startPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (1.3092624979662482, 9.7721105751457777, 0.0), (18.189831585158906, 18.644156609898388, 0.0)]] endPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (18.189831585158906, 18.644156609898388, 0.0), (1.3092624979662482, 9.7721105751457777, 0.0)]] startPointVertices = [file.createIfcVertexPoint(pnt) for pnt in startPoints] ##(11.488633266990302, 2.0794462812679022, 0.0) endPointVertices = [file.createIfcVertexPoint(pnt) for pnt in endPoints] nurbs = [] edges = [] for (deg,knotM, knotV, ctrlPnt, weight) in zip(degree, knotMult, knotValues, ctrlPoints, weights): nurbs.append(getNurbsCurve(deg, knotM, knotV, ctrlPnt, weight)) orientedEdges = [] for (nurb, startPnt, endPnt) in zip(nurbs, startPointVertices, endPointVertices): edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurb, EdgeStart=startPnt, EdgeEnd=endPnt, SameSense=False) orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges.append(orientedEdge) srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) #srfEdgeLoop.get_info() srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) #srfEdges.get_info() advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=False) #advFace.get_info() closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) #advancedBrep.get_info() product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepr1) #------------- Include the edgeCurves just to illustrate that it works... -------------------------------------------------------------------------------- for nurb in nurbs: sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurb, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) # file.write(resultFilePath) # print(resultFilePath) # import ifcopenshell.validate # ifc_file = ifcopenshell.open(resultFilePath) # json_logger = ifcopenshell.validate.json_logger() # ifcopenshell.validate.validate(ifc_file, json_logger) # json_logger.statements #--------------------------------------------------------- # Another surface: 3 edge curve, but nonlinear shape. degreeU = 3; degreeV = 1; knotMultU = [4,1,4]; knotMultV = [2,2] knotsU = [0.0, 6.5271304493932183, 14.439736364771663]; knotsV = [0.0, 14.376081499435825] weights = [[1.0,1.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,1.0]] controlPointsList = [[(2.4328629032258124, -21.878763440860219, 0.0), (2.4328629032258124, -21.878763440860219, 0.0), (2.4328629032258124, -21.878763440860219, 0.0), (2.4328629032258124, -21.878763440860219, 0.0), (2.4328629032258124, -21.878763440860219, 0.0)], [(4.2292338709677466, -7.98682795698925, 0.0), (2.2412746894434226, -8.2258234962885322, 1.1661183045757162), (-2.0543144430183622, -9.16515373563945, 2.5797616607728742), (-6.1235854279252848, -11.012859497694475, 1.4136433561971586), (-8.2854838709677363, -12.298118279569891, 0.0)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":False, "VClosed":False, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED", } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) srfFace = bSurf; #--------------------------------------------------------------------------------------------- # Create all edges for the given surface: degree = [1,3,1] knotMult = [[2,2],[4,1,4],[2,2]] knotValues = [[0.0, 14.376081499435825],[-14.439736364771663,-6.5271304493932183,0.0],[-14.376081499435825,0.0]] ctrlPoints = [[(2.4328629032258124, -21.878763440860219, 0.0),(-8.2854838709677363, -12.298118279569891, 0.0)], [(-8.2854838709677363, -12.298118279569891, 0.0),(-6.1235854279252848, -11.012859497694475, 1.4136433561971586), (-2.0543144430183622, -9.16515373563945, 2.5797616607728742), (2.2412746894434226, -8.2258234962885322, 1.1661183045757162), (4.2292338709677466, -7.98682795698925, 0.0)], [(4.2292338709677466, -7.98682795698925, 0.0), (2.4328629032258124, -21.878763440860219, 0.0)] ] weights = [[1.0, 1.0],[1.0,1.0,1.0,1.0,1.0],[1.0,1.0]] startPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (2.4328629032258124, -21.878763440860219, 0.0), (-8.2854838709677363, -12.298118279569891, 0.0), (4.2292338709677466, -7.98682795698925, 0.0)]] endPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (-8.2854838709677363, -12.298118279569891, 0.0), (4.2292338709677466, -7.98682795698925, 0.0), (2.4328629032258124, -21.878763440860219, 0.0)]] startPointVertices = [file.createIfcVertexPoint(pnt) for pnt in startPoints] ##(11.488633266990302, 2.0794462812679022, 0.0) endPointVertices = [file.createIfcVertexPoint(pnt) for pnt in endPoints] nurbs = [] edges = [] for (deg,knotM, knotV, ctrlPnt, weight) in zip(degree, knotMult, knotValues, ctrlPoints, weights): nurbs.append(getNurbsCurve(deg, knotM, knotV, ctrlPnt, weight)) orientedEdges = [] for (nurb, startPnt, endPnt) in zip(nurbs, startPointVertices, endPointVertices): edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurb, EdgeStart=startPnt, EdgeEnd=endPnt, SameSense=False) orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges.append(orientedEdge) srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=False) closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #------------- Include the edgeCurves just to illustrate that it works... -------------------------------------------------------------------------------- for nurb in nurbs: sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurb, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #------------------------------------------------------------------------------------------------- # NURBS SURFACE degreeU = 2; degreeV = 1; knotMultU = [3, 3]; knotMultV = [2, 2] knotsU = [0.0, 78.197245129461265]; knotsV = [0.0, 15.44734012437695] weights = [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]] controlPointsList = [[(4.5998754038534315, -29.116393340907536, 0.0), (-21.255228403960196, -18.644873629173532, 0.0), (-31.052400846724694, 30.693921283176252, 0.0)], [(4.5998754038534315, -29.116393340907536, 15.44734012437695), (-21.255228403960196, -18.644873629173532, 15.44734012437695), (-31.052400846724694, 30.693921283176252, 15.44734012437695)] ] attributes = { # Create an attribute dictionary: "UDegree":degreeU, "VDegree":degreeV, "UClosed":True, "VClosed":True, "UMultiplicities":knotMultU, "VMultiplicities":knotMultV, "UKnots":knotsU, "VKnots":knotsV, "WeightsData":weights, "ControlPointsList": [[file.createIfcCartesianPoint(pnt) for pnt in points] for points in controlPointsList], "SurfaceForm" : "UNSPECIFIED", "SelfIntersect":False, "KnotSpec":"UNSPECIFIED", } bSurf = file.create_entity("IfcRationalBSplineSurfaceWithKnots", **attributes) srfFace = bSurf; # Create all edges for the given surface. Must be sorted so that each one starts where the previous ended: degree = [2, 1, 2, 1] knotMult = [[3,3], [2,2], [3,3], [2,2]] knotValues = [[0.0, 78.197245129461265], [0.0, 15.44734012437695], [-78.197245129461265, 0.0], [-15.44734012437695, 0.0]] ctrlPoints = [((4.5998754038534315, -29.116393340907536, 0.0), (-21.255228403960196, -18.644873629173532, 0.0), (-31.052400846724694, 30.693921283176252, 0.0)), ((-31.052400846724694, 30.693921283176252, 0.0), (-31.052400846724694, 30.693921283176252, 15.44734012437695)), ((-31.052400846724694, 30.693921283176252, 15.44734012437695), (-21.255228403960196, -18.644873629173532, 15.44734012437695), (4.5998754038534315, -29.116393340907536, 15.44734012437695)), ((4.5998754038534315, -29.116393340907536, 15.44734012437695), (4.5998754038534315, -29.116393340907536, 0.0)) ] weights = [[1.0,1.0,1.0], [1.0, 1.0],[1.0,1.0,1.0],[1.0, 1.0]] startPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (4.5998754038534315, -29.116393340907536, 0.0), (-31.052400846724694, 30.693921283176252, 0.0), (-31.052400846724694, 30.693921283176252, 15.44734012437695), # This section must be reversed (4.5998754038534315, -29.116393340907536, 15.44734012437695)]] # This section must be reversed endPoints = [file.createIfcCartesianPoint(pnt) for pnt in [ (-31.052400846724694, 30.693921283176252, 0.0), (-31.052400846724694, 30.693921283176252, 15.44734012437695), (4.5998754038534315, -29.116393340907536, 15.44734012437695), (4.5998754038534315, -29.116393340907536, 0.0)]] startPointVertices = [file.createIfcVertexPoint(pnt) for pnt in startPoints] #(11.488633266990302, 2.0794462812679022, 0.0) endPointVertices = [file.createIfcVertexPoint(pnt) for pnt in endPoints] nurbs = [] edges = [] for (deg,knotM, knotV, ctrlPnt, weight) in zip(degree, knotMult, knotValues, ctrlPoints, weights): nurbs.append(getNurbsCurve(deg, knotM, knotV, ctrlPnt, weight)) orientedEdges = [] for (nurb, startPnt, endPnt) in zip(nurbs, startPointVertices, endPointVertices): edge = file.create_entity("IfcEdgeCurve", EdgeGeometry=nurb, EdgeStart=startPnt, EdgeEnd=endPnt, SameSense=False) # False orientedEdge = file.create_entity("IfcOrientedEdge", EdgeElement=edge, Orientation=True) orientedEdges.append(orientedEdge) srfEdgeLoop = file.create_entity("IfcEdgeLoop", orientedEdges) srfEdges = file.create_entity("IfcFaceOuterBound", Bound=srfEdgeLoop, Orientation=True) advFace = file.create_entity("IfcAdvancedFace", FaceSurface=srfFace, Bounds=[srfEdges,], SameSense=False) # False closedShell = file.create_entity('IfcClosedShell', CfsFaces = [advFace,]) advancedBrep = file.create_entity('IfcAdvancedBrep', Outer=closedShell) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcWall") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'SolidModel', Items = [advancedBrep]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #------------- Include the edgeCurves just to illustrate that it works... -------------------------------------------------------------------------------- for nurb in nurbs: sweptDiskSolid = file.create_entity('IfcSweptDiskSolid', Directrix = nurb, Radius = 0.4) product = ifcopenshell.api.run('root.create_entity', file, ifc_class = "IfcReinforcingBar") product.ObjectPlacement = placement; # Origo is used as default relative position shapeRepresentation = file.create_entity('IfcShapeRepresentation', ContextOfItems = context, RepresentationIdentifier = 'Body', RepresentationType = 'AdvancedSweptSolid', Items = [sweptDiskSolid]) # Add the shape representation to the IFC object: ifcopenshell.api.run('geometry.assign_representation', file, product = product, representation = shapeRepresentation) #--------------------------------------------------------------------------------------------- file.write(resultFilePath) print(resultFilePath) import ifcopenshell.validate ifc_file = ifcopenshell.open(resultFilePath) json_logger = ifcopenshell.validate.json_logger() ifcopenshell.validate.validate(ifc_file, json_logger) print(json_logger.statements)