Accessing PythonOCC in FreeCAD 0.20

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Zoltan
Posts: 62
Joined: Wed Jul 07, 2021 10:08 am

Accessing PythonOCC in FreeCAD 0.20

Post by Zoltan »

My script relies on PythonOCC. Now,

Code: Select all

import OCC
does not work any more in version 0.20 and the (currently) latest weekly build either.
On the other hand, the Part.__toPythonOCC__ and Part.__toPythonOCC__ functions are still present. Note that __toPythonOCC__ throws the following error when a Part.Shape object is passed:

Code: Select all

Part.OCCError: SWIG: Cannot find type information for requested type: TopoDS_Shape *
I could not find the OCC package on the usr/lib/python3.10/site-packages/ path (after extracting the Appimage), so I guess it is not packaged with conda any more. Is there a FreeCAD binary distribution that still contains PythonOCC? If not, I need to install it by myself into the conda virtual environment. In that case, which PythonOCC should I install, which is compatible with FreeCAD 0.20?
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Gift »

You need the conda build
Zoltan
Posts: 62
Joined: Wed Jul 07, 2021 10:08 am

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Zoltan »

Gift wrote: Thu Jun 23, 2022 6:44 pm You need the conda build
Thank you, but that AppImage does not contain PythonOCC either. Same import error. The packages.txt file in the root of the extracted AppImage also lacks the OCC package.
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Gift »

looo wrote: Ping
Do you have any idea?
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Accessing PythonOCC in FreeCAD 0.20

Post by looo »

I excluded pythonocc from the bundles as I wanted to update to occt7.6 and pythonocc is not ready for occt7.6. Also I did not know others were relying on pythocc.

What functionality do you need from pythocc. Maybe you can make a feature request so Freecad-developers can add this functionality.
Zoltan
Posts: 62
Joined: Wed Jul 07, 2021 10:08 am

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Zoltan »

looo wrote: Fri Jun 24, 2022 9:39 am What functionality do you need from pythocc. Maybe you can make a feature request so Freecad-developers can add this functionality.
I use it in the following code for my most important project:

Code: Select all

from OCC.Core.BRepProj import BRepProj_Projection
from OCC.Core.gp import gp_Dir

def project(curve, surface, direction):
        """Cylindrical projection of a curve onto a surface.
        Parameters
        ----------
        curve : Part.Wire
            Curve to be projected.
        surface : Part.Face
            Surface to project onto.
        direction : tuple of float
            Direction vector of the projection, tuple of three numbers.
        Returns
        -------
        Part.Compound
            A compound object, containing the parts of the projected curve.
        Raises
        ------
        Exception
            If the projection algorithm of OpenCASCADE fails. This typically happens if the
            projected curve would not lie on the surface.
        Notes
        -----
        This function is a wrapper around the cylindrical projection functionality available in
        OpenCASCADE. For details, see its documentation:
        https://dev.opencascade.org/doc/refman/html/class_b_rep_proj___projection.html
        """
        curve = Part.__toPythonOCC__(curve)
        surface = Part.__toPythonOCC__(surface)
        projection_direction = gp_Dir(*direction)
        proj = BRepProj_Projection(curve, surface, projection_direction)
        if not proj.IsDone():
            raise Exception('Projection failed.')
        return Part.__fromPythonOCC__(proj.Shape())
I have other, less important, projects where I use OCC here and there. It would be nice if it was shipped with FreeCAD, so the users would not need to manually compile it or fetch the binaries from conda.
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Accessing PythonOCC in FreeCAD 0.20

Post by onekk »

Zoltan wrote: Fri Jun 24, 2022 10:08 am

This could not be achieved using Geom2D things:


https://forum.freecadweb.org/viewtopic.php?f=22&t=65844

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Accessing PythonOCC in FreeCAD 0.20

Post by looo »

Ok I will try to add it back in the next couple of days. But anyway it would be nice if you try to make a feature request for the necessary stuff so we can use this functionality directly in freecad.
Zoltan
Posts: 62
Joined: Wed Jul 07, 2021 10:08 am

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Zoltan »

I am not against making a feature request, but this is Python code. On the other hand, this basic functionality (projection) fits to the Part module, which is coded in C++, with which I have no familiarity.
Zoltan
Posts: 62
Joined: Wed Jul 07, 2021 10:08 am

Re: Accessing PythonOCC in FreeCAD 0.20

Post by Zoltan »

onekk wrote: Fri Jun 24, 2022 10:26 am This could not be achieved using Geom2D things:

https://forum.freecadweb.org/viewtopic.php?f=22&t=65844
OK, I will look into it soon.
Post Reply