Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Gear Hub script: can't find `mirror`, and questions about best practices

maxwell_smartmaxwell_smart Member Posts: 8

Hello, I just wrote a feature to automate making a set-screw gear hub. But I have a feeling I'm doing a few things poorly.

Here is the code:

https://cad.onshape.com/documents/92c07f0cdc903565dc9f8a19/w/1aa9f471de9b453b1ac79eb7/e/cf78ac218e146caefb0e95f6

The general description of the code is:

        // take the center point of face, `center` (not sure how)
        // draw two circles one of `hub_diam` the other of `shaft_diam` both centered on `center`        
        // sketch on top face of that extrusion
        // define a rectangle of `nut_length`*`nut_width` that has its edge closest to the center `slot_dist` away from center
        // extrude cut the rectangle down by `extrude_depth`. this will be the centerpoint height of the set screw bolt / nut
        // take the face created by this cut and closest to the center and draw a circle centered at the bottom edges' midpoint of diamter `bolt_diam`
        // then do a two direction cut where the cut towards the center is `slot_dist` and the cut outwards is `hub_diam` (to be safe)
        // draw a sketch on that same face that was just drawn on. find that same midpoint used for the cylindrical cut
        // and draw a hexagon that has a constraint where the bottom corner and one of the edges of the hexagon are midpointed
        // do an extrude cut one way of this hexagon outwards by `nut_width`
        // mirror the hexagon, 2-way cylinder, and rectangular cuts across to the other side of the hub

I would love some advice to make this code robust and as generally useful as possible, as I'm sure I'm doing many things wrong.

The biggest concern was that the tutorials say not to rely on the ordering of results from queries, as they are unpredictable. I didn't know how else to properly specify the face that I wanted so I just found the index that was correct (it just happened to be 0).

But the main thing is I can't seem to find the mirror function in the suggestions when I type it in. I was hoping to finish off this script so that it uses 2 nuts and 2 bolts for set screw.

Thanks!

Sign In or Register to comment.