Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4159

Trying to get IfcOpenShell running in RhinoCode

$
0
0

Hello @eirannejad (and everybody else :slight_smile: )

following these examples, I managed to get basic IfcOpenShell queries running in RhinoCode (in Rhino 8.8 SRC from yesterday). I manually downloaded IfcOpenShell for Python 3.9 from here and installed it into .rhinocode in my user folder.
Now I’m trying to get into Geometry Processing via IfcOpenShell… Follwoing this guide, I tried to get the following code snippet running:

import ifcopenshell
import ifcopenshell.geom

ifc_file = ifcopenshell.open('model.ifc')
element = ifc_file.by_type('IfcWall')[0]

settings = ifcopenshell.geom.settings()
settings.set(settings.USE_PYTHON_OPENCASCADE, True)

try:
    shape = geom.create_shape(settings, element)
    geometry = shape.geometry # see #1124
    # These are methods of the TopoDS_Shape class from pythonOCC
    shape_gpXYZ = geometry.Location().Transformation().TranslationPart()
    # These are methods of the gpXYZ class from pythonOCC
    print(shape_gpXYZ.X(), shape_gpXYZ.Y(), shape_gpXYZ.Z())
except:
    print("Shape creation failed")

Unfortunately, to be able to access settings.USE_PYTHON_OPENCASCADE depends on pythonOCC, a package for which there only seems to be a Conda install avaliable (see PythonOCC getting started guide).

Searching for solutions how to use Conda in RhinoCode I found your post on how to point RhinoCode to an existing Conda Environment. So using MiniConda I installed both IfcOpenShell and pythonOCC-core into a new Conda Environment:

conda create -n openshell python=3.9
conda activate openshell
conda install -c conda-forge ifcopenshell pythonocc-core

Then I pointed RhinoCode to that Environment via a new path entry in the Editor Options and using

# env: C:\Users\[username]\miniconda3\envs\openshell\Lib\site-packages

IfcOpenShell seems to be found flawlessly that way, unfortunately the error with the missing dependency remains. I boiled the script down to the following 5 lines to be able to cath the error more easily:

Then I tried it the other way round and executed the exact same script (without the line with # env) directly in the Conda Environment Python. There it worked flawlessly and I could see USE_PYTHON_OPENCASCADE being an element of the settings object.

Please excuse this lengthy description, I’m a simple python scripter and not too much into things like PIP and Conda so I tried to bite my way through… Unfortunately I’m now stuck and don’t know how to continue. Do you maybe have a hint on how I could get this to work? When I managed to get it running in the Conda Environemnt I felt like very close to the solution… but I don’t know to take it over to Rhino…

It would be great if you could give me a hint on how to move on… Thanks!

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4159

Latest Images

Trending Articles



Latest Images