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.

How to find the radius or diameter of a curve in Featurescript

peter_morrispeter_morris Member Posts: 43 ✭✭
I'm trying to amend some code to generate a spur gear - eventually I want it to create a helical gear, but I have to walk before I can run!

The starting position is that I will have created a part studio with the relevant gears as blank extruded pieces.  The diameter of the extrusions are the gear tip diameters as I'm making a drawing of an old lathe.  In the precondition section I'm able to select an edge (the curved edge of what will be the gear), but now need to calculate or find the diameter of that circle.  I have one immediate challenge and that is how to extract the diameter from the definition.TipDiameter and, in order to refine the precondition, I'd like to be able check that this is actually a curve and not a straight edge.

I'd be really grateful for any advice.

The code I'm using in the precondition is:
<div>&nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Tooth Tip Circle", "Filter" : EntityType.EDGE&nbsp; &nbsp; , "MaxNumberOfPicks" : 1 }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; definition.TipDiameter is Query;</div>
and to try and extract the diameter I'm using:

&nbsp; &nbsp; &nbsp; &nbsp;TipDiameterVariable=evaluateQuery(Context, definition.ToothTip)[0];
But that is a complete guess that fails to compile properly.

Comments

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    look at

    evCurveDefinition (context is Context, arg is map) returns map

    Given a query for a curve, return a CircleEllipse, or Line value for the curve. If the curve is none of these types, return a map with unspecified contents.

    ParameterTypeAdditional Info
    arg<a rel="nofollow" href="https://cad-usw2.onshape.com/FsDoc/variables.html#map">map</a>
    • edge
    <a rel="nofollow" href="https://cad-usw2.onshape.com/FsDoc/library.html#Query">Query</a>

    The curve to evaluate.

    Also there already exists Spur gear feature by Neil Cooke.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
  • peter_morrispeter_morris Member Posts: 43 ✭✭
    Hi Konstantin and Neil,

    Thanks Konstantin, I've not managed to make that work - I'll look closer at the ev functions.

    Neil, I've been working with an earlier version of your spur gear code as I was hoping to adapt it to create a helical gear (and learn about Featurescript).  It looks like this will already do what I want and in a far more sophisticated way than I think I would have achieved - I'm an electronics engineer by trade and this has meant learning way more about gear geometry than I'd ever imagined!

    Many thanks to you both.

    Regards

    Peter
Sign In or Register to comment.