OSArch Community

How to define IfcWall according to an axis

  1. J

    Hello everyone. I am having problem with the creation of IfcWall with IfcOpenShell. I followed the official documentation

    https://docs.ifcopenshell.org/ifcopenshell-python/geometry_creation.html

    and the creation of model from scratch from this example

    https://docs.ifcopenshell.org/ifcopenshell-python/code_examples.html

    to create a wall and it successfully created one. But I am facing a problem with the coordinates of the wall.

    I wrote the following line of code to represent the two coordinates of the wall as p1 and p2.

    representation = ifcopenshell.api.geometry.create_2pt_wall(model, element=wall, context=body, p1=(1., 1.), p2=(3., 2.), elevation=0, height=3, thickness=0.2)

    I wanted the points p1 and p2 to represent the coordinates of AXIS, but in my case, it is representing the coordinates of the two outer edges.

    What should I add or change in the code to identify the coordinates of axis? I am attaching my whole code below:

    import ifcopenshell.api.root
    
    import ifcopenshell.api.unit
    
    import numpy
    
    import ifcopenshell.api.geometry
    
    import ifcopenshell.api.project
    
    import ifcopenshell.api.context
    
    import ifcopenshell.api.aggregate
    
    # Initialize a new IFC model
    
    model = ifcopenshell.api.run("project.create_file")
    
    # Creating IFC Project element
    
    project = ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject", name="My Project")
    
    # Assign units to the project (millimeters)
    
    length_unit = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI")
    
    ifcopenshell.api.unit.assign_unit(model, units=[length_unit])
    
    # Creating a site, building, and storey
    
    site = ifcopenshell.api.root.create_entity(model, ifc_class="IfcSite", name="My Site")
    
    building = ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuilding", name="Building A")
    
    storey = ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuildingStorey", name="Ground Floor")
    
    #Placing site to the project
    
    ifcopenshell.api.aggregate.assign_object(model, relating_object=project, products=[site])
    
    #Placing buildiong to the site
    
    ifcopenshell.api.aggregate.assign_object(model, relating_object=site, products=[building])
    
    #Placing storey to the building
    
    ifcopenshell.api.aggregate.assign_object(model, relating_object=building, products=[storey])
    
    # Creating a wall entity
    
    wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
    
    # Creating a 4x4 identity transformation matrix
    
    matrix = numpy.eye(4)
    
    # Rotate the matix 90 degrees anti-clockwise around the Z axis (i.e. in plan).
    
    # Anti-clockwise is positive. Clockwise is negative.
    
    matrix = ifcopenshell.util.placement.rotation(-15, "Z") @ matrix
    
    # Translate the wall to a specific location
    
    # Definition in [m] !!
    
    matrix[:,3][0:3] = (2, 3, 5)
    
    # Set our wall's Object Placement using our matrix.
    
    ifcopenshell.api.geometry.edit_object_placement(model, product=wall, matrix=matrix, is_si=True)
    
    #creating representation contexts
    
    model3d = ifcopenshell.api.context.add_context(model, context_type="Model")
    
    body = ifcopenshell.api.context.add_context(model, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
    
    # plan = ifcopenshell.api.context.add_context(model, context_type="Plan")
    
    ifcopenshell.api.context.add_context(model, context_type="Plan", context_identifier="Axis", target_view="GRAPH_VIEW", parent=model3d)
    
    # A wall-like representation starting and ending at a particular 2D point
    
    representation = ifcopenshell.api.geometry.create_2pt_wall(model, element=wall, context=body, p1=(1., 1.), p2=(3., 2.), elevation=0, height=3, thickness=0.2)
    
    # Assigning the new body geometry back to our wall
    
    ifcopenshell.api.geometry.assign_representation(model, product=wall, representation=representation)
    
    # Placing the wall in the ground floor
    
    ifcopenshell.api.spatial.assign_container(model, relating_structure=storey, products=[wall])
    
    # Saving the IFC file
    
    model.write("wall_with_coordinates.ifc")
    
    print("IFC file created: wall_with_coordinates.ifc")
  2. G

    Hello, an axis alone cannot place a wall into space, I think you want an origin point + a director vector + a length along this vector ? Or maybe I'm misunderstanding your goal ?

Login or Register to reply.