For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

pythonOCC

Thomas Paviot's picture
Forums: 

Hello,

I've been working, for a couple of weeks, on a python wrapper for OpenCascade 6.2.0 library. The development is in a very early stage, but i decided to release my work under a free licence (CeCILL) and set up different tools to enable collaborative work on this project.

You can find info, mailing list, SVN anonymous access, prebuilt binaries for Windows on the project web page:

http://www.minerva-plm.org/pythonOCC/

You're welcome to help in any way(testing, bug report, patches, doc etc.). Only 20 out of 4000 objects are currently wrapped. Py++ code generator for Boost.Python library is used to achieve the work.

Regards,

Thomas Paviot
thomas_dot_paviot_at_supmeca_dot_fr

Darren's picture

Hi,
This sounds like a great project. I am a user of Blender 3d (which also uses python), and I can see these would be of great benefit for use with Blender.

You have said that currently only 20 objects are wrappped. What are these and can they provide cad or solid modelling fuctions to Blender - or should I wait until most of them are wrapped before they can be of benefit?

Best of luck with your work. It will be much apreciated.

Thomas Paviot's picture

pythonOCC is intented to provide a rapid prototyping tool for OpenCascade apps development.

There are currently 3 types of wrapped objects:
- gp* : gp_Lin, gp_Pnt, etc. excepted gp_Mat and gp_Mat2d
- GCE2d* : GCE2d_MakeLine, etc.
- GC* : GC_MakeLine, GC_MakeCircle, etc.

PY++ is a very convenient tool to develop Python bindings for C++ libs and the number of available object should quickly grow. I plan to wrap the whole OCC library but it's very time consuming. That's why I expect help from OCC users, once the development framework will be completely uploaded to the SVN repository I set up.

Steve's picture

Hello,

why are you not using the wrapper classes form http://jcae.sourceforge.net/, which are compiled with swig for java. But you could compile it also for any other language like Python

Thomas Paviot's picture

Hello,

That's what I did in a first step. Although I had a few problem while hacking *.i jcae files in order to create a Python wrapper, another issue lead me to Py++ : the high number of OpenCascade classes require an automated tool to generate all the .i Swig files. I did not find such a tool.

Dan Heeks's picture

Thomas,
This is just what I need for a python CAD/CAM project I am planning.
I have tried this link http://www.minerva-plm.org/pythonOCC/
The link for "2. pythonOCC 0.15 Windows Installer for Python 2.4." works OK,
but the link for "1. pythonOCC 0.15 Windows Installer for Python 2.5." does not work.
Does this exe exist?
Dan Heeks

Thomas Paviot's picture

Dan,

The link was broken. I just uploaded a new release of pythonOCC that should work for both Python 2.4 and Python 2.5. Note that I work under Windows and I did not try the wrapper for Unix or Linux. It's in my "todo" list.

The number of wrapped object significantly grew and can be accessed from http://www.minerva-plm.org/pythonOCC/pythonOCC_APIREF.html .

Regards,

Thomas

Dan Heeks's picture

Thomas, thank you! It works now.

Dan Heeks's picture

How do I use GC_MakeLine?

I tried the example:

P1 = gp.gp_Pnt2d(1,2)
P2 = gp.gp_Pnt2d(3,-5.1)
makeline = GCE2d.GCE2d_MakeLine(P1,P2)
makeline.IsDone()
makeline.Status()

and I got this error:

makeline.Status()
TypeError: No to_python (by-value) converter found for C++ type: enum gce_ErrorType

Thomas Paviot's picture

I forgot to include gce_ErrorType enum in gce module. I fixed it and should be correct in the next release.

Thomas Paviot's picture

Dan,

I uploadad a new release that fixes that bug and adds new wrappers for following modeling modules : gce, Geom, Convert and Geom2d.

Available at : http://www.minerva-plm.org/pythonOCC

Thomas

Dan Heeks's picture

Yes, this fixes the problem. Thanks!
All this code now works:
P1 = gp.gp_Pnt2d(1,2)
P2 = gp.gp_Pnt2d(3,-5.1)
makeline = GCE2d.GCE2d_MakeLine(P1,P2)
makeline.IsDone()
makeline.Status()

shape = BRep.BRepPrimAPI_MakeSphere(20);
shape2 = BRep.BRepPrimAPI_MakeSphere(gp.gp_Pnt(10,0, 0),22);
ShapeCut = BRep.BRepAlgoAPI_Cut(shape, shape2);

Can I use this function yet? ( I want to use triangulation )
BRep.BRepMesh_Mesh(ShapeCut, 0.1);

Thomas Paviot's picture

The Mesh algorithms have not yet been wrapped.

BTW, I updated the APIREF page with a more readable one built upon pydoc.

See http://www.minerva-plm.org/pythonOCC/APIREF/OCC.html

Thomas Paviot's picture

I just released a new version of pythonOCC. Basic BRep mesh algorithms are implemented and a lot of member functions have been added for each class (new inheritance mechanism). IGES export is possible.

URL : http://www.minerva-plm.org/pythonOCC

New API Reference : http://www.minerva-plm.org/pythonOCC/APIREF/OCC.html

Dan Heeks's picture

Good. This allows BRep.BRepMesh.Mesh to work. This is getting exciting now.
shape = BRep.BRepPrimAPI_MakeSphere(20)
shape2 = BRep.BRepPrimAPI_MakeSphere(gp.gp_Pnt(10,0, 0),22)
ShapeCut = BRep.BRepAlgoAPI_Cut(shape, shape2)
cut_shape = ShapeCut.Shape()
mesh = BRep.BRepMesh.Mesh(cut_shape, 0.1)

Next, I want to transfer this C code to Python ( to render all the triangles with OpenGL )
TopExp_Explorer ex;
for ( ex.Init( m_shape, TopAbs_FACE ) ; ex.More(); ex.Next() )
{
TopoDS_Face F = TopoDS::Face(ex.Current());
TopLoc_Location L;
Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(F,L);
const Poly_Array1OfTriangle &triangles = facing->Triangles();
const TColgp_Array1OfPnt & nodes = facing->Nodes();
if (!facing.IsNull())
{
for ( int i=facing->NbTriangles(); i >= 1; --i ) // (indeksy 1...N)
{
Poly_Triangle triangle = triangles(i);
Standard_Integer node1,node2,node3;
triangle.Get(node1, node2, node3);

so, I am stuck trying to find TopExp_Explorer

Thomas Paviot's picture

The new release of pythonOCC adds TopExp module as well as IGES import fixes and STL import/export.

Enjoy.

Dan Heeks's picture

Thanks.
This works OK now:
mesh = BRep.BRepMesh.Mesh(cut_shape, 0.1)
ex = TopExp.TopExp_Explorer()
ex.Init(cut_shape, TopAbs.TopAbs_FACE)
while ex.More():
F = TopoDS.TopoDS.Face(ex.Current())
# Get triangulation
L = TopLoc.TopLoc_Location()

I am now stuck trying to convert this C code
Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(F,L);