Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a simple wall with property set and quantity information | IfcOpenShell Academy #4

Open
IfcOpenBot opened this issue Aug 14, 2021 · 32 comments

Comments

@IfcOpenBot
Copy link

#Creating a simple wall with property set and quantity information | IfcOpenShell Academy

url

@IfcOpenBot
Copy link
Author

Original comment by Omar zerhouni on 2021-01-04 08:12:44


Hi,

I am following the recipe, but getting an error in create_ifclocalplacement part.

Traceback (most recent call last):

File "C:/Users/TOSHIBA/AppData/Roaming/JetBrains/PyCharmCE2020.2/scratches/TestZone.py", line 103, in

site_placement = create_ifclocalplacement(ifcfile)

File "C:/Users/TOSHIBA/AppData/Roaming/JetBrains/PyCharmCE2020.2/scratches/TestZone.py", line 25, in create_ifclocalplacement

axis2placement = create_ifcaxis2placement(ifcfile, point, dir1, dir2)

File "C:/Users/TOSHIBA/AppData/Roaming/JetBrains/PyCharmCE2020.2/scratches/TestZone.py", line 17, in create_ifcaxis2placement

point = ifcfile.createIfcCartesianPoint(point)

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\file.py", line 83, in create_entity

self.wrapped_data.add(e.wrapped_data)

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 1478, in add

return _ifcopenshell_wrapper.file_add(self, entity)

TypeError: in method 'file_add', argument 2 of type 'IfcUtil::IfcBaseClass *'

Is the recipe still operating with the new updates ?

@IfcOpenBot
Copy link
Author

Original comment by Mohammad Najjar on 2021-07-01 16:40:19


This looks very interesting. I don't know how far this can go! Will we be able to create a bim creation tool starting from here? obviously we can create levels, wall, windows and maybe slabs. So it worth trying.

@IfcOpenBot
Copy link
Author

Original comment by Mohammad Najjar on 2021-07-01 16:40:19


This looks very interesting. I don't know how far this can go! Will we be able to create a bim creation tool starting from here? obviously we can create levels, wall, windows and maybe slabs. So it worth trying.

Original comment by thomas on 2021-08-07 12:49:18


Be sure to have a look at https://blenderbim.org/

Copy link

When I run the file, I get this error at this line -

 f.write(template)
TypeError: a bytes-like object is required, not 'str'

How do I get rid of this error?

Copy link
Member

aothms commented Jun 22, 2022

@keshavanarayan

Change open(temp_filename, "wb") into open(temp_filename, "w") to open the file in text mode.

Since this tutorial has been written there is also ifcopenshell.template.create() which does more or less the same without the temporary file. https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/template.py

Copy link

Hi @aothms,

Thank you for your insights.
I have one more question.
How to convert an existing mesh(say like an .obj file) into an IFCFURNISHINGELEMENT type using Ifcopenshell?

@Moult
Copy link

Moult commented Jun 23, 2022

@keshavanarayan this might help: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/scripts/obj2ifc.py

@aothms
Copy link
Member

aothms commented Jun 23, 2022

There is also ifcopenshell.geom.serialize() and ifcopenshell.geom.tesselate() that work based on the input of a Open Cascade shape. If you're reading mesh data from OBJ it's indeed more efficient to bypass opencascade and write as a IFC faceset directly as suggested by @Moult

Copy link

Hi @aothms @Moult,

Thank you so much for your help. I created an IFC wall file following this tutorial using my own inputs, I am getting the .IFC file and the python is also not showing errors. However, I am unable to open the ifc file. I have uploaded the python files I have used and a visual explanation of what I have done in the readme file. Please let me know of what mistake I am doing when you're free.

https://github.com/keshavanarayan/ifcwall-test/tree/main

@aothms
Copy link
Member

aothms commented Jun 23, 2022

@keshavanarayan you don't actually assign the wall to the building storey (IfcRelContainedInSpatialStructure) some viewers only show elements that are part of the spatial structure.

Copy link

Hi @aothms,

Thank you so much. :)
So for creating slabs replacing this function [ifcfile.createIfcWallStandardCase()] with [ifcfile.createIfcSlab()] helps? Is there any documentation that I can read on creating slabs, columns, etc in a similar manner?

Copy link

Hi @aothms,

I tried to create a custom wall mesh inspired by the obj2ifc.py file. On running the file I get this error as shown below. I have put my python file in this github repo for your reference.

https://github.com/keshavanarayan/ifcwall-test/tree/main

File "d:/00PortFolio/IFC/TOSEND_testwall/ifcwall-test/mesh2ifc.py", line 109, in <module>
    [file.createIfcCartesianPoint(vertices[index]) for index in face]
  File "d:/00PortFolio/IFC/TOSEND_testwall/ifcwall-test/mesh2ifc.py", line 109, in <listcomp>
    [file.createIfcCartesianPoint(vertices[index]) for index in face]
  File "C:\Users\kesha\AppData\Local\Programs\Python\Python38\lib\site-packages\ifcopenshell\file.py", line 276, in create_entity
    e[idx] = arg
  File "C:\Users\kesha\AppData\Local\Programs\Python\Python38\lib\site-packages\ifcopenshell\entity_instance.py", line 196, in __setitem__
    self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value))
  File "C:\Users\kesha\AppData\Local\Programs\Python\Python38\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4857, in setArgumentAsAggregateOfDouble
    return _ifcopenshell_wrapper.entity_instance_setArgumentAsAggregateOfDouble(self, i, v)
TypeError: Attribute of type AGGREGATE OF REAL needs a python sequence of floats

@aothms
Copy link
Member

aothms commented Jul 3, 2022

@keshavanarayan

If vertices[index] is a numpy float then ifcopenshell will not recognize it.

Try:

tuple(map(float, vertices[index])) to convert to a tuple of python floats.

Copy link

Hi,

Thanks for this nice tutorial to teach IFC.
I have tried code on Fedora 37 using Python 11 but when executing 'container_project = ifcfile.createIfcRelAggregates(create_guid(), owner_history, "Project Container", None, project, [site])' line I get a segfault.
I get also a segfault when reproducing in Github gitpod after a 'pip install ifcopenshell'.

I'm single to have a such segfault?

See https://github.com/EstebanDugueperoux2/ifc-test to reproduce.

Regards.

@aothms
Copy link
Member

aothms commented Jan 28, 2023

@EstebanDugueperoux2 I can't reproduce that. Can you try with the latest version here IfcOpenBot/IfcOpenShell@07ee62e#comments Otherwise open a bug at https://github.com/IfcOpenShell/IfcOpenShell/issues

Copy link

keshavanarayan commented Apr 2, 2023

Hi @aothms,
Does the variable point_list_extrusion_area represent the rectangle shown?
Are the coordinates mentioned in point_list_extrusion_area represent the coordinates respect to the global (0,0,0) or is it relative to the coordinates in the ifc_polyline?

The reason why I ask this is to create walls in any orinetation in plan and it does not make sense to hard code coordinates in the python file.
So the best way as I understand is to create all walls along the positive x-direction and orient the walls along the orientation required using a transformation and this is exactly where I am stuck.

Or editing the ifcaxis2placement should give the desirable outcome?

I think more explanation is needed for the ifcaxis2placement function in ifcopenshell.

Can the tutorial for this also be added to this simple wall? I hope that this will be useful for others as well.

!(https://www.dropbox.com/s/qtlhxe4xfbfhblf/base.png?dl=0)

@aothms
Copy link
Member

aothms commented Apr 8, 2023

afbeelding

Does the variable point_list_extrusion_area represent the rectangle shown?

point_list_extrusion_area = [(0.0, -0.1, 0.0), (5.0, -0.1, 0.0), (5.0, 0.1, 0.0), (0.0, 0.1, 0.0), (0.0, -0.1, 0.0)]

Yes, an IfcRectangleProfileDef could also have been used in this case. If you look at the coords, you see {0 ; 5.0} for X and {-0.1 ; 0.1} for Y. This is the idiomatic way to build a wall prism in IFC, the local direction should follow X.

Are the coordinates mentioned in point_list_extrusion_area represent the coordinates respect to the global (0,0,0) or is it relative to the coordinates in the ifc_polyline?

There are various placements involved. The IfcExtrudedAreaSolid has a placement itself and also the IfcWall.ObjectPlacement is a recursive placement. Both affect the eventual world coordinates of the polyline points.

The reason why I ask this is to create walls in any orinetation in plan and it does not make sense to hard code coordinates in the python file.

Exactly. But these days there have also been massive efforts on a high level API that does make more sense. See https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/api/geometry/add_axis_representation.py

@keshavanarayan
Copy link

Hi @aothms ,

Thank you so much for the detailed answer. How do I add color to this wall based on a material?
I am aware that an 'IfcColor' type exists, but if you can share a code snipper in the context of this wall, it would be great.

Thank you so much.

@aothms
Copy link
Member

aothms commented Apr 14, 2023

@keshavanarayan have a look at this API call:

https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/api/style/assign_material_style.py

Essentially you'd be building this structure:

IfcMaterial <- IfcMaterialDefinitionRepresentation -> IfcStyledRepresentation -> IfcStyledItem

@fdh-fdh
Copy link

fdh-fdh commented Sep 13, 2023

https://blenderbim.org/

Original comment by Mohammad Najjar on 2021-07-01 16:40:19

This looks very interesting. I don't know how far this can go! Will we be able to create a bim creation tool starting from here? obviously we can create levels, wall, windows and maybe slabs. So it worth trying.

Hii, there,
Are there any solutions without using blender add on ? only for using IFCOpenshell in python ?
or are there any update on solving this problem about
TypeError: in method 'entity_instance_setArgumentAsEntityInstance', argument 3 of type 'IfcUtil::IfcBaseClass *
i am currently tryting to create a void element on a existing IfcWall element, and i got this error while using createIfcLocalPlacement to creating a opeing placement related to wall placement generated by
wall_placement = numpy.asarray(ifcopenshell.util.placement.get_local_placement(containing_wall.ObjectPlacement)[:,3][:3])

Copy link

tomito6 commented Feb 5, 2024

Does someone know where the ifcfile.createIfcBuilding() method comes from? I cannot find it

@aothms
Copy link
Member

aothms commented Feb 5, 2024

@tomito6 ifcopenshell.file has a magic method getattr which uses the current associated schema at runtime. Therefore, for example for IFC4X3_ADD2 it means you can use the following entity names https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/annex-b1.html and type names https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/annex-b2.html

@yashreadytobox
Copy link

yashreadytobox commented Mar 17, 2024

I am trying to read a point cloud, estimate a mesh bounding the point cloud and then write a ifc file with mesh representation. unable to understand why am I getting a error in creating the mesh representation. I am getting the error somewhat similar to the one above in this thread, on the line representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices_list, faces=f) getting TypeError: Attribute of type AGGREGATE OF INTEGER needs a python sequence of ints Exception ignored in: <function entity_instance.__del__ at 0x00000284A94E8820> , TypeError: 'NoneType' object is not callable Exception ignored in: <function entity_instance.__del__ at 0x00000284A94E8820> and TypeError: 'NoneType' object is not callable

import ifcopenshell
from ifcopenshell.api import run
import open3d as o3d
import numpy as np

model = run("project.create_file")
run("root.create_entity", model, ifc_class="IfcProject")
run("unit.assign_unit", model)
model3d = run("context.add_context", model, context_type="Model")
body = run("context.add_context", model,
    context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
element = run("root.create_entity", model, ifc_class="IfcFurniture")

run("geometry.edit_object_placement", model, product=element)

mesh = o3d.data.BunnyMesh()
gt_mesh = o3d.io.read_triangle_mesh(mesh.path)
gt_mesh.compute_vertex_normals()
pcd = gt_mesh.sample_points_poisson_disk(3000)

#pcd = o3d.io.read_point_cloud("D:\\building_1_500_updated\\building_1_500_updated\\beam\\Segment_output\\beam_7.xyz")
#pcd.estimate_normals()
radii = [0.005, 0.01, 0.02, 0.04,0.1,0.5,1,1.1]
rec_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(pcd, o3d.utility.DoubleVector(radii))
rec_mesh.paint_uniform_color([1, 0.706, 0])
o3d.visualization.draw_geometries([pcd,rec_mesh])
vertices = np.asarray(rec_mesh.vertices)
# Convert vertices to a list of tuples of Python floats
vertices_list = [[tuple(map(float, vertex)) for vertex in vertices]]
print(vertices_list)
triangles = np.asarray(rec_mesh.triangles)
#v = [[tuple(vertex) for vertex in vertices]]
f = [[tuple(triangle) for triangle in triangles]]
print(f)

representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices_list, faces=f)
run("geometry.assign_representation", model, product=element, representation=representation)

@Moult
Copy link

Moult commented Mar 17, 2024

@yashreadytobox
Copy link

Yes I am referring to the above documentation, both the faces and vertices are correctly formatted and are passed as nested lists.

@Moult
Copy link

Moult commented Mar 18, 2024

@yashreadytobox does the sample code work for you in the docs? If so, it must be an issue with your code. At a glance I don't see any errors in your code but you have debug print statements and can you check data types (e.g the error message seems to expect a sequence of ints presumably for the triangle indices).

@yashreadytobox
Copy link

@Moult First of all, Thank you very much for your quick response.
Yes the sample code was working perfectly, the type of elements present in the list of list of tuples f is numpy.intc and that of elements of vertices_list is float. I have even converted the type of elements of f from numpy.intc to int but no use.

Will the below log throw some light on what the issue might be.

