# [PYTHON] 3D or D with Py

There are many opportunities to perform numerical calculations (mainly using Python) even when using 3D CAD, and there is a request to generate (must) data for 3D (STEP, IGES, STL) based on numerical calculations. It is a solution while the number is increasing.

## Conclusion

OpenCASCADE is famous for C ++ and Deathly Hallows Open Cascade Technology, but the original is a library composed of 1 million lines in C ++, so if you try to use it It's very difficult. So I use the great code pythonocc-core, which is a Wrap of almost all OpenCASCADE to Python.

## Install method

``````# Python 3.8
conda install -c conda-forge pythonocc-core
# Python 3.7 or 3.6
conda install -c dlr-sc pythonocc-core
``````

It is a good code group to put in additionally.

• https://github.com/tpaviot/pythonocc-core
• https://github.com/tpaviot/pythonocc-demos
• https://github.com/tpaviot/pythonocc-utils

## How to use

This is a very simple usage example.

``````from OCC.Display.SimpleGui import init_display
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir
from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge

display.DisplayShape(gp_Pnt())

p1 = gp_Pnt(0, 0, 0)
p2 = gp_Pnt(0, 0, 10)
edge = BRepBuilderAPI_MakeEdge(p1, p2)
result = edge.Edge()
write_step_file(result, "pythonocc-core.stp")
display.DisplayShape(result)

display.FitAll()
display.View.Dump("pythonocc-core.png ")
start_display()
``````

When you run it, you will see a photo of the 3D Viewer and its Viewer and a STEP file called pythonocc-core.stp.

How to use it is yet to come. After that, you can move the 3D Viewer around, spit out files other than STEP (IGES, STL, BRep), or create your favorite shape.

There are many samples at demo.