Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify which corner to use #1708

Closed
davidedelvento opened this issue Nov 23, 2024 · 6 comments
Closed

Specify which corner to use #1708

davidedelvento opened this issue Nov 23, 2024 · 6 comments
Labels
question Further information is requested

Comments

@davidedelvento
Copy link

This does what I want on one face

a = Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces(">Y")
a = a.box(4, 13, 4, centered=[1,0,0])

however I want it on the other face, so I try

a = Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces("<Y")
a = a.box(4, 13, 4, centered=[1,0,0])

but that uses the "wrong" corner of the box and it goes wrong. Using centered=[1,1,0] in this second instance makes it slightly less wrong.

I guess I can fix this by either translating or mirroring the second box (or the whole thing), but that's a pain to get the appropriate values (or mirror surface) right in a parametric correct way. Is there a cleaner way?

@davidedelvento davidedelvento added the question Further information is requested label Nov 23, 2024
@lorenzncode
Copy link
Member

Specify the centerOption as in this example. The center of the sphere is the selected corner vertex.

import cadquery as cq

a = cq.Workplane("XY")
a = a.box(9, 20, 4)
a = a.vertices(">X and <Y and >Z")  # or as: ">XZ and <Y"
a = a.workplane(centerOption="CenterOfMass")
a = a.sphere(1)

See also the docs example Locating a Workplane on a vertex.

@lorenzncode
Copy link
Member

I suppose creating the workplane is not needed for simply adding the sphere or box. You would typically create the new workplane say in the following scenario where you are building on a selected face and vertex:

a = cq.Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces("<Y").vertices(">XZ")
a = a.workplane(centerOption="CenterOfMass")
# now the plane normal is in -Y dir, with center at selected corner
a = a.circle(2).extrude(5)

@davidedelvento
Copy link
Author

davidedelvento commented Nov 23, 2024

Thanks @lorenzncode

Unless I am completely misunderstanding what you are suggesting in both comments, and the example you are referring (which I read before submitting the issue), this is not what I want. I am able to select the desired workplane just fine as in my examples. The problem is that the second box (the sphere in your example), is placed on that workplane using a vertex which is the one I want in the >Y case, but not the one I want in the <Y case. To be clearer, consider

a = Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces(">Y")
a = a.box(4, 13, 4, centered=[1,0,1])

vs

a = Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces("<Y")
a = a.box(4, 13, 4, centered=[1,0,1])

The first is what I want but mirrored on the XZ plane. I know I could do the mirroring (or rotating, or translating), but the example is obviously a simplification of the actual part that I am designing, so I really want to avoid mirroring, rotating or translating because that would include a whole lot of complexity

@davidedelvento
Copy link
Author

I guess one possible solution is

a = Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces(">Y")
a = a.workplane()
a = a.rect(4,4).extrude(13)

which works fine with both >Y and <Y

Is this the best option?

@lorenzncode
Copy link
Member

OK I see, it could be done like this.

import cadquery as cq

# a, b are symmetric in XZ

a = cq.Workplane("XY")
a = a.box(9, 20, 4)
a = a.faces(">Y")
a = a.workplane(6.5)  # offset workplane in normal dir
a = a.box(4, 4, 13)

b = cq.Workplane("XY")
b = b.box(9, 20, 4)
b = b.faces("<Y")
b = b.workplane(6.5)  # offset workplane in normal dir
b = b.box(4, 4, 13)

I'd prefer your solution though to extrude the shape.

a = a.workplane()
a = a.rect(4,4).extrude(13)

and then with this solution you can also use Sketch when you have a more complex 2D shape to extrude.

a = a.sketch().rect(4, 4).finalize().extrude(13)

@davidedelvento
Copy link
Author

Got it thanks, and you also managed to let me start understanding sketches which have been puzzling me for a while!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants