OSArch Community

[IfcOpenShell] Cityjson to IFC

  1. M
  2. M

    Maybe we should ship it with the BlenderBIM Add-on and build a small UI for it, to make it more accessible to more users? Ping @LaurensJN ?

  3. L

    @magicalcloud_75 I could make an extended install guide on the OSArch wiki.

    @Moult might be a good idea. Also because it is dependent on the ifcopenshell.api that currently is not shipped with the python distributions in http://ifcopenshell.org/python but are with BlenderBIM. However it also has a cjio dependency. You think that's a problem?

  4. L

    @magicalcloud_75 I forgot to make the tutorial, sorry about that. Here you can find it: https://wiki.osarch.org/index.php?title=Ifccityjson.

    @Moult I'm still up for making a small CityJSON importer UI in BlenderBIM. How can I get it to ship with it so I could make the UI? Also, is the cjio dependency a problem in that case?

  5. M

    Good job Laurens. We have a FME running for us that does these kinds of jobs quite well. Not much of a programmer but would love to be able to use a FOSS solution to make IFC cityjson available for my own activities.

  6. C

    I followed the steps in the tutorial, maybe I am doing something wrong, it still can't find the ifcopenshell.api module. I am on Windows 10 and using Python 3.9.

    What I did:

    1. Went to my system installed python and installed cjio using pip install cjio . It worked, I now have cjio.exe in my scripts folder

    1. Downloaded the latest BlenderBIM add-on, extracted it and placed the ifcopenshell module in my local Python installation

    1. Git cloned IfcOpenShell to my local machine

    C:\Code\IfcOpenShell\src\ifccityjson

    1. Went to the ifccityjsonfolder

    1. Tried to run the script through powershell

       Windows PowerShell
      
       Copyright (C) Microsoft Corporation. All rights reserved.
      
       Try the new cross-platform PowerShell https://aka.ms/pscore6
      
       PS C:\Code\IfcOpenShell\src\ifccityjson> python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" n -o C:/Users/user/Documents/3DBAG.ifc -n identificatie
      
       Traceback (most recent call last):
      
         File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 21, in <module>
      
           from cityjson2ifc import Cityjson2ifc
      
         File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 20, in <module>
      
           import ifcopenshell.api
      
       ModuleNotFoundError: No module named 'ifcopenshell.api'
      
       PS C:\Code\IfcOpenShell\src\ifccityjson>

    I feel I am missing something in step 2. I cant't find any file or folder called .api. Still missing the ifcopenshell.api. What am I doing wrong?

  7. L

    Great that you tried to follow it @Coen! And I think you are entirely correct that something is missing in step 2. If I download the BlenderBIM add-on and navigate to blenderbim/libs/site/packages/ifcopenshell, the api folder is there, while in your folder it is missing...

    Did you download the latest add-on from https://blenderbim.org/download.html? I'm not sure why your directory looks different otherwise..

  8. C

    @LaurensJN

    Your tutorial is correct, the problem was me. I already had an ifcopenshell folder there before I even installed BlenderBIM, somehow it didn't copy paste the api folder.

    Unto to next challenge,. :-). I typed in this command in Command Prompt:

    python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Gives the following output:

    Traceback (most recent call last):
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
    
        converter.convert(city_model)
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
    
        self.create_IFC_classes()
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 227, in create_IFC_classes
    
        IFC_geometry, shape_representation_type = self.geometry.create_IFC_geometry(self.IFC_model,
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 51, in create_IFC_geometry
    
        IFC_geometry = self.create_IFC_surface(IFC_model, geometry)
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 126, in create_IFC_surface
    
        IFC_faces.append(self.create_IFC_face(IFC_model, face))
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 136, in create_IFC_face
    
        vertices.append(self.vertices[tuple(vertex)])
    
    KeyError: (205925.252, 445764.534, 0.0)

    I also tried to copy paste what was in the tutorial:

    "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" n -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Gives the following output, I think a dash is needed before the first n? Might be a small mistake in the tutorial?

    ifccityjson.py: error: unrecognized arguments: n

    So I placed a dash but now got this:

    C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -n -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    ifccityjson.py: error: argument -n/--name: expected one argument

  9. L

    Let me start with the second question: the first 'n' should not be there at all. There only is one argument '-n' or '--name' (the attribute that has the name, in case of 3DBAG 'identificatie' . So if you would type C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie it should work.

    The first question is a bit more difficult. That is probably a bug in in the converter. I think it has to do with the identifier being a float tuple instead of an int tuple. I will try to fix that.

    Thanks for testing it out! It is always better if somebody else finds some bugs that you couldn't find yourself :)

  10. C

    Thanks for the answer, I am getting this error now

    I typed in the command prompt:

    C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    It returns this

    Traceback (most recent call last):
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
    
        converter.convert(city_model)
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
    
        self.create_IFC_classes()
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 227, in create_IFC_classes
    
        IFC_geometry, shape_representation_type = self.geometry.create_IFC_geometry(self.IFC_model,
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 51, in create_IFC_geometry
    
        IFC_geometry = self.create_IFC_surface(IFC_model, geometry)
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 126, in create_IFC_surface
    
        IFC_faces.append(self.create_IFC_face(IFC_model, face))
    
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 136, in create_IFC_face
    
        vertices.append(self.vertices[tuple(vertex)])
    
    KeyError: (205925.252, 445764.534, 0.0)
  11. L

    I found the bug: CJIO had an update that broke some code. I posted an issue there and will update if I got an answer

  12. L

    It should be fixed now (see commit). You can download ifcopenshell again, or (might be easier), go to src/ifccityjson/ifccityjson.py and change line 39: city_model = cityjson.load(args.input) to city_model = cityjson.load(args.input, transform=False)

  13. M

    Sorry for the late reply @LaurensJN . Indeed it would be awesome to ship it with the BlenderBIM Add-on. The cjio dependency can be added to https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/Makefile - you can see other examples of other Python libs already bundled there.

    You can also see some example code for other importers such as for P6 / MSProject in the sequence module. I think it might be appropriate to create a new module for cityjson. Perhaps a module named gis? Just in case you foresee future development around GIS features. Once you've created a new module here is some existing code you can use as an example: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/sequence/__init__.py#L127-L128 and L141 and L151. And the corresponding operator code: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/sequence/operator.py#L1079-L1098

  14. C

    @LaurensJN said:

    It should be fixed now (see commit). You can download ifcopenshell again, or (might be easier), go to src/ifccityjson/ifccityjson.py and change line 39: city_model = cityjson.load(args.input) to city_model = cityjson.load(args.input, transform=False)

    Thanks, I changed line 39 like you said, ran the command again.

    python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Now the console returns this:

        Traceback (most recent call last):
    
          File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
    
            converter.convert(city_model)
    
           File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
    
             self.create_IFC_classes()
    
           File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 225, in create_IFC_classes
    
            IFC_semantic_surface_children = self.create_IFC_semantic_surface_children(geometry, lod)
    
          File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 290, in create_IFC_semantic_surface_children
    
            IFC_shape_representation =self.create_IFC_shape_representation(surface_geometry, 'brep', lod)
    
          File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 302, in create_IFC_shape_representation
    
            self.IFC_representation_sub_contexts[str(lod)], 'Body',
    
        KeyError: '1.2'
  15. L

    @Moult Thanks for the pointers, I'll be able to start there.

    @Coen I can't reproduce your error. Care to give me your file? You can send it to l.oostwegel (at) gmail.com

  16. C

    @LaurensJN said:

    @Coen I can't reproduce your error. Care to give me your file? You can send it to l.oostwegel (at) gmail.com

    .json file format is not allowed. I changed the file extension to .txt to attach to this post.

    I downloaded this file from the 3DBAG Viewer.

  17. L

    Thanks. My best guess is that this has again to do with the updated CJIO library, this time this issue. The metadata in the file is not properly updated, therefore it does not recognise the multiple LoDs in the file. We'll have to wait for their response to get it working again I'm afraid. Will keep you updated!

  18. M

    Make a 'City IFC for Dummies' video afterwards :)

  19. L

    @Coen issue is now solved inside ifccityjson until there is an update of CJIO where that bug is fixed. I came across another bug, which has to do with generation of interior holes in faces using IFC that I could unfortunately not solve (yet). I will make a post about that on the forum and hopefully somebody can help me :) Anyway, you can download the new code on github and your 3D BAG should have no errors anymore! The command changed ever-so-slightly, it is now best to use: python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie --lod 1.3 (or whichever lod you'd like to extract.).

    @magicalcloud_75 I will put some effort in merging ifccityjson inside BlenderBIM, which will make everything a lot more intuitive for a non-programmer, after that I promise to make a video!

  20. C

    @LaurensJN said:

    Anyway, you can download the new code on github and your 3D BAG should have no errors anymore! The command changed ever-so-slightly, it is now best to use: python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie --lod 1.3 (or whichever lod you'd like to extract.).

    Absolutely fantastic!

    In BimCollabZoom

    And in BIMVision

  21. C

    Can .osm files also be converted to .ifc with this tool?

  22. L
  23. L

    After importing you could get an error, but this does not fail loading the IFC file. I should fix that soon though...

  24. C

    That is really amazing, would be cool to see this for the whole of Europe instead of the Netherlands. :-)

    Slightly related, can you also merge the different IFC tiles in Blender?

  25. L

    I guess you could achieve that in two ways: (1) do process above twice with a different .json file (IFC file gets saved where you specified in 'IFC Output') and use IfcPatch to merge IFCs (see https://community.osarch.org/discussion/447/import-and-merge-ifc).

    (2) merge the cityjson files using CJIO python library (using: pip install cjio). It's a CLI and you can find here https://github.com/cityjson/cjio how the merge function works. After merging multiple tiles, you can just import the big cityjson file as IFC in Blender. Hope that helps?

  1. Page 1
  2. 2
  3. 3

Login or Register to reply.