I'm new to CADQUERY

393 views
Skip to first unread message

Adhip

unread,
Sep 20, 2023, 2:23:05 AM9/20/23
to CadQuery
Hello, 

I'm fairly new to CADQUERY. I'm trying to create a code where I can get the desired model by specifying user inputs. However I'm still struggling with 1 hole having two different angles. Can anyone help?

Jeremy Wright

unread,
Sep 20, 2023, 6:47:35 AM9/20/23
to Adhip, CadQuery
Can you post code or give more detail on what you mean by 1 hole having 2 different angles? Do you mean a tapered hole?


On Wed, Sep 20, 2023, 2:23 AM Adhip <drpramod...@gmail.com> wrote:
Hello, 

I'm fairly new to CADQUERY. I'm trying to create a code where I can get the desired model by specifying user inputs. However I'm still struggling with 1 hole having two different angles. Can anyone help?

--
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/3107b526-2db0-4cb3-accf-0e168cc02419n%40googlegroups.com.

Adhip

unread,
Sep 20, 2023, 9:52:50 AM9/20/23
to CadQuery
Hi
thanks for replying back
I have attached the drawing of the hole im trying to recreate in cadquery.
I created the hole but my second angle is always different. I used transform feature.
Code:
model = (
            cq.Workplane("XY")
            .polyline(pts1)
            .radiusArc((0,49.8), radius=85)
            .close()
            .extrude(284)
            .pushPoints([(25,24)])
            .circle(5)
            .cutBlind(16)
            .transformed(offset=(0,0,35))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,39))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,39))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,39))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,39))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,39))
            .polyline(pts2)
            .close()
            .cutBlind(19)
            .transformed(offset=(0,0,54))
            .pushPoints([(25,24)])
            .circle(5)
            .cutBlind(-16)
            .transformed(offset=(0,0,0), rotate=(-90,0,0))
            .center(25,142)
            .rect(44,278)
            .cutBlind(5)
            .transformed(offset=(0,0,0))
            .center(0,0)
            .rect(20,244)
            .cutBlind(10)
            .pushPoints([(15,259),(35,259),(35,15),(15,15)])
            .moveTo(-10,122)
            .radiusArc((10,122), radius=10)
            .close()
            .cutBlind(10)
            .moveTo(-10,-122)
            .radiusArc((10,-122), radius=-10)
            .close()
            .cutBlind(10)
            .faces(">X")
            .workplane()
            .transformed(offset=(30,0,0))
            .transformed(rotate=(0,angle_1,0))
            .transformed(rotate=(angle_2,0,0))
            .circle(2)
            .cutThruAll()
)

Im converting it to STL and the viewing it in browser instead of using CQ editor

Thanks in advance if you can figure out a better way to create the hole.
(Angles are user input)
MRP.png

Jeremy Wright

unread,
Sep 20, 2023, 1:23:14 PM9/20/23
to Adhip, CadQuery
Have a look at the attached sample code and see if it helps.



two_angle_holes_example.py

Yoululauren

unread,
Sep 20, 2023, 2:18:40 PM9/20/23
to CadQuery
Usually, rotate will be based on x-axis first, then y-axis, if this is what you want. Another approach would be to create a cylinder, then rotate with begin point and end point, cut the cylinder from your model. 

A side note, if this is for 3D printing, you may want to print a part of your model first. I doubt that with angled holes, you will not get a high precision object. Test before you proceed with your design. 

Adhip

unread,
Sep 21, 2023, 1:53:26 AM9/21/23
to CadQuery
Hello

Thanks for the code. I think the angles you gave were 45 and 75 right? 45 degree comes perfectly but 75 does not. I'm facing the same issue as my second angle is not proper. Problem arises if I want to make it user input. Lets say user gave 30 instead of 45 and second angle is 75 no change, 30 will be proper but 75 won't be.
My code also faces the same issue. Is there anyway to create a line passing through two points and the points are created in such a way that the line automatically has 45 and 75 angles to it? The line or axis can be used to make a hole. That's how I do it in CAD software for these type of problems.
Let me know if that is possible in cadquery. THANKS A LOT THOUGH!!

