How to fix IFC file via python

edited March 15 in General

Hi everyone,
I've coded a script that generates an IFC model but I think that the IFC in the output is wrong because it doesn't classify the elements. For example, I have a series of elements typed as IfcCivilElementType but when I parse the file I have this "No stream support: No module named 'lark'", but being new in this kind of stuff I have no idea what it means. Furthermore, I have no elements classified when I read IFC with IFC viewer. I have attached my script to this discussion. Thank you in advance to everyone who will be able to help me. Cheers!
PS: STL file needed to run the script is attached in .txt as stl.txt

Comments

  • Hi! Can you please narrow down the issue in your script so it will be easier to help? Currently it's 1.4k lines of code.

  • You're right, the script works but I think that there is a problem in the BIM part because the IFC comes out is not good (the IFC viewer doesn't recognize the different IFC type in the model). Just to figure out, the problem would be from line 628 to the end leaving out the saving part. Thank you!

  • edited March 15

    It's still 0.8k lines of code... Can you please create simple script to reproduce the issue?

  • Well, I've just made up a simpler Python script. As I explained for the other script, the problem is that the IFC viewer doesn't see the properties of the structure underneath the accropode because in my opinion the IFC is not written correctly. Thank you!

  • It seems to me that you tried to write the properties yourself instead of using the blenderbim and ifcopenshell modules. Any reasons why you did this way?

    theoryshaw
  • @bruno_perdigao Yes, I did. I'd need to write elements custom properties via Python script and I don't know if it is the right way to do this. It is the only reason. If you have some pieces of advice I'd be very happy to follow them. Thank you for your feedback!

  • I don't have experience in creating an IFC file from scratch, so I don't know what would be the best practice here. But I suggest that you take a look at this section (https://blenderbim.org/docs/devs/hello_world.html) from the BlenderBIM documentation. It's aimed to development, but it will help you understand how the code generally works and how you can use ifcopenshell and blenderbim functions inside Blender. There is also this introduction to ifcopenshell: https://blenderbim.org/docs-python/ifcopenshell-python/hello_world.html
    For more advanced stuff: https://github.com/cvillagrasa/IfcOpenHouse/blob/master/nbs/00_generation.ipynb

    In your code, for example, you tried to update the author name by using bpy.context.scene.BIMProjectProperties.author_name which only updates this property inside blender, not in the IFC file. If you want to edit the author name inside blender using a script, you would have to load the ifc file to the code:

    from blenderbim.bim.ifc import IfcStore
    
    ifc_file = IfcStore.get_file()
    ifc_file.wrapped_data.header.file_name.author = ("Author Name", "author@email.com")
    

    Maybe there are other ways, but I think this is the general problem of your code, sometimes you're not editing the IFC, just the Blender file. So all the data is not being saved as IFC.

    theoryshawMassimo
  • @valgianf said:
    Well, I've just made up a simpler Python script. As I explained for the other script, the problem is that the IFC viewer doesn't see the properties of the structure underneath the accropode because in my opinion the IFC is not written correctly. Thank you!

    I tried to run simplified version and it seems to work fine.

    After running the script:

    After reopening created file in BBIM:

    Opening created file in Open IFC Viewer:

    but I think that the IFC in the output is wrong because it doesn't classify the elements
    Furthermore, I have no elements classified when I read IFC with IFC viewer

    Can you please show some examples what is missing?

  • @Andrej730 In the case of the complex script when I open the IFC with Open IFC Viewer misses all the elements underneath the accropodes. Just to figure out, The elements are visualized but they don't appear in the project tree on the left side

  • @valgianf said:
    @Andrej730 In the case of the complex script when I open the IFC with Open IFC Viewer misses all the elements underneath the accropodes. Just to figure out, The elements are visualized but they don't appear in the project tree on the left side

    The missing object "IfcCivilElement/Cons" is. I guess it's missing because it's assigned to IfcProject directly and not to IfcSite/IfcBuilding etc. You can add this object to one of those collections in your script before saving .ifc file and object will appear in IFC Viewer.

    bruno_perdigao
  • Perfect, it works! Thank you so much

Sign In or Register to comment.