cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Workplane() resets currently selected objects

Open adam-urbanczyk opened this issue 5 years ago • 5 comments

The following code does not work

import cadquery as cq
result = cq.Workplane("XY").rect(10.0,10.0).extrude(10).faces("<Y")\
    .workplane().vertices('<XZ').circle(1).extrude(10)

I think it should -- it is quite clear what the intent if the user is here. This is also related to #24

adam-urbanczyk avatar Jun 13 '19 18:06 adam-urbanczyk

We agree that the expected behaviour would be equal to this :

import cadquery as cq
result = cq.Workplane("XY").rect(10.0,10.0).extrude(10).faces("<Y")\
    .workplane().end(1).vertices('<XZ').circle(1).extrude(10)

I have been bothered several time by this and while the end method solves the problem, it's super unnatural and definitely not novice friendly.

If this is still expected to be solved I will try to bring a PR

EDIT : Looking at the source code for workplane since it expects faces or wires on the stack shouldn't we just pass the objects of the parent obj to the child ?

# make the new workplane
plane = Plane(offsetCenter, xDir, normal)
s = self.__class__(plane)
s.parent = self
s.objects = self.objects # we would just add this ?
s.ctx = self.ctx

Of course I need to make sure it doesn't make the tests fail but it seems it would be what's expected ?

Jojain avatar Jan 25 '22 21:01 Jojain

I think, that's it indeed.

adam-urbanczyk avatar Jan 26 '22 17:01 adam-urbanczyk

Or maybe:

s.objects = self.objects[:]

adam-urbanczyk avatar Jan 26 '22 20:01 adam-urbanczyk

I have tried my solution, it breaks some tests, I have quickly looked, some tests could be rewritten, some need a bit more investigation why they break.

Jojain avatar Jan 26 '22 20:01 Jojain

Feel free to open a WIP PR and we can take a look together.

adam-urbanczyk avatar Jan 26 '22 21:01 adam-urbanczyk