Traceback (most recent call last):
  File "c:\trial_mesh_rep.py", line 54, in <module>
    run("geometry.assign_representation", model, product=element, representation=representation) 
  File "C:\instance_env\lib\site-packages\ifcopenshell\api\__init__.py", line 66, in run
    result = usecase_class(ifc_file, **settings).execute()
  File "C:\instance_env\lib\site-packages\ifcopenshell\api\geometry\assign_representation.py", line 31, in execute
    if self.settings["product"].is_a("IfcProduct"):
AttributeError: 'int' object has no attribute 'is_a'
Exception ignored in: <function entity_instance.__del__ at 0x0000016BDA90C820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x0000016BDA90C820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x0000016BDA90C820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable

@Moult
Copy link

Moult commented Mar 19, 2024

File "C:\instance_env\lib\site-packages\ifcopenshell\api\geometry\assign_representation.py", line 31, in execute
if self.settings["product"].is_a("IfcProduct"):

This suggests that you are not passing in the product kwarg properly. Are you sure element is an entity_instance? The error suggests it is an int.

@yashreadytobox
Copy link

I was using the variable element elsewhere and that was causing the above error. The main issue I am facing is with creation of the mesh representation from the vertices and faces that have been derived. Upon replacing the vertices and faces lists from the tutorial here. I am getting the below error:

Exception ignored in: <function entity_instance.__del__ at 0x000001EC5C138820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x000001EC5C138820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x000001EC5C138820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x000001EC5C138820>
Traceback (most recent call last):
  File "C:\instance_env\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\instance_env\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable

@yashreadytobox
Copy link

yashreadytobox commented Mar 26, 2024

There seems to be some conflict between the open3d and Ifcopenshell libraries.

For the code below, by simply commenting out the import open3d as o3d line, the error I am facing disappears!
I have installed open3d and ifcopenshell with pip install ifcopenshell and pip install open3d.

Is there any resource that is being utilized by the libraries that causing this error to generate or am I doing something wrong... Any way in which I can resolve this error is much appreciated. (As I need to use both the libraries for my use case).

Code:

from ifcopenshell.api import run
import open3d as o3d

# Let's create a new project using millimeters with a single furniture element at the origin.
model = run("project.create_file")
run("root.create_entity", model, ifc_class="IfcProject")
run("unit.assign_unit", model)

# We want our representation to be the 3D body of the element.
# This representation context is only created once per project.
# You must reuse the same body context every time you create a new representation.
model3d = run("context.add_context", model, context_type="Model")
body = run("context.add_context", model,
    context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)

# Create our element with an object placement.
element = run("root.create_entity", model, ifc_class="IfcFurniture")
run("geometry.edit_object_placement", model, product=element)

# These vertices and faces represent a 2m square 1m high pyramid in SI units.
# Note how they are nested lists. Each nested list represents a "mesh". There may be multiple meshes.
vertices = [[(0.,0.,0.), (0.,2.,0.), (2.,2.,0.), (2.,0.,0.), (1.,1.,1.)]]
faces = [[(0,1,2,3), (0,4,1), (1,4,2), (2,4,3), (3,4,0)]]
representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices, faces=faces)

# Assign our new body representation back to our element
run("geometry.assign_representation", model, product=element, representation=representation)

Error produced:

Exception ignored in: <function entity_instance.__del__ at 0x0000017FD8E089D0>
Traceback (most recent call last):
  File "C:\IFCenv\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\IFCenv\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x0000017FD8E089D0>
Traceback (most recent call last):
  File "C:\IFCenv\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\IFCenv\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x0000017FD8E089D0>
Traceback (most recent call last):
  File "C:\IFCenv\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\IFCenv\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function entity_instance.__del__ at 0x0000017FD8E089D0>
Traceback (most recent call last):
  File "C:\IFCenv\lib\site-packages\ifcopenshell\entity_instance.py", line 135, in __del__
  File "C:\IFCenv\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in <lambda>
TypeError: 'NoneType' object is not callable

Above error can be corrected if we don't import open3d.

A simple and obvious solution which worked for me was to write the data extracted from the open3d pipeline into a text file and then utilize that file to create the ifc model.

@aothms
Copy link
Member

aothms commented Mar 26, 2024

That's odd. I don't have an explanation for this. The error happens during shutdown of the interpreter, somehow the cleanup order is affected that instances are still being deleted, but the ifcopenshell_wrapper module itself is already being destructed. The error seems to be relatively harmless because it only happens at the finalization time.

File "C:\IFCenv\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 4826, in

line 4826 is in the generated swig code:

    __setattr__ = lambda self, name, value: _swig_setattr(self, entity_instance, name, value)

The NoneType object is not callable, probably refers to _swig_setattr.

I'm glad you found a workaround. If you manage to discover more information regarding this then let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants