Open Source Python Library for 3D Modeling & Dataexchange
Free Python library for 3D modeling and Dataexchange handling. It allows working with 3D CAD, BIM, PLM and CAM File Formats via Python API online.
PythonOCC-Core is an open-source 3D modeling and CAD automation library built on top of the OpenCASCADE Technology (OCCT) kernel. It harnesses the power of Python, a popular and user-friendly programming language, to provide a robust platform for creating, modifying, and analyzing complex 3D geometries. It brings together the best of both worlds: the flexibility and simplicity of Python and the powerful modeling capabilities of OCCT. With its intuitive Python interface and extensive set of functionalities, the library provides a seamless experience for both beginners and seasoned developers in the field.
PythonOCC-Core's visualization capabilities make it suitable for game development and virtual reality applications. It allows the creation of immersive environments, realistic simulations, and interactive experiences. There are several other important features part of the library, such as processing Medical Imaging, 3D geometry manipulation, CAD Data import and export, advanced simulations on 3D models, 3D visualization in a web browser, 3D visualization from the most famous Python GUIs, and so on. The library also plays a vital role in scientific research areas such as computational physics, material science, and biomedical engineering.
PythonOCC-Core enables architects and engineers to create parametric models, generate building layouts, and perform structural analysis. It enhances the design process, enabling accurate visualization and efficient collaboration. The library is widely used in industries like automotive, aerospace, and product design to create and optimize complex 3D models. It facilitates rapid prototyping, simulation, and analysis of designs, streamlining the product development cycle. Its integration with Python's simplicity and OCCT's robustness makes it a popular choice among software professionals and developers in various industries. By leveraging PythonOCC-Core, developers can unleash their creativity and automate complex CAD tasks, paving the way for innovation and efficiency in the world of 3D modeling and design.
At A Glance
An overview of PythonOCC-Core features.
- Create 3D Geometries
- Edit 3D Geometries
- Analyze 3D Geometries
- CAD Data import
- Mesh simplification
- CAD Data Export
- Advanced simulations
- 3D visualization
- Character rigging
- Facial tracking
- 2D Curves
PythonOCC-Core only requires Python 3.5+ and pytorch (>=1.5)
- Python 3.5 and above.
Getting Started with PythonOCC-Core
The easiest way to install PythonOCC-Core stable release is using pip. Please use the following command for a smooth installation.
Install PythonOCC-Core via pip
pip install pythonocc-core
Install PythonOCC-Core via Conda
conda install -c conda-forge pythonocc-core
You can also install PythonOCC-Core via Conda using the following command.
conda install -c 1adrianb face_alignment
You can download the compiled shared library from Github repository.
Create & Manage 3D Geometries via Python
The open source PythonOCC-Core library has included complete support for creating and managing 3D models inside Python applications. Moreover, the library offers an extensive set of tools for creating and manipulating 3D geometric shapes, including points, curves, surfaces, and solids. It provides a wide range of algorithms for constructing and modifying complex objects, such as Boolean operations, filleting, and chamfering. The following example shows how software developers can create core geometry bounding boxes using python commands.
How to Compute and Display Bounding Boxes inside Python Apps?
def get_boundingbox(shape, tol=1e-6, use_mesh=True): bbox = Bnd_Box() bbox.SetGap(tol) if use_mesh: mesh = BRepMesh_IncrementalMesh() mesh.SetParallelDefault(True) mesh.SetShape(shape) mesh.Perform() if not mesh.IsDone(): raise AssertionError("Mesh not done.") brepbndlib_Add(shape, bbox, use_mesh) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() return xmin, ymin, zmin, xmax, ymax, zmax, xmax - xmin, ymax - ymin, zmax - zmin print("Box bounding box computation") box_shape = BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape() bb1 = get_boundingbox(box_shape) print(bb1) print("Cylinder bounding box computation") cyl_shape = BRepPrimAPI_MakeCylinder(10.0, 20.0).Shape() bb2 = get_boundingbox(cyl_shape) print(bb2) print("Torus bounding box computation") torus_shape = BRepPrimAPI_MakeCylinder(15.0, 5.0).Shape() bb3 = get_boundingbox(torus_shape) print(bb3)
CAD Automation using Python API
The open source PythonOCC-Core library has provided very useful features for handling various tasks related to CAD diagrams. The library supports various file formats commonly used in CAD, including STEP, IGES, STL, and BREP. The library enables developers to automate repetitive CAD tasks, such as generating parametric designs, performing geometric transformations, and conducting geometric analysis. It provides a high-level API that simplifies the implementation of CAD workflows, making it an ideal choice for building CAD automation tools.
Create Shape & Export It to CAD STEP File Format via Python API
from __future__ import print_function from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_AsIs from OCC.Core.Interface import Interface_Static_SetCVal from OCC.Core.IFSelect import IFSelect_RetDone # creates a basic shape box_s = BRepPrimAPI_MakeBox(10, 20, 30).Shape() # initialize the STEP exporter step_writer = STEPControl_Writer() dd = step_writer.WS().TransferWriter().FinderProcess() print(dd) Interface_Static_SetCVal("write.step.schema", "AP203") # transfer shapes and write file step_writer.Transfer(box_s, STEPControl_AsIs) status = step_writer.Write("box.stp") if status != IFSelect_RetDone: raise AssertionError("load failed")