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.

Bevel gear pair generator

fmafma Member Posts: 87 ✭✭

I started to learn FeatureScript by writing a bevel gear pair generator. I already did such generator using OpenScad, so this is more a port than a complete writing. So far, I successfully generate the gear pair without teeth; gears are represented by their primitive diameters. Here is my code:


Even if I have a teeth routine in my Openscad design (not written by me), I think it would be better to use code from the FeatureScript 'Spur Gear', written by Neil:


Before going further, I would be interested by your feedback about my code; as it is my first FeatureScript, it is certainly not optimized! Feel free to comment; the idea is to have a good base to implement the next stop: adding teeth! Any advice for this welcome to.


PS : my OpenScad design is at the end of the FeatureScript.


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,156

    Looks like a great project!  One suggestion: when you post a link to your document in the forum, please make a version first and post a link to the version.  Otherwise, we can't see the functioning state -- it looks like you're in the middle of editing your code and it's temporarily broken.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,156
    That looks better  :)
    One note -- I'm not an expert on gear math, but the bevel gear tooth shape is different than the spur gear tooth shape.  Googling talks about something called an "octoid", but finding equations for it seems harder.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • fmafma Member Posts: 87 ✭✭
    I didn't know that! Thanks for the information, I'll dig that point. I already 3D printed such gears, generated with my OpenScad script, and they work fine. I guess that I don't really need a perfect gear profile in this case, but I will try to write a correct FeatureScript.

    What about the code? I don't like much the duplication; any advice to avoid that?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,156
    I expect that gears with imperfect teeth will still work, but they'll have more noise/wear/friction than necessary.

    Regarding code duplication, I think the way to avoid it is similar to what you did in OpenSCAD: write a function that creates a single beveled gear and call it twice, once for each in the pair.  Making the function argument a map tends to make the code more readable IMO (that's why definition for feature is a map).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • fmafma Member Posts: 87 ✭✭
    Ok, thanks. I'm working on the teeth, and I will refactor the code once I get something working.
  • robert_morrisrobert_morris OS Professional, Developers Posts: 162 PRO
    If your looking for some reference formulas for the gear teeth, I would recommend doing a search for "Elements of Metric Gear Technology".
    It's a great resource that explains the theories and formulas for a bunch of different gear types.
  • fmafma Member Posts: 87 ✭✭
    Very interesting! Thanks for pointing.
  • PeteYodisPeteYodis Moderator, Onshape Employees Posts: 502
    Be prepared to spend a lifetime of learning in the realm of true gear teeth profiles...an enormously complex field if you factor in all the types of gearing and all the modifications that can be applied in a high number of scenarios.  For 3D printing - you can probably get by with a more simplistic approach.  Usually 3D printers can't match the accuracy needed and often plastics are pretty compliant anyways.  Smooth running and wear will be affected - but if you're 3D printing gears, you probably don't care about these things as much at this stage of the design process.

    The stiffer the material/geometry and the more critical the applications - the greater the need for accurate profiles.  Gear designers usually don't worry about trying to model gear teeth accurately for those scenarios.  They usually have a symbolic representation of the model and place the qualifying information on a drawing that is meant for manufacturing information and QA requirements based on the manufacturing equipment and inspection equipment being used to make/validate the parts.  I've attached a sample set of qualifying information for a simple spur gear set

    Another set of good resource on gears and profile information is any book by one of the pioneers of modern gear design: Earle Buckingham.  Here's one:  https://www.amazon.com/Analytical-Mechanics-Gears-Earle-Buckingham/dp/0486657124

    By the way, kudos on approaching this as designing a set of gears - you're best off with this approach.

  • fmafma Member Posts: 87 ✭✭
    As said, the final goal is to be able to 3D-print bevel gears, so let's keep things simple ;)

    I successfully generated the teeth; how do I tell Onshape to add them to the main part? Do I have to specifically use a boolean operator? I'm using opPattern() to copy the tooth all around...
  • fmafma Member Posts: 87 ✭✭
    Ok, here is a working version, which is a complete port of my OpenScad script:


    Next step will be to use a better profile, and correct little mis-alignements.
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    edited March 2017
    Nice work Sir, and thanks for sharing.

    Could we trouble you for options of shaft diameters and woodruff key slots?

    Happy coding,


    Edited for speeling and addition of "key"
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • fmafma Member Posts: 87 ✭✭
    What is woodruff slots? Keyway, as in the Spur Gear script?
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Hi @fma, I should have stated Woodruff "Key" slot.

    Along these lines:-

    Regards, Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭
    Very cool example of the power of featurescript, @fma, thanks for sharing!
    Certainly learned a thing or two reading through the code.
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
  • fmafma Member Posts: 87 ✭✭
    Well, my code is certainly not the best! I have an issue with an extrude REMOVE:


    In this snapshot, the shaft hole is done between all entities, so it makes a hole in another part:

    Line 318, I tried to set the defaultScope param to false, and give the booleanScope param, but doing that, I get a INVALID_INPUT...

    Any help welcome.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,965
    @fma very cool - if you swapped your skPolyline for skSpline would it work?
    Senior Director, Technical Services, EMEA 
  • fmafma Member Posts: 87 ✭✭
    No: it now says EXTRUDE_NO_SELECTED_REGION...
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 560
    @fma You'll want the scope to be
    qCreatedBy(id + "revolve1", EntityType.BODY)

  • fmafma Member Posts: 87 ✭✭
    Thanks, it works! Queries are the most tricky part of FeatureScript...
  • fmafma Member Posts: 87 ✭✭

    Could we trouble you for options of shaft diameters and woodruff key slots?

    Done in release 1.2.
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    fma said:

    Could we trouble you for options of shaft diameters and woodruff key slots?

    Done in release 1.2.
    Wow, thanks. 
    Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • fmafma Member Posts: 87 ✭✭
    As I wrote in the header, there are some little issues, and the gears may not regenerate in all cases; I didn't add any checks on params...
    Also note that the ends of the teeth are flat, so don't match the bore, which is circular.

    As said, this is mainly for 3D-printing, so it is OK. And I guess it is enough for design visualisation too.
  • leo_chen538leo_chen538 Member Posts: 2
    Great plugin, only needed simple bevel gears for my project to 3d print. Only other admins I found were either paid or crappy.

    Good work!
  • peter_m091peter_m091 Member Posts: 8
    hi team. any ideas why all extrudes stop working once I drop the gears? (the green button to apply the extrude is graded out without any errors/ warnings displayed - also the preview shows the operation exactly as expected, I just can't commit it)
Sign In or Register to comment.