35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from python_solvespace import SolverSystem, ResultFlag
|
|
|
|
def solve_constraint():
|
|
solv = SolverSystem()
|
|
wp = solv.create_2d_base() # Workplane (Entity)
|
|
p0 = solv.add_point_2d(0, 0, wp) # Entity
|
|
p1 = solv.add_point_2d(10, 10, wp) # Entity
|
|
p2 = solv.add_point_2d(0, 10, wp) # Entity
|
|
solv.dragged(p0, wp) # Make a constraint with the entity
|
|
|
|
line0 = solv.add_line_2d(p0, p1, wp) # Create entity with others
|
|
line1 = solv.add_line_2d(p0, p2, wp)
|
|
#solv.angle(line0, line1, 45, wp) # Constrain two entities
|
|
solv.coincident(p0, p1, wp)
|
|
solv.add_constraint(100006, wp, 0, p1,p2, line0, line1)
|
|
|
|
line1 = solv.entity(-1) # Entity handle can be re-generated and negatively indexed
|
|
solv.
|
|
if solv.solve() == ResultFlag.OKAY:
|
|
# Get the result (unpack from the entity or parameters)
|
|
# x and y are actually float type
|
|
dof = solv.dof()
|
|
x, y = solv.params(p1.params)
|
|
print(dof)
|
|
print(x)
|
|
print(y)
|
|
|
|
else:
|
|
# Error!
|
|
# Get the list of all constraints
|
|
failures = solv.failures()
|
|
print(failures)
|
|
...
|
|
|
|
solve_constraint() |