slvstopy is a Python library for reading SolveSpace drawings as a python-solvespace system.

Motivation

This library addresses the need to analyze complex 3D mechanisms. SolveSpace is a parametric 3d CAD tool with a graphical 3d modelling interface. SolveSpace provides basic analysis tools; however, it is not flexible enough for complex 3d mechanisms. The python-solvespace project adds Python bindings to the SolveSpace geometric constraint solver. Analyzing a mechanism in Python enables analysis using popular libraries such as sympy.geometry.

Use Case - Suspension Kinematics

Kinematic analysis of an automotive suspension consists of four parts:

  1. Constraining the mechanism
  2. Solving a geometric constraint problem
  3. Post-process the results
  4. Automotive specific analysis

The slvstopy library aids in solving the geometric constraint problem such that the solution can be post-processed outside of SolveSpace.

Constraining the mechanism can be unintuitive, especially when the constraints are not initially known. This process can be aided through the use of a 3d CAD package. The SolveSpace graphical user interface makes it easy to draw and visualize the mechanism.

When the suspension mechanism is complete, the *.slvs file can be read as a SolverSystem.

from slvstopy import Slvstopy

slvs_to_py = Slvstopy(file_path="macpherson-strut.slvs")
system, entities = slvs_to_py.generate_system()

Constraints and parameters can be updated to articulate the mechanism. Entity IDs are retrieved by inspecting the *.slvs file in a text editor.

from python_solvespace import Entity

# Example of adding a constraint
wheel_entity_id = "00040000"
xy_plane_entity_id = "00010000"
system.distance(
    entities[wheel_entity_id],
    entities[xy_plane_entity_id],
    100,
    Entity.FREE_IN_3D,
)

# Example of updating a parameter
steering_rack_entity_id = "00050000"
system.set_params(
    entities[steering_rack_entity_id],
    (-75.2, 311.9, -29.1),
)

The mechanism is now ready to be solved.

from python_solvespace import ResultFlag

result = system.solve()
assert result == ResultFlag.OKAY

If the result flag returns ResultFlag.OKAY, the solver successfully converged. The updated position of a point can be retrieved.

endlink_entity_id = "00060000"
endlink_position = system.params(entities[endlink_entity_id].params)

Caveats

  • Groups are not supported; mechanisms must be in a single sketch
  • Requests are not supported
  • Not all entities and constraints are supported
  • Certain constraints may cause instability; avoid dimensioning from the reference planes, use ‘dragged’ constraints where possible

Benefits

  • Single source of truth (*.slvs file)
  • Can use SolveSpace 3d modelling tools to develop and constrain the mechanism
  • Can use other Python libraries to post-process results

*Based on 7d3015 at the time of writing