pythonOCC (http://www.pythonocc.org) is a wrapper for the free geometry library OpenCASCADE (https://www.opencascade.com/).
It allows the programmer to leverage the extensive libraries and ease of use of the Python language with the powerful CAD tools of OpenCASCADE.
The steps of this tutorial were performed in Windows, but it should work similarly under Linux after the first step.
First, we will install the Anaconda package manager which comes with Python. From https://www.anaconda.com/distribution/#download-section, download the Python 3.7 version for your OS.
Once you have installed Anaconda, run the prompt:
From the prompt, check Python is there by simply typing Python. Note- Python version will be downgraded when installing pythonOCC. You are now in the Python interpreter. Type exit() to go back to the Anaconda prompt.
As per instructions at http://www.pythonocc.org/download/ install pythonOCC in Anaconda: conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18.1
Go back into the Python interpreter and check OpenCASCADE libraries are available:
We will write a program to load and display an IGES file using pythonOCC. You can download a sample IGES file here:
This is the code. Save it with .py extension:
#load needed libraries from OCC import IGESControl from OCC.IGESControl import IGESControl_Reader from OCC.Display.SimpleGui import init_display from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox #create new IGES reader class reader = IGESControl_Reader() #read file, make sure you update path. Note in Windows slash needs to be used reader.ReadFile('D:/projects/pythonocc/test.iges') #no idea what this does but without it the shape won't be created :) reader.TransferRoots() #generate Shape shape = reader.Shape() #initialize built-in viewer display, start_display, add_menu, add_function_to_menu = init_display() #load shape from IGES display.DisplayShape(shape, update=True) #show viewer start_display()
From the Anaconda prompt (not the Python interpreter!) launch python with the .py file as argument:
The viewer should pop up displaying your IGES file:
One thought on “Quick tutorial for getting started with pythonOCC”
[…] it set up, or are unfamiliar with pythonOCC, the Python OpenCASCADE wrapper, please go our tutorial here first to to set it up alongside Anaconda […]