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

Using IfcOpenShell and pythonOCC to construct new geometry | IfcOpenShell Academy #3

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

Comments

@IfcOpenBot
Copy link

#Using IfcOpenShell and pythonOCC to construct new geometry | IfcOpenShell Academy

url

@IfcOpenBot
Copy link
Author

Original comment by Johannes Römpp on 2017-08-25 04:33:35


Hi Thomas

I was wondering, if there is already a way to bring this newly constructed geometry (space) in to an ifc-file, as ifcspace (ifcclosedshell) in this case.

I tried the helloWall example and it works fine. But is there a way, to translate the box or any TopoDSShape to an ifc-entity directly?

Regards

Johannes

@IfcOpenBot
Copy link
Author

Original comment by Johannes Römpp on 2017-08-25 04:33:35


Hi Thomas

I was wondering, if there is already a way to bring this newly constructed geometry (space) in to an ifc-file, as ifcspace (ifcclosedshell) in this case.

I tried the helloWall example and it works fine. But is there a way, to translate the box or any TopoDSShape to an ifc-entity directly?

Regards

Johannes

Original comment by thomas on 2017-10-04 09:04:40


Hi Johannes,

Great question, an academy article on this is long overdue (feel free to step in case you feel like it). In recent IfcOpenShell versions there is ifcopenshell.geom.tesselate() and ifcopenshell.geom.serialize(). tesselate() will always work irrespective of shape and IFC schema, it just meshes the geometry, serialize() will fail for curved surfaces in 2x3 since they are not supported (and even in 4 a lot of viewers will not support them). Both return an IfcProductDefinitionShape that you can assign to a IfcProduct.Representation directly.

Kind regards,

Thomas

@IfcOpenBot
Copy link
Author

Original comment by Franke on 2018-04-12 13:45:06


Hello Thomas,

I have tried to run the code of part "Geting started" after completing all installation steps hopefully, the display window just crashed.

I have also tried to add "raw_input()", and then I could see the display window but it was always running. On chance to manipulate the ifc model there.

I have installed Qt4 and pyqt5. Would that be the prolem? I appreciate it, if you could give me some suggestions.

@IfcOpenBot
Copy link
Author

Original comment by Franke on 2018-04-12 13:45:06


Hello Thomas,

I have tried to run the code of part "Geting started" after completing all installation steps hopefully, the display window just crashed.

I have also tried to add "raw_input()", and then I could see the display window but it was always running. On chance to manipulate the ifc model there.

I have installed Qt4 and pyqt5. Would that be the prolem? I appreciate it, if you could give me some suggestions.

Original comment by Franke on 2018-04-13 15:52:01


It is a little wird to anser own question, but I hope my experience could help anyone who wanna try something on this.


the setup steps could be simpler:

  1. download Anaconda

  2. build an environment in Anaconda, the python version is not a problem, but you must make sure other packages matching the version of python.

  3. just run the code from http://www.pythonocc.org/download/ in the terminal of the environment.

  4. download the IfcOpenShell package, extract it into the Lib\site-packages\ directory of the Python installation folder. (just following the original instruction)

  5. If you want to try the example of the IfcOpenHouse, remember to add raw_input() , which exists in the source code file, beneath the code in part "getting started". Otherwise, the viewer window will crash!

@IfcOpenBot
Copy link
Author

Original comment by Franke on 2018-04-12 13:45:06


Hello Thomas,

I have tried to run the code of part "Geting started" after completing all installation steps hopefully, the display window just crashed.

I have also tried to add "raw_input()", and then I could see the display window but it was always running. On chance to manipulate the ifc model there.

I have installed Qt4 and pyqt5. Would that be the prolem? I appreciate it, if you could give me some suggestions.

Original comment by Franke on 2018-04-13 15:52:01


It is a little wird to anser own question, but I hope my experience could help anyone who wanna try something on this.


the setup steps could be simpler:

  1. download Anaconda

  2. build an environment in Anaconda, the python version is not a problem, but you must make sure other packages matching the version of python.

  3. just run the code from http://www.pythonocc.org/download/ in the terminal of the environment.

  4. download the IfcOpenShell package, extract it into the Lib\site-packages\ directory of the Python installation folder. (just following the original instruction)

  5. If you want to try the example of the IfcOpenHouse, remember to add raw_input() , which exists in the source code file, beneath the code in part "getting started". Otherwise, the viewer window will crash!

Original comment by thomas on 2018-05-29 15:11:14


Thanks for those suggestions. If you're using Anaconda, you can also install ifcopenshell using conda

conda install -c conda-forge -c oce -c dlr-sc -c ifcopenshell ifcopenshell

Indeed, a python script is executed from top to bottom and ends at the last line. You can add a raw_input() [input() in python3] or time.sleep() or ifcopenshell.geom.utils.main_loop() should also work.

@IfcOpenBot
Copy link
Author

Original comment by Franke on 2018-04-12 13:45:06


Hello Thomas,

I have tried to run the code of part "Geting started" after completing all installation steps hopefully, the display window just crashed.

