Skip to content

Commit 6dfc129

Browse files
committed
Param and Point can be passed to SolidPython (which will convert them to a double resp. a list of doubles)
1 parent 814928e commit 6dfc129

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

solid-python

solvespace/exposed/slvs.i

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public:
126126
__swig_setmethods__["value"] = SetValue
127127
if _newclass: value = property(GetValue, SetValue)
128128
%}
129+
130+
%pythoncode %{
131+
def to_openscad(self):
132+
return self.value
133+
%}
129134
};
130135

131136
class Entity {
@@ -161,6 +166,11 @@ public:
161166
Param x() throw(invalid_state_exception);
162167
Param y() throw(invalid_state_exception);
163168
Param z() throw(invalid_state_exception);
169+
170+
%pythoncode %{
171+
def to_openscad(self):
172+
return [ self.x().value, self.y().value, self.z().value ]
173+
%}
164174
};
165175

166176
class Normal3d : public Entity {
@@ -205,6 +215,11 @@ public:
205215
Param u() throw(invalid_state_exception);
206216
Param v() throw(invalid_state_exception);
207217
Workplane workplane() throw(invalid_state_exception);
218+
219+
%pythoncode %{
220+
def to_openscad(self):
221+
return [ self.u().value, self.v().value ]
222+
%}
208223
};
209224

210225
class LineSegment : public Entity {

solvespace/exposed/solid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../solid-python/solid/

solvespace/exposed/test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,26 @@ def test_example2d(self):
247247
printf("system nonconvergent");
248248
self.assertTrue(False, "solve failed")
249249

250+
def test_with_solidpython(self):
251+
import solid
252+
253+
sys = System()
254+
255+
a = sys.add_param(10)
256+
b = sys.add_param(3)
257+
c = sys.add_param(17)
258+
d = sys.add_param(23)
259+
260+
#NOTE We should use Point2d, but I don't want to
261+
# create a workplane just for that.
262+
p1 = Point3d(Param(7), Param(2), Param(0), sys)
263+
264+
poly = solid.polygon([[a,b],[c,d], [0,0], p1])
265+
266+
self.assertEqual(
267+
solid.scad_render(poly),
268+
"\n\npolygon(paths = [[0, 1, 2, 3]], points = [[10.0000000000, 3.0000000000], [17.0000000000, 23.0000000000], [0, 0], [7.0000000000, 2.0000000000, 0.0000000000]]);")
269+
270+
250271
if __name__ == '__main__':
251272
unittest.main()

0 commit comments

Comments
 (0)