little tool to extract the grid from an ifc file ?

Hi everyone,
I'm looking for a simple little tool to extract the grid from an ifc file. I don't know how to program and I don't use python and ifcopenshell. I tried to create a batch file, but it fails to give me the expected result. Does anyone know a little tool to extract grid values ?
BR
David

KoAra

Comments

  • Thank you @theoryshaw for your answer.
    I tried with ChatGPT to create the batch file ... but it doesn't work yet. I can't work with paid programs, but I will see if IFC explorer could do the job. More complicated for me to play with BlenderBim and IFCOpenShell because I can't install it on my machine. Maybe I'll try if I have some time on my personal machine.
    So, If you have another idea (or if someone has already made the Batch file...) don't hesitate ;)
    thanks again
    David

  • hi @Dav_id

    Thank you @theoryshaw for your answer.
    I tried with ChatGPT to create the batch file ... but it doesn't work yet. I can't work with paid programs, but I will see if IFC explorer could do the job. More complicated for me to play with BlenderBim and IFCOpenShell because I can't install it on my machine. Maybe I'll try if I have some time on my personal machine.
    So, If you have another idea (or if someone has already made the Batch file...) don't hesitate ;)

    what is the information you need to extract from grids?

  • edited July 10

    for simple query you can use Spreadsheet Import/Export too

    to do it with command line maybe you can use the same query in IFC2CSV, but need to test it

    KoAraMassimo
  • Hi @steverugi
    I would like to recover the positions (with IFCCARTESIANPOINT).
    ex.
    X 0 1500 3000 4500
    Y 0 6000 12000
    Z 0 200 3200 6200
    to find the spacings (from 0.00)
    X 0 31500
    Y 0 2
    6000
    and possibly recover the labels directly (with IFCGRIDAXIS)
    I did some tests yesterday with ChatGPT, but there is always a moment when it no longer works.
    Do you have an idea?
    X 0 31500
    Y 0 2
    6000
    Z 0 200 3200 6200
    and for the label
    X A B C D
    Y 1 2 3
    Z 0.00 +200 +3200 +6200
    at the end, i would like to have
    David

  • edited July 10

    Hi @Dav_id
    does my previous post take you somewhere closer?
    it would be helpful if you could put the desired information in a tabular format (spreadsheet-like)

  • try this please

    to get this

  • @steverugi said:
    Hi @Dav_id
    does my previous post take you somewhere closer?
    it would be helpful if you could put the desired information in a tabular format (spreadsheet-like)

    Hi @steverugi .
    No, as i told to @theoryshaw i can't use BlenderBim ... it's not for my personal usage. I need a simple file (simple like a *.bat) so that my collegues can quickly create their grids (based on the IFC files they received)
    BR
    David

  • edited July 10

    OK, I now understand
    you send an .ifc file with gridlines in it and you want to share that info with your colleagues, is the output above OK? can you snapshot a table ?
    If I may ask: where are your colleagues going to create the grid, Autocad?

  • Hi,No, it's for TEKLA.
    Here's the workflow
    1. they receive an ifc
    2. the ifc is sent in the little tool that I am looking for, just to retrieve the values ​​that I gave earlier in this forum.
    3. they retrieve the values ​​to copy them into TEKLA.

    D

  • Maybe you can have something working using IfcCSV with the query generating the table above (AxisTag| x1|y1| x2|y2)

    put it into a function with .ifc filename as parameter, and create a .py executable in a .BAT file

    a bit above my skills atm but should be possible with a little effort, let's see if anybody else comes to the rescue here..

  • Something like this?...
    from chatgpt: https://chatgpt.com/share/7c5e931e-fb1c-47f1-b467-f7f23f796c3b

    import ifcopenshell
    import csv
    import bpy
    
    # Function to extract points from a curve
    def get_curve_points(axis_curve):
        if isinstance(axis_curve, ifcopenshell.entity_instance):
            if axis_curve.is_a("IfcPolyline"):
                return [point.Coordinates for point in axis_curve.Points]
            elif axis_curve.is_a("IfcTrimmedCurve"):
                basis_curve = axis_curve.BasisCurve
                if basis_curve.is_a("IfcLine"):
                    start_point = basis_curve.Pnt
                    direction = basis_curve.DirVector.DirectionRatios
                    length = axis_curve.Trim1[0]  # Assuming a single value for trimming
                    end_point = [
                        start_point.Coordinates[0] + direction[0] * length,
                        start_point.Coordinates[1] + direction[1] * length,
                        start_point.Coordinates[2] + direction[2] * length
                    ]
                    return [start_point.Coordinates, end_point]
        return []
    
    # Function to extract grid axis information
    def extract_grid_axis(ifc_file_path):
        ifc_file = ifcopenshell.open(ifc_file_path)
        grid_axes = ifc_file.by_type("IfcGridAxis")
    
        axis_data = []
        for axis in grid_axes:
            points = get_curve_points(axis.AxisCurve)
            axis_data.append({
                "id": axis.id(),
                "name": axis.AxisTag,
                "points": points
            })
    
        return axis_data
    
    # Example usage
    ifc_path = "path_to_your_ifc_file.ifc"  # Replace with your IFC file path
    grid_axis_info = extract_grid_axis(ifc_path)
    
    # Define CSV file path
    csv_file_path = "path_to_output_file.csv"  # Replace with your desired output path
    
    # Export data to CSV
    with open(csv_file_path, mode='w', newline='') as csv_file:
        csv_writer = csv.writer(csv_file)
        csv_writer.writerow(["Axis ID", "Axis Name", "Point Index", "Point Coordinates"])
    
        for axis in grid_axis_info:
            for index, point in enumerate(axis["points"]):
                csv_writer.writerow([axis["id"], axis["name"], index, point])
    
    print(f"Grid axis information has been exported to {csv_file_path}")
    
    

    steverugi
  • edited July 10

    thank you for trying to help me but as I can't install blender or ifcopenshell... and my colleagues won't be able to either... I'm going to continue looking for a small program or continue my tests to create a batch.
    BR
    David
    Yesterday I was there... I will continue trying later

  • @Dav_id said:
    thank you for trying to help me but as I can't install blender or ifcopenshell... and my colleagues won't be able to either... I'm going to continue looking for a small program or continue my tests to create a batch.
    BR
    David
    Yesterday I was there... I will continue trying later

    what did you use to produce that table?
    btw you can use google colab to install ifcopenshell..

  • Can they/you install anything? or are you looking for a web-based program?

  • edited July 11

    @steverugi said:
    what did you use to produce that table?
    btw you can use google colab to install ifcopenshell..

    I use a simple .bat file to create a .csv file

    @theoryshaw said:
    Can they/you install anything? or are you looking for a web-based program?

    It's complicated to ask to install a program for such a simple need. I really prefer the simplicity of a .bat file so I don't have to ask for installation.
    do you know a web-based tool?
    I think I'll ask tekla to do something
    BR
    David

  • hi @Dav_id

    I use a simple .bat file to create a .csv file

    I'd like to have a look at it if you don't mind, could you share it? I don't know much about .bat files apart from simple things
    thanks

  • @theoryshaw said:
    Can they/you install anything? or are you looking for a web-based program?

    yes, it's a really simple batch file ... juste drag/drop the IFC on the .bat ... really easy to use and without any installation.

    here's the code

    @echo off
    setlocal enabledelayedexpansion
    
    REM Vérifier si un fichier a été fourni en argument
    if "%~1"=="" (
        echo Usage: %~0 filename.ifc
        exit /b 1
    )
    
    set inputFile=%~1
    set outputFile=output.csv
    
    REM Créer ou vider le fichier de sortie
    echo X,Y,Z > %outputFile%
    
    REM Lire le fichier ligne par ligne
    for /f "delims=" %%A in ('findstr /i "IFCCARTESIANPOINT" "%inputFile%"') do (
        set line=%%A
    
        REM Extraire les coordonnées X, Y, Z
        for /f "tokens=2 delims=()" %%B in ("!line!") do (
            set coordinates=%%B
    
            REM Retirer les espaces
            set coordinates=!coordinates: =!
    
            REM Extraire les valeurs séparées par des virgules
            for /f "tokens=1,2,3 delims=," %%X in ("!coordinates!") do (
                set x=%%X
                set y=%%Y
                set z=%%Z
    
                REM Écrire les coordonnées dans le fichier de sortie
                echo !x!,!y!,!z! >> %outputFile%
            )
        )
    )
    
    echo Extraction complète. Les résultats sont dans %outputFile%
    

    David

    steverugitheoryshaw
  • That batch script won't give you the correct values depending on all sorts of factors, like whether or not the grid has a non-zero placement, a rotation, georeferencing, etc. Coordinates are relative to other coordinates so you need to do matrix math. This is where libraries like IfcOpenShell come in.

    You don't need admin rights to install either Blender, the BlenderBIM Add-on, Python, or IfcOpenShell. They are all portable (Blender has a zip file, or if you don't want Blender, you can use a portable Python) and you can accompany it with a small Python script that they can drag and drop files onto.

    steverugitheoryshawBedsonCSNDav_id
  • CSNCSN
    edited July 13

    As Moult says, trying to use batch to work with IFC is cursed to say the least. However , if, like me, you like to do things in ways which make very little logical sense and probably don't work in large numbers of use cases - then you can try to use the following batch script.

    Big disclaimer that all I tested this on was an IFC from Tekla which contained nothing but an IFCGRID. I have absolutely no idea if it will work for IFCs that are made outside of Tekla, or IFCs with more than a single Grid in them, or on Grids which have been transformed/rotated etc etc.
    I really only made this just to see what I could hack together using batch. I am not an expert in batch scripting - in fact I'm very amateur - but this was a fun hack together that taught me some more batch scripting tricks.

    @echo off
    setlocal enabledelayedexpansion
    
    if "%~1"=="" (
        echo Drag and drop a file onto this script.
        pause
        exit /b
    )
    
    :: loop through each line in the file, set # vars
    for /f "tokens=1,* delims==" %%a in ('type "%~1"') do (
        set "line=%%a=%%b"
        if "!line:~0,1!"=="#" (
            set "lineNumber=%%a"
            set "lineContent=%%b"
            set "!lineNumber!=!lineContent!"
        )
    )
    ::initialize
    set "loopcheck=true"
    
    :: loop over lines again, this time to process
    for /f "tokens=1,* delims==" %%a in ('type "%~1"') do (
        set "line=%%a"
    
        if "!line:~0,1!"=="#" (
            set "varName=%%a"
            set "varValue=!%%a!"
    
            if "!varValue:~0,9!"==" IFCGRID(" (
    
                :: loop over grid parts
                for /f "tokens=2-4 delims=(" %%i in ("!varValue!") do (
    
                    for /f "tokens=3,6 delims=,'" %%x in ("%%i") do (
    
                        if defined zlabels (set "zlabels=!zlabels! %%x") else (set "zlabels=%%x")                
                        set "LocalPlacement=!%%y!"              
    
                        for /f "tokens=2 delims=,)" %%x in ("!LocalPlacement!") do (
                            set "3dPlacement=!%%x!"
    
                            for /f "tokens=2 delims=(," %%x in ("!3dPlacement!") do (
                                set "3dPoint=!%%x!"
    
                                for /f "tokens=3 delims=,)" %%x in ("!3dPoint!") do (
    
                                    set "zvalue=%%x"
                                    set /a zvalue=zvalue
    
                                    if defined zvalues (set "zvalues=!zvalues! !zvalue!") else (set "zvalues=!zvalue!")
                                )
                            )                    
                        )                
                    )
                    if "!loopcheck!"=="true" (
                        ::extract the x parts
                        for /f "tokens=1 delims=)" %%x in ("%%j") do (
                            set "xlines=%%x"
    
                            for %%x in (!xlines!) do (
                                set "GridAxis=!%%x!"
    
                                for /f "tokens=2,3 delims=(,'" %%x in ("!GridAxis!") do (
                                    if defined xlabels (set "xlabels=!xlabels! %%x") else (set "xlabels=%%x")
                                    set "Polyline=!%%y!"
    
                                    for /f "tokens=2 delims=(," %%x in ("!Polyline!") do (
                                        set "GridPoint=!%%x!"
    
                                        for /f "tokens=2 delims=(," %%x in ("!GridPoint!") do (
                                            if defined xvalues (
    
                                                set "newx=%%x"
                                                set /a xdiff = newx - xvalue
                                                set "xvalues=!xvalues! !xdiff!"
                                                set "xvalue=!newx!"
    
                                            ) else (
                                                set "xvalue=%%x"
                                                set /a xvalue=xvalue
                                                set "xvalues=!xvalue!"
                                            )
                                        )
                                    )
                                )
                            )
                        )            
                        ::extract the y parts
                        for /f "tokens=1 delims=)" %%x in ("%%k") do (
                            set "ylines=%%x"
    
                            for %%x in (!ylines!) do (
                                set "GridAxis=!%%x!"
    
                                for /f "tokens=2,3 delims=(,'" %%x in ("!GridAxis!") do (
                                    if defined ylabels (set "ylabels=!ylabels! %%x") else (set "ylabels=%%x")
                                    set "Polyline=!%%y!"
    
                                    for /f "tokens=2 delims=(," %%x in ("!Polyline!") do (
                                        set "GridPoint=!%%x!"
    
                                        for /f "tokens=3 delims=(,)" %%x in ("!GridPoint!") do (
                                            if defined yvalues (
    
                                                set "newy=%%x"
                                                set /a ydiff = newy - yvalue
                                                set "yvalues=!yvalues! !ydiff!"
                                                set "yvalue=!newy!"
                                            ) else (
                                                set "yvalue=%%x"
                                                set /a yvalue=yvalue
                                                set "yvalues=!yvalue!"
                                            )
                                        )
                                    )
                                )
                            )
                        )
    
                        set "loopcheck=false"
                    )
                )       
            )
        )
    )
    (
    echo !xlabels!
    echo !xvalues!
    echo !ylabels!
    echo !yvalues!
    echo !zlabels!
    echo !zvalues!
    )>grid.txt
    echo Script complete. Check 'grid.txt' for your values.
    
    endlocal
    pause
    

    Use this entirely at your own risk.

    steverugiDav_id
  • @Moult said:
    That batch script won't give you the correct values depending on all sorts of factors, like whether or not the grid has a non-zero placement, a rotation, georeferencing, etc. Coordinates are relative to other coordinates so you need to do matrix math. This is where libraries like IfcOpenShell come in.

    You don't need admin rights to install either Blender, the BlenderBIM Add-on, Python, or IfcOpenShell. They are all portable (Blender has a zip file, or if you don't want Blender, you can use a portable Python) and you can accompany it with a small Python script that they can drag and drop files onto.

    @CSN said:
    As Moult says, trying to use batch to work with IFC is cursed to say the least. However , if, like me, you like to do things in ways which make very little logical sense and probably don't work in large numbers of use cases - then you can try to use the following batch script.

    Big disclaimer that all I tested this on was an IFC from Tekla which contained nothing but an IFCGRID. I have absolutely no idea if it will work for IFCs that are made outside of Tekla, or IFCs with more than a single Grid in them, or on Grids which have been transformed/rotated etc etc.
    I really only made this just to see what I could hack together using batch. I am not an expert in batch scripting - in fact I'm very amateur - but this was a fun hack together that taught me some more batch scripting tricks.

    Hi Dion, thank you very much for your feedback and congratulations on everything you do. I have followed your progress from afar since you started BlenderBim... but I lack time to delve (for the moment) into the subjects that speak more to programmers than to me (ifcopenshell...). For the script, as I told you, I am not a coder at all and I am therefore forced to limit myself to asking chatgpt for help to create a simple batch (...) but I keep in mind the possibility to create a script without my colleagues having to do any installations.

    For the rest, don't worry, I am well aware of the differences and constraints linked to the positioning of the ifc. I know that there are limits and that we will therefore not spontaneously obtain the same thing with an ifc Tekla as with an ifc revit or archicad...

    like @CSN we work with TEKLA, a large quantity of IFCs come from TEKLA (and among these many are in Millimeters and positioned at the origin... because many of them are not produced with the aim of a BIM construction site). So I was looking for a very small and easy solution to help my colleagues create their grid while saving time... and if they have to modify it by hand afterwards, it doesn't matter... modifying the grid n It's not complicated.

    @CSN, I tested your batch on the test that I had done (also a simple grid to start with of course) and the result worked as you can imagine :) being consistent with what we need in TEKLA (the GRD file being very simple) ... the approach to an XML file would be much more complex ... I will see that (or not) much later if the desire comes :) ... for information, I tested with another larger project... it didn't work any better than mine ;)...

    Thank you all and if by chance someone finds a small program to facilitate the recovery of values, don't hesitate! :) !

    BR
    David

Sign In or Register to comment.