How to extract Location data from IFC

Hi
I have a IFC file and I want to retrieve tuple in IfcCartesianPoint.
Please guide me through the relevant sources.

Comments

  • Have you read this crash course? https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples I think it will help answer a lot of questions.

  • edited July 17

    Hi
    I read an IFC file and parsed it based on a condition.
    I want to extract IfcCartesianPoint for that extracted list.
    Below is my code and I get a error saying "list objects no attribute by_type"

    import multiprocessing
    import ifcopenshell
    import ifcopenshell.geom
    import ifcopenshell.util
    from ifcopenshell.util.selector import Selector
    
    ifc = ifcopenshell.open(r'Filename.ifc')
    
    settings = ifcopenshell.geom.settings()
    iterator = ifcopenshell.geom.iterator(settings, ifc, multiprocessing.cpu_count())
    if iterator.initialize():
        while iterator.next():
            selector = Selector()
            element = selector.parse(ifc, '.IfcBuildingElementProxy[Name="PUP Sewer Jnct"]')
            shape = iterator.get()
            coordinates = element.by_type("IfcCartesianPoint")
            print(coordinates)
    
  • In your code, element is a list, not a single element. The selector filters your file by your query and returns a list of elements. That is why you're getting your error.

    What exactly are you trying to achieve? Do you want to know the location of each object? Are you trying to convert element geometry into vertices and faces?

  • I want the location of each object in the list.

  • @Shilpa try this:

    elements = selector.parse(ifc, '.IfcBuildingElementProxy[Name="PUP Sewer Jnct"]')
    for element in elements:
        placement_matrix = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
        print(placement_matrix)
    
  • edited July 29

    I tried that and below is the error message :

    AttributeError                            Traceback (most recent call last)
    <ipython-input-2-c5f678fd821d> in <module>
         14         elements = selector.parse(ifc, '.IfcBuildingElementProxy[Name="PUP Sewer Jnct"]')
         15         for element in elements:
    ---> 16             placement_matrix = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
         17             print(placement_matrix)
    
    AttributeError: module 'ifcopenshell.util' has no attribute 'placement'
    
  • You have an old IfcOpenShell. See this link for the latest util module: https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.6.0/src/ifcopenshell-python/ifcopenshell

  • Can you please let me know how to update the util module in jupyter notebooks?

  • I have not used Jupyter before, unfortunately, so I don't know :(

  • I updated all the packages in my conda environment. ifcopenshell version is v0.6.0.
    Will the util module also gets updated automatically?

  • @Shilpa perhaps yes, perhaps no. The util module moves a bit faster than the conda builds I expect, so I'm not sure how recent the conda builds are.

  • edited July 29

    Hi
    Below is my code

    import multiprocessing
    import ifcopenshell
    import ifcopenshell.geom
    from ifcopenshell.util.placement import get_local_placement
    from ifcopenshell.util.selector import Selector
    
    ifc = ifcopenshell.open(r'C:\12d\14.00\Metro Project\PUP Delivery\12dSewerService.ifc')
    
    settings = ifcopenshell.geom.settings()
    iterator = ifcopenshell.geom.iterator(settings, ifc, multiprocessing.cpu_count())
    if iterator.initialize():
        while iterator.next():
            selector = Selector()
            elements = selector.parse(ifc, '.IfcBuildingElementProxy[Name="PUP Sewer Jnct"]')      
            for element in elements:
                placement_matrix = get_local_placement(element.ObjectPlacement)
                print(placement_matrix)
    

    My Output is :

    [[1. 0. 0. 0.]
     [0. 1. 0. 0.]
     [0. 0. 1. 0.]
     [0. 0. 0. 1.]]
    [[1. 0. 0. 0.]
     [0. 1. 0. 0.]
     [0. 0. 1. 0.]
     [0. 0. 0. 1.]]
    

    But i want to retrieve the below from the ifc file

     IFCCARTESIANPOINT((51971.12751875, 158030.33677902, -1.494));
    #29 = IFCCARTESIANPOINT((51971.12751875, 158030.33677902, 4.598));
    #30 = IFCCARTESIANPOINT((51971.1328404, 158030.4631682, -1.494));
    #31 = IFCCARTESIANPOINT((51971.1328404, 158030.4631682, 4.598));
    

    Let me know how to retrieve these values from ifc file.

  • Given an element, you can retrieve all related cartesian points like this:

    points = [e for e in ifc.traverse(element) if e.is_a("IfcCartesianPoint")]
    print(points)
    
Sign In or Register to comment.