Coder Social home page Coder Social logo

voneiden / ocp-freecad-cam Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 2.0 384 KB

CAM for CadQuery and Build123d by leveraging FreeCAD

Home Page: https://pypi.org/project/ocp-freecad-cam/

License: Apache License 2.0

Python 100.00%
cadquery computer-aided-manufacturing freecad parametric-modelling

ocp-freecad-cam's Introduction

image

Overview

oc-freecad-cam exposes FreeCAD's Path workbench in a fluent python API that takes OCP TopoDS_Shape objects and their wrappers from CadQuery and Build123d to enable generating parametric tool paths from the comfort of your keyboard.

image

⚠ NOTE ⚠

This project is fairly experimental at this stage. Expect bugs and always double-check the generated gcode for naughty surprises.

Usage

See documentation at https://ocp-freecad-cam.readthedocs.io/en/latest/

Installation

ocp-freecad-cam is available on pypi: https://pypi.org/project/ocp-freecad-cam/ ocp-freecad-cam does not attempt to install runtime dependencies since it's designed to run with any combination of these three:

Additionally, FreeCAD module needs to be available.

General guideline for hooking on FreeCAD

There are at least three options to approach this

  1. Using the FreeCAD Python interpreter
  2. Using system interpreter with the same major version as the FreeCAD Python interpreter
  3. Compiling FreeCAD to use the system interpreter

Number one is now the recommended way and will be documented below

Acquiring FreeCAD

Again, three options. Please use at least version 0.21.

  1. Official distributions https://www.freecad.org/downloads.php
  2. Official portable packages https://github.com/FreeCAD/FreeCAD-Bundle/releases
    • includes weekly packages
  3. voneiden's fork of portable packages https://github.com/voneiden/FreeCAD-Bundle/releases
    • uses an older version of OpenSSL and there are also some python 3.11 packages

Linux AppImage installation example using a venv

This is fairly straightforward. Download the AppImage, extract it, create a virtual environment from the included interpreter, include lib, activate it and install your preferred packages.

mkdir freecad
cd freecad 
wget https://github.com/voneiden/FreeCAD-Bundle/releases/download/0.21.2/FreeCAD_0.21.2-2023-12-26-conda-Linux-x86_64-py311.AppImage
chmod +x FreeCAD_0.21.2-2023-12-26-conda-Linux-x86_64-py311.AppImage
./FreeCAD_0.21.2-2023-12-26-conda-Linux-x86_64-py311.AppImage --appimage-extract
./squashfs-root/usr/bin/python -m venv --system-site-packages fcvenv
echo "$PWD/squashfs-root/usr/lib" > fcvenv/lib/python3.11/site-packages/freecad.pth
source fcenv/bin/activate
pip install cadquery build123d ocp-freecad-cam 

Test that your interpreter works by running

python -c "import FreeCAD"

Windows 7z installation example

While I would suggest using WLS, if you want to stick to pure windows, the general idea is the same as above in the linux example with two exceptions.

  1. Instead of "$PWD/squashfs-root/usr/lib" > fcvenv/lib/python3.11/site-packages/freecad.pth use
"$($PWD)\..\src" | Out-File -FilePath "fcvenv\Lib\site-packages\ocp_freecad_cam.pth"

or create the pth file manually somehow. Just note that the venv file structure is a bit different on Windows.

  1. Instead of source you activate the venv with just
.\fcvenv\Scripts\activate

Dev dependecies

Dev dependencies are listed in requirements-dev.txt, generated from requirements-dev.in with pip-compile

Limitations

Pocket3D does not work, possibly related to FreeCAD/FreeCAD#6815 - shouldn't be a big loss though, Surface3D can get the same things done IMO.

VCarve can produce unstable toolpaths, but that is probably a bug in the underlying openvoronoi library. Tweaking the job params may help.

Contributing

Contributions are welcome.

  • Missing params, fixes
  • Tests
  • Documentation

PR's

Apply black and isort and ensure that tests pass. Preferably also include test coverage for new code.

ocp-freecad-cam's People

Contributors

voneiden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ocp-freecad-cam's Issues

Installation - Import error with numpy

Hello, my environment is Linux-Ubuntu with VS Code and working build123d package on python 3.11. freecad_ocp_cam installation is done with freecad.pth file in site-packages and I think it works because I got an error trying to execute freecad_ocp_cam-code which calls numpy from a package in this path.

The error message is:

File "/home/.../freecad/squashfs-root/usr/lib/python3.10/site-packages/numpy/init.py", line 135, in
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.

Has anyone had this before?

Thank you
Markus

Document a conda-free way to use ocp-freecad-cam

Both CadQuery and Build123d install just fine from pip without needing conda. This enables the use of FreeCAD's bundled interpreter directly, simplifying installation greatly.

Saving here for later:

~/Downloads/freecad/squashfs-root/usr/bin/python -m venv --system-site-packages fcvenv
source fcenv/bin/activate
pip install cadquery build123d ocp-freecad-cam 
echo "/home/voneiden/Downloads/freecad/squashfs-root/usr/lib" > fcvenv/lib/python3.11/site-packages/freecad.pth

Support 3d ops

Surface3D and Waterline? Pocket3D doesn't quite work.

  • Surface3D
  • Waterline

Permission denied error on Windows when exporting gcode

ocp-freecad-cam creates a temporary file that is used for capturing the export output from FreeCAD:

with tempfile.NamedTemporaryFile() as tmp_file:
options = ["--no-show-editor"]
if self.units == "imperial":
options.append("--inches")
gcode = processor.export(sublist, tmp_file.name, " ".join(options))

However on windows this crashes, because FreeCAD attemps to re-open the file while it is already open and it is not possible to open the file twice.

Relates to #21

Setup CI

  • Release workflow
  • Test workflow

Test workflow requires a way to download the freecad weekly appimage

Installing in windows

Hello, has anyone success with running ocp_freecad_cam in a windows (11) environment?

When I run python code I got an error "ModuleNotFoundError: No module named 'FreeCAD'". I've tried a lot...

The installation of ocp_freecad_ cam library with pip looks fine (it's not 1.0.0 but 0.94, but this shouldn't an issue)

I think the problem is the path for the freecad-libraries:

echo %PYTHONPATH%
showed only itself %PYTHONPATH%

So I used:

set PYTHONPATH=.;%PYTHONPATH%;C:\Users...\PythonSoftwareFoundation.Python.3.10;C:\Users...\freecad\FreeCAD_weekly-builds-34651-2023-10-13-conda-Windows-x86_64-py310\lib;C:\Users...\freecad\FreeCAD_weekly-builds-34651-2023-10-13-conda-Windows-x86_64-py310\Mod\Draft;C:\Users\tux\freecad\FreeCAD_weekly-builds-34651-2023-10-13-conda-Windows-x86_64-py310\Mod\Path

(and many more ;-) ) to add the directories to the Pathvariable. But I even don't know if the python-environment in windows11 the path variable is handled like this. Python environment is installed via windows app store and it works fine with vs code and "standalone" (with all additional installed python modules).

In freecad-zip for windows I cannot find a python site-packages directory, maybe this is a problem.

I'll try on, and post the solution if I get one.
Any help would be appreciated to cut the waste of time.
Thank you
Markus

Face: exclude_raised does not work

exclude_raised seems to ignore the job model and just use the op model, which in our case is only the face that we intend to operate on. Unsure if this can be worked around.

Job level defaults

While each job needs to be configurable independently, job should have the ability to provide defaults to all ops
(SetupSheet)

  • CoolantMode
  • CoolantModes (?)
  • FinalDepthExpression
  • StartDepthExpression
  • StepDownExpression
  • ClearanceHeightExpression
  • ClearanceHeightOffset
  • SafeHeightExpression
  • SafeHeightOffset

FreeCAD sees incorrect outer wire

Now this one is interesting. With the attached brep, FreeCAD sees the inner wire as the outer wire and chaos ensues. FreeCAD uses ShapeAnalysis.OuterWire to determine the outer wire whereas cadquery and build123d use BRepTools.OuterWire.

The face was generated by build123d. Running ShapeFix on it seems to resolve the issue.

outer_wire_bug.brep.tar.gz

Visualizer: input vector has zero norm

return gp_Dir(circle_normal.X(), circle_normal.Y(), circle_normal.Z())

OCP.Standard.Standard_ConstructionError: gp_Dir() - input vector has zero norm

Support OCP Cad Viewer

OCP Cad Viewer needs a bit different approach, but it is possible to render toolpaths as edges so this should be perfectly doable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.