2019-09-23 13:20:10 +00:00
|
|
|
[![PyPI](https://img.shields.io/pypi/v/python-solvespace.svg)](https://pypi.org/project/python-solvespace/)
|
2019-05-28 12:00:15 +00:00
|
|
|
[![GitHub license](https://img.shields.io/badge/license-GPLv3+-blue.svg)](https://raw.githubusercontent.com/KmolYuan/solvespace/master/LICENSE)
|
|
|
|
|
2019-09-25 10:32:27 +00:00
|
|
|
# python-solvespace
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2020-07-09 03:40:27 +00:00
|
|
|
Python library from the solver of SolveSpace, an open source CAD software.
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2019-09-25 10:32:27 +00:00
|
|
|
+ [Python API](https://pyslvs-ui.readthedocs.io/en/stable/python-solvespace-api/)
|
|
|
|
+ [C API](https://github.com/solvespace/solvespace/blob/master/exposed/DOC.txt)
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2021-12-12 04:37:05 +00:00
|
|
|
The example extracted from unit test:
|
|
|
|
|
|
|
|
```python
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
|
|
|
|
```python
|
|
|
|
import pickle
|
|
|
|
print(pickle.dumps(sys))
|
|
|
|
|
|
|
|
sys_new = sys.copy()
|
|
|
|
# equivalent to
|
|
|
|
func, args = sys.__reduce__()
|
|
|
|
sys_new = func(*args)
|
|
|
|
```
|
|
|
|
|
2019-09-25 10:32:27 +00:00
|
|
|
# Install
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2019-09-25 10:32:27 +00:00
|
|
|
```bash
|
|
|
|
pip install python-solvespace
|
|
|
|
```
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2019-09-25 10:32:27 +00:00
|
|
|
# Build and Test (Repository)
|
2019-05-28 12:00:15 +00:00
|
|
|
|
2021-12-12 04:37:05 +00:00
|
|
|
First build and install the module from the repo:
|
2019-05-28 12:00:15 +00:00
|
|
|
|
|
|
|
```bash
|
2021-12-12 04:37:05 +00:00
|
|
|
git submodule update --init extlib/mimalloc
|
|
|
|
cd cython
|
2021-02-12 06:21:07 +00:00
|
|
|
pip install -e .
|
2019-05-28 12:00:15 +00:00
|
|
|
```
|
|
|
|
|
2021-12-12 04:37:05 +00:00
|
|
|
Build the module:
|
2019-05-28 12:00:15 +00:00
|
|
|
|
|
|
|
```bash
|
2021-12-12 04:37:05 +00:00
|
|
|
pip install -e . --no-deps
|
|
|
|
```
|
|
|
|
|
|
|
|
Run the unit tests:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
python -m unittest
|
2019-05-28 12:00:15 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Uninstall the module:
|
|
|
|
|
|
|
|
```bash
|
2019-09-25 10:32:27 +00:00
|
|
|
pip uninstall python-solvespace
|
2019-05-28 12:00:15 +00:00
|
|
|
```
|