Edge selector advanced example

29 views
Skip to first unread message

neri-engineering

unread,
Jun 30, 2024, 5:44:14 PM (6 days ago) Jun 30
to CadQuery
Hi, I've been looking for this code for a while, have not found it.

I start with a basic timing belt pulley sort of shape:

pulley-orig.png

I would like to round the sharp edges.  So I add this line:

pulley = pulley.edges("|Z").fillet(radius=fillet_r)

Which produces this:

pulley-fillet.png

While this is acceptable in my case I would really rather only round the outside edges and not the ones in the cavity.  I have tried various things, but only superficially, e.g. some sort of "objects closest to a point" selector and the possible use of an inverse selector.  I have not figured out how to chain one of the custom selectors with the '|Z', through use of 'and'.

Basically I want to select all edges that are parallel to Z, which are maximally far away from the origin.  The edges on the outside of teeth happen to be at same distance from origin in my case.

While I can come up with a real cludge of a code to do this, i.e. by referencing hardcoded indices in 'all()', I was wondering if there is some elegant way to do this.

Sent with Proton Mail secure email.

Lorenz

unread,
Jul 2, 2024, 8:20:54 PM (4 days ago) Jul 2
to CadQuery
Could you move the fillet to 2D (say with cq.Sketch)? It might be easier that way.

#example based on code from https://groups.google.com/g/cadquery/c/3bfr1eoP7sI/m/l_LdWUJZAAAJ

w = 10
h = 1
r = 2
rc = 0.4

s = (
    cq.Sketch()
    .circle(r)
    .parray(0, 0, 135, 4)
    .rect(w, h, tag="rect")
    .clean()
    .reset()
    .vertices(tag="rect")
    .fillet(rc)
)

Lorenz

unread,
Jul 3, 2024, 10:34:08 AM (3 days ago) Jul 3
to CadQuery

FYI, new additional special methods are coming with PR 1514.  After this is checked in, the new filter method might be used to select on 3D:

import cadquery as cq


w = 10
h = 1
r = 2
rc = 0.4
dz = 10

s = cq.Sketch().circle(r).parray(0, 0, 135, 4).rect(w, h).clean()

result = cq.Workplane().placeSketch(s).extrude(dz)


def get_outer_edges(pnt, d):
    """Select edges with center distance to point less than d"""

    def callback(obj):
        dist = obj.Center() - cq.Vector(pnt)
        if dist.Length > d:
            return True

    return callback


result = result.edges("|Z").filter(get_outer_edges((0, 0, dz / 2), r + 1))
result = result.fillet(rc)

Lorenz

unread,
Jul 3, 2024, 11:04:06 AM (3 days ago) Jul 3
to CadQuery
To correct docstring typo, it should say select edges with distance *greater* than d (filtering out the inner edges). 

Adam Urbanczyk

unread,
Jul 3, 2024, 2:48:44 PM (3 days ago) Jul 3
to CadQuery
Filter was just merged to master. You could also try good old RadiusNthSelector https://cadquery.readthedocs.io/en/latest/apireference.html#selectors

neri-engineering

unread,
Jul 3, 2024, 2:57:42 PM (3 days ago) Jul 3
to Lorenz, CadQuery
Great.  Thanks.

One of these days I have to get more familiar with PRs and Git.  I sort of only sort of know it.

In particular I need to eventually commit my "animator module", which allows you to programmatically position the camera etc. and take a PNG snapshot of specified dimensions.

Winter projects... winter projects...

Sent with Proton Mail secure email.

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/6ef22fdd-460f-4b37-8fc4-98205bc628f2n%40googlegroups.com.

neri-engineering

unread,
Jul 4, 2024, 12:24:54 PM (2 days ago) Jul 4
to Lorenz, CadQuery
I got the changes from your PR.  In particular Workplane.filter() seems to work nicely.

The code I ended up using was this:

def __z_get_outer_edges(radial_min):
    def callback(obj):
        radial_d = math.sqrt(pow(obj.Center().x, 2) +
                             pow(obj.Center().y, 2))
        if (radial_d >= radial_min):
            return True
    return callback

Now I get nice fillets but only on the outsides of teeth.

front-pulley.png

Sent with Proton Mail secure email.

On Wednesday, July 3rd, 2024 at 4:34 PM, Lorenz <lorenzjn...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages