solvespace/cython
KmolYuan da5cd070ab Wrap solve result. 2022-02-08 14:40:44 +08:00
..
platform Apply PEP 517. 2021-02-12 14:21:07 +08:00
python_solvespace Wrap solve result. 2022-02-08 14:40:44 +08:00
test Adjust unit test. 2021-12-11 21:06:33 +08:00
.gitignore Fix static linking of stdlibs. 2020-07-31 17:05:09 +08:00
MANIFEST.in Apply PEP 517. 2021-02-12 14:21:07 +08:00
README.md Hide copy API. 2021-12-14 09:44:45 +08:00
pyproject.toml Apply PEP 517. 2021-02-12 14:21:07 +08:00
setup.cfg Bump version and update Python support. 2021-12-20 17:10:21 +08:00
setup.py Apply PEP 517. 2021-02-12 14:21:07 +08:00

README.md

PyPI GitHub license

python-solvespace

Python library from the solver of SolveSpace, an open source CAD software.

The example extracted from unit test:

from python_solvespace import SolverSystem, ResultFlag

sys = SolverSystem()
wp = sys.create_2d_base()  # Workplane (Entity)
p0 = sys.add_point_2d(0, 0, wp)  # Entity
sys.dragged(p0, wp)  # Make a constraint with the entity
...
line0 = sys.add_line_2d(p0, p1, wp)  # Create entity with others
...
line1 = sys.add_line_2d(p0, p3, wp)
sys.angle(line0, line1, 45, wp)  # Constrain two entities
line1 = sys.entity(-1)  # Entity handle can be re-generated and negatively indexed
...
if sys.solve() == ResultFlag.OKAY:
   # Get the result (unpack from the entity or parameters)
   # x and y are actually float type
   dof = sys.dof()
   x, y = sys.params(p2.params)
   ...
else:
   # Error!
   # Get the list of all constraints
   failures = sys.failures()
   ...

Solver can also be serialized and copied, but can not modify or undo last step.

import pickle
print(pickle.dumps(sys))

sys_new = sys.copy()

The entity and parameter handles should have the same lifetime to the solver.

Install

pip install python-solvespace

Build and Test (Repository)

First build and install the module from the repo:

git submodule update --init extlib/mimalloc
cd cython
pip install -e .

Build the module:

pip install -e . --no-deps

Run the unit tests:

python -m unittest

Uninstall the module:

pip uninstall python-solvespace