Adhip

unread,
Sep 21, 2023, 1:54:41 AM9/21/23
to CadQuery
Can you give a code? I'm still figuring out cadquery. 
Also, this is not for 3D printing. I'm trying to brush up my skills in CADQUERY so that i can create complex models with ease.
Thanks!!

Adhip

unread,
Sep 21, 2023, 2:54:02 AM9/21/23
to CadQuery
I have uploaded my code again which you can run and see what I mean. If you have any 3D modelling software, you may open the STEP file and measure the angles. 1st angle is always spot on but the second one is always less than given angle.

THANKS AGAIN

angle_hole.py

Adhip

unread,
Sep 21, 2023, 9:40:56 AM9/21/23
to CadQuery
I want to know if i can push points in 3D space. It will be two points that I calculate using math library in python and then can I use those two points to create the desired hole?

THANKS IN ADVANCE

Yoululauren

unread,
Sep 21, 2023, 6:12:11 PM9/21/23
to CadQuery

I am not good at 3d geometry. I can't understand how to use rotate to achieve the angle you required. However, if you can come up with points in space that the hole should go thru, this may be the solution:

# distance from p1 to p2
# --- to be defined ---
def dist(p1, p2):

    return 10.0

def hole(p1, p2, radius):
    p3 = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]) # this can be done by some function
    height = dist(p1, p2)

    r = (cq.Workplane()
         .cylinder(height, radius, direct = p3, centered = (True, True, False))
         .translate(p1)
         )

    return r

r = hole((-3.0, -2.0, -1.0), (3.0, 2.0, 1.0), 0.2)

1. Sorry, don't know how to format code in google groups.
2. "cylinder" function only supported in new cadquery versions. If you are using pre-built cq-editor, this function may not be available.

Adam Urbanczyk

unread,
Sep 22, 2023, 1:56:10 AM9/22/23
to CadQuery
I might be misunderstanding the 2D drawing, but to me it implies that you want to control angles between projected vectors. I don't think this can be easily specified in the current API. If you know the final orientation of your coordinate system, you can simple construct a cq.Plane object and overwrite one in your cq.Workplane. E.g.

plane_old = model.plane
model.plane = cq.Plane(plane_old.origin, xdir, zdir)


Latest CQ-editor build can be downloaded from here https://github.com/CadQuery/CQ-editor/releases/tag/nightly (also stated in the README https://github.com/CadQuery/CQ-editor#development-packages)

Adhip

unread,
Sep 22, 2023, 2:29:00 AM9/22/23
to CadQuery
"# distance from p1 to p2
# --- to be defined ---
def dist(p1, p2):

    return 10.0

def hole(p1, p2, radius):
    p3 = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]) # this can be done by some function
    height = dist(p1, p2)

    r = (cq.Workplane()
         .cylinder(height, radius, direct = p3, centered = (True, True, False))
         .translate(p1)
         )

    return r

r = hole((-3.0, -2.0, -1.0), (3.0, 2.0, 1.0), 0.2)"

I understand what you're trying to do here but I'm not sure if that will work. I'll update you after I try it.

Adhip

unread,
Sep 22, 2023, 2:29:55 AM9/22/23
to CadQuery
"plane_old = model.plane
model.plane = cq.Plane(plane_old.origin, xdir, zdir)"

Can you please specify more on this? I didn't really understand this.

Adam Urbanczyk

unread,
Sep 22, 2023, 2:58:53 AM9/22/23
to CadQuery
Can you specify the correct coordinate system for your holes in terms of local x direction, y direction an z direction vectors (thus not angles)? If so, you can simple modify the coordinate system used in the model instance (this is roughly what the transformed method does internally).
Reply all
Reply to author
Forward
0 new messages