I have also tried to add "raw_input()", and then I could see the display window but it was always running. On chance to manipulate the ifc model there.

I have installed Qt4 and pyqt5. Would that be the prolem? I appreciate it, if you could give me some suggestions.

Original comment by Franke on 2018-04-13 15:52:01


It is a little wird to anser own question, but I hope my experience could help anyone who wanna try something on this.


the setup steps could be simpler:

  1. download Anaconda

  2. build an environment in Anaconda, the python version is not a problem, but you must make sure other packages matching the version of python.

  3. just run the code from http://www.pythonocc.org/download/ in the terminal of the environment.

  4. download the IfcOpenShell package, extract it into the Lib\site-packages\ directory of the Python installation folder. (just following the original instruction)

  5. If you want to try the example of the IfcOpenHouse, remember to add raw_input() , which exists in the source code file, beneath the code in part "getting started". Otherwise, the viewer window will crash!

Original comment by Thi Nguyen on 2020-06-03 14:40:49


Hello Frank and Thomas.

Thank you for your instructions. I tried to follow the instructions of Frank to install pythonocc-core==0.18.1 for python 2.7. At the third step, when i ran the command below in anaconda prompt:

conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18.1

Anaconda prompt ran during 8 hours without results (I can not import OCC in my python script).

Could you please tell me how did you build the environment in Anaconda at your second step?

Thank you in advance for your help!

@IfcOpenBot
Copy link
Author

Original comment by Franke on 2018-04-12 13:45:06


Hello Thomas,

I have tried to run the code of part "Geting started" after completing all installation steps hopefully, the display window just crashed.

I have also tried to add "raw_input()", and then I could see the display window but it was always running. On chance to manipulate the ifc model there.

I have installed Qt4 and pyqt5. Would that be the prolem? I appreciate it, if you could give me some suggestions.

Original comment by Franke on 2018-04-13 15:52:01


It is a little wird to anser own question, but I hope my experience could help anyone who wanna try something on this.


the setup steps could be simpler:

  1. download Anaconda

  2. build an environment in Anaconda, the python version is not a problem, but you must make sure other packages matching the version of python.

  3. just run the code from http://www.pythonocc.org/download/ in the terminal of the environment.

  4. download the IfcOpenShell package, extract it into the Lib\site-packages\ directory of the Python installation folder. (just following the original instruction)

  5. If you want to try the example of the IfcOpenHouse, remember to add raw_input() , which exists in the source code file, beneath the code in part "getting started". Otherwise, the viewer window will crash!

Original comment by Thi Nguyen on 2020-06-03 14:40:49


Hello Frank and Thomas.

Thank you for your instructions. I tried to follow the instructions of Frank to install pythonocc-core==0.18.1 for python 2.7. At the third step, when i ran the command below in anaconda prompt:

conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18.1

Anaconda prompt ran during 8 hours without results (I can not import OCC in my python script).

Could you please tell me how did you build the environment in Anaconda at your second step?

Thank you in advance for your help!

Original comment by thomas on 2020-08-24 12:29:20


Perhaps try without the -c conda-forge for pythonocc version 0.18 all the modules should be available on the other channels. You can also try to install just pythonocc-core without a version number (you'll get a newer version) from the conda-forge or pythonocc channel.

@IfcOpenBot
Copy link
Author

Original comment by Omar Zerhouni on 2020-08-27 14:38:42


It seems there is an incompatibility with the new version of pythonOCC-core.

Running this code, I get this message as an error :

Traceback (most recent call last):

File "C:/Users/TOSHIBA/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/scratch_22.py", line 27, in

occ_display = ifcopenshell.geom.utils.initialize_display()

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\geom\occ_utils.py", line 78, in initialize_display

setup()

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\geom\occ_utils.py", line 57, in setup

viewer = viewer_handle.GetObject()

AttributeError: 'V3d_Viewer' object has no attribute 'GetObject'

TKOpenGl.WinSystem | Type: Error | ID: 6 | Severity: High | Message:

wglMakeCurrent() has failed. Descripteur non valide

@IfcOpenBot
Copy link
Author

Original comment by Omar Zerhouni on 2020-08-27 14:38:42


It seems there is an incompatibility with the new version of pythonOCC-core.

Running this code, I get this message as an error :

Traceback (most recent call last):

File "C:/Users/TOSHIBA/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/scratch_22.py", line 27, in

occ_display = ifcopenshell.geom.utils.initialize_display()

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\geom\occ_utils.py", line 78, in initialize_display

setup()

File "C:\ProgramData\Anaconda3\envs\EnvPy36\lib\site-packages\ifcopenshell\geom\occ_utils.py", line 57, in setup

viewer = viewer_handle.GetObject()

AttributeError: 'V3d_Viewer' object has no attribute 'GetObject'

TKOpenGl.WinSystem | Type: Error | ID: 6 | Severity: High | Message:

wglMakeCurrent() has failed. Descripteur non valide

Original comment by thomas on 2020-09-22 11:50:23


There have been various fixes for compatibility with OCC versions. Can you try a more recent file from the github repo? IfcOpenShell/IfcOpenShell@e2784fb Just substitute the occ_utils.py file you have locally.

@IfcOpenBot
Copy link
Author

Original comment by Hamid Kiavarz on 2020-12-03 07:25:16


What is the equal syntax for the below statements:

topo = OCC.Utils.Topo(shape)

for face in topo.faces():

surf = OCC.BRep.BRep_Tool.Surface(face)

I need to extract the faces of a wall



Thanks,

Hamid

@IfcOpenBot
Copy link
Author

Original comment by Darija on 2021-06-15 13:32:36


I tried to run the code but this error came in, any suggestions?

Thank you in advanced

TypeError: Wrong number or type of arguments for overloaded function 'new_V3d_DirectionalLight'.

Possible C/C++ prototypes are:

V3d_DirectionalLight::V3d_DirectionalLight(V3d_TypeOfOrientation const,Quantity_Color const &,Standard_Boolean const)

V3d_DirectionalLight::V3d_DirectionalLight(gp_Dir const &,Quantity_Color const &,Standard_Boolean const)

@IfcOpenBot
Copy link
Author

Original comment by Darija on 2021-06-15 13:32:36


I tried to run the code but this error came in, any suggestions?

Thank you in advanced

TypeError: Wrong number or type of arguments for overloaded function 'new_V3d_DirectionalLight'.

Possible C/C++ prototypes are:

V3d_DirectionalLight::V3d_DirectionalLight(V3d_TypeOfOrientation const,Quantity_Color const &,Standard_Boolean const)

V3d_DirectionalLight::V3d_DirectionalLight(gp_Dir const &,Quantity_Color const &,Standard_Boolean const)

Original comment by thomas on 2021-08-07 12:51:22


Yes, the PythonOCC version in this example is rather dated. Have a look here for more recent usage https://github.com/IfcOpenShell/IfcOpenShell/blob/dab2d5ce04ee6c4f8e37637184a1b0f083a7e2ee/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py#L93

@IfcOpenBot
Copy link
Author

Original comment by Hamid Kiavarz on 2020-12-03 07:25:16


What is the equal syntax for the below statements:

topo = OCC.Utils.Topo(shape)

for face in topo.faces():

surf = OCC.BRep.BRep_Tool.Surface(face)

I need to extract the faces of a wall



Thanks,

Hamid

Original comment by thomas on 2021-08-07 12:56:27


Use TopExp_Explorer to iterate over the faces

Copy link

wassimj commented Dec 8, 2021

Am I correct that this method of finding interior faces only works if the space is convex? If it is an L-shaped space, I would get some exterior faces pointing towards the Center of Mass.

Copy link
Member

aothms commented Dec 11, 2021

@wassimj True, same applies to the intersection of halfspaces later on. I really tried to minimize the amount of code and complexity.

The tutorial is more aimed at the IFC side of things I suppose, but if you actually want to apply this, it's a important limitation.

It's not unthinkable to provide a more general solution. Conceptually simplest I think would be to simplify the walls into 2d edges and arrange them ccw. That way the interior faces (or edges) in 2d would be on the left.

@pjinwoo1995
Copy link

pjinwoo1995 commented Jun 10, 2022

I am getting this same error msg. I checked out the version and occt seems to be latest. any suggestions?

Thank you in advance

Copy link

The download source code link doesn't seem to be working. Can someone send the link to the source file?

Great work BTW. :)

@aothms
Copy link
Member

aothms commented Jun 22, 2022

@keshavanarayan they are here https://github.com/IfcOpenShell/academy/tree/main/files/scripts

Copy link

I am getting this error. I am trying out the latest ifcopenshell and OCC
Any suggestions on how to proceed.

TypeError                                 Traceback (most recent call last)
Cell In[12], line 8
      6 display_shape = ifcopenshell.geom.utils.display_shape(shape)
      7 if product.is_a('IfcPlate'):
----> 8     ifcopenshell.geom.utils.set_shape_transparency(display_shape, 0.8)

File ~\miniforge3\envs\preset\lib\site-packages\ifcopenshell\geom\occ_utils.py:207, in set_shape_transparency(ais, t)
    206 def set_shape_transparency(ais, t):
--> 207     handle.Context.SetTransparency(ais, t)

File ~\miniforge3\envs\preset\lib\site-packages\OCC\Core\AIS.py:5512, in AIS_InteractiveContext.SetTransparency(self, *args)
   5497 def SetTransparency(self, *args) -> "void":
   5498     r"""
   5499     Provides the transparency settings for viewing the object. the transparency value avalue may be between 0.0, opaque, and 1.0, fully transparent.
   5500 
   (...)
   5510 
   5511     """
-> 5512     return _AIS.AIS_InteractiveContext_SetTransparency(self, *args)

TypeError: AIS_InteractiveContext_SetTransparency expected 4 arguments, got 3```

@Moult
Copy link

Moult commented Mar 2, 2023

IfcOpenShell/IfcOpenShell#1037

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

7 participants