1. Products
  2.   3D
  3.   Python
  4.   PythonOCC-Core
 
  

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.

What is PythonOCC-Core Library ?

PythonOCC-Core is a free 3D modeling and CAD automation library. It uses Python, a widely used programming language, on top of the OpenCASCADE Technology (OCCT) kernel. This combination offers a strong foundation for making, changing, and studying intricate 3D shapes. By blending Python’s ease with OCCT’s potent modeling tools, you get a versatile and effective tool at your disposal. 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. it empowers architects and engineers like you to craft parametric models, produce building layouts, and conduct structural analysis. This tool improves the design workflow, allowing for precise visualization and effective teamwork. It is popular across various sectors such as automotive, aerospace, and product design for developing and refining intricate 3D models. With this library, you can expedite prototyping, simulations, and design analysis, thus simplifying the process of product development.

PythonOCC-Core’s visualization features are perfect for creating games and virtual reality experiences. With this tool, you can build engaging environments, lifelike simulations, and interactive adventures. Beyond that, the library offers essential functions like working with Medical Imaging, manipulating 3D geometry, importing and exporting CAD Data, running advanced simulations on 3D models, visualizing 3D content on web browsers, and showcasing 3D visuals through popular Python GUIs. . The library also plays a vital role in scientific research areas such as computational physics, material science, and biomedical engineering. Many software professionals and developers in different industries find PythonOCC-Core appealing because it combines Python’s ease and OCCT’s strength. With PythonOCC-Core, you can boost your creativity and streamline intricate CAD processes. This opens up new possibilities for innovation and productivity in 3D modeling and design.

Previous Next

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.

How to 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")