openpyscad
openpyscad copied to clipboard
linear_extrude does not work for Difference, Union & Intersection
Hi thank you for creating this library.
I discovered a bug in the logic related to linear extrusion. Trying to execute the following code results in an exception. I am using version 0.3.2
from openpyscad import Square
x = Square([2, 2])
y = Square([1, 1])
diff = x - y
diff.linear_extrude(height=1)
This results in an exception (which seems to be related to #5)
Traceback (most recent call last):
File "openpyscad-test.py", line 5, in <module>
diff.linear_extrude(height=1)
File "/mnt/extspace/andre/devel/git/keyboard_designs/venv/lib/python3.7/site-packages/openpyscad/base.py", line 308, in linear_extrude
return Linear_Extrude(*args, **kwargs).append(self)
File "/mnt/extspace/andre/devel/git/keyboard_designs/venv/lib/python3.7/site-packages/openpyscad/base.py", line 184, in append
self._validate_append(obj)
File "/mnt/extspace/andre/devel/git/keyboard_designs/venv/lib/python3.7/site-packages/openpyscad/transformations.py", line 59, in _validate_append
raise TypeError('Appended object must be a instance of Shape2dObject or Transformation.')
TypeError: Appended object must be a instance of Shape2dObject or Transformation.
I would expect that the library can generate openscad output like this:
linear_extrude(height=1) {
difference() {
square([2, 2]);
square([1, 1]);
};
};
@aweltsch Thank you for your feedback. I'll check the bug.
Should this also work for rotate_extrude? I'm new to OpenSCAD, only ever played with linear_extrude. I forked this repo and it looks like the fix would be very simple, going to create a PR. I am guessing that rotate_extrude has the same problem as linear_extrude.
class Linear_Extrude(_Transformation):
def _validate_append(self, obj):
from .shapes_2d import Shape2dObject
if not isinstance(obj, (Shape2dObject, Transformation)):
raise TypeError('Appended object must be a instance of Shape2dObject or Transformation.')
class Rotate_Extrude(_Transformation):
def _validate_append(self, obj):
from .shapes_2d import Shape2dObject
if not isinstance(obj, (Shape2dObject, Transformation)):
raise TypeError('Appended object must be a instance of Shape2dObject.')
As you can see, there is a check that is run to make sure it's the right instance, but this happens for rotate_extrude too.