Replies: 3 comments 15 replies
-
This part of the docs describe exactly what you are requesting: custom objects. Once you create objects that are a subclass of I'm happy that you're attempting to build objects like this. |
Beta Was this translation helpful? Give feedback.
-
Thank you! Yes I tried with Could you explain how am I supposed to implement this |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you for your time. You last example shows pretty well what disturbs me. If you take a look at my original message, it's not so different to what I tried first: class RoundedBoxWithHole(_.Box):
def __init__(self, length, width, height, hole_diam, fillet, **kwargs):
super().__init__(length, width, height, **kwargs)
self.make_hole(hole_diam)
self.make_fillet(fillet)
def make_hole(self, hole_diam):
self -= _.Cylinder(hole_diam, self.height)
def make_fillet(self, fillet):
self = _.fillet(self.edges().filter_by(_.Axis.Z), 5) The main difference is that your methods return First, I don't understand the point of affecting the object to self. You can get the same result with: class HoleBox(_.Box):
def make_hole(self, hole_diam) -> Self:
return self - Hole(hole_diam, self.box_height) Secondly, while returning a new object can be useful for expressions chaining, I would like to be able to actually update the object itself: class HoleBox(Box):
def make_hole(self, hole_diam) -> Self:
self -= Hole(hole_diam, self.box_height)
hb = HoleBox(10, 20, 30) # using inherited constructor
hb.make_hole(5) # method updates the object
show(hb) # -> box with a hole Note that directly assigning to self is considered a bad practice, so ideally we should be able to use a method for that, like From what I understand, with build123d we basically just create new object every time and we never update them, which is a bit of a shame. Is there a reason for that? |
Beta Was this translation helpful? Give feedback.
-
I would like to embrace python's OOP with build123d, I think it's a good paradigm to deal with cad models.
For instance, I would like to make a class that represent a box with a hole and a fillet.
In algebra mode, I do it this way:
In OOP, I would like to inherit the Box class. Something like this:
But then I have some issues when implementing the two last methods. Of course, I can't do this:
So I was looking for oop equivalents, and so I found
part.fillet()
andpart.cut()
, nice! Let's try this:But it seems that it doesn't work that way. This fails (for both method calls).
I would like to understand why. Is there a technical reason that could make this difficult to implement by design? Or it could but it's out of scope / not planned yet?
Beta Was this translation helpful? Give feedback.
All reactions