Parameters For a Helical Gear Feature Script

peter_morris
peter_morris Member Posts: 43 ✭✭
I'm very slowly getting to grips with Featurescript and modifying Neil Cooke's Spur Gear code to allow me to apply a helical gear profile to an already extruded blank.  The next stage requires (in my mind) the confirmation that the queried face is in fact a circle and then to extract the position of its centre and its radius/diameter.

I think I'm then going to have a question about how to use feature script to apply a helix to an extruded circular surface, but that perhaps can wait for another day.

Any advice greatly received.

Many thanks.

Peter

Comments

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,278 image
    Take a look at evCurveDefinition and evSurfaceDefinition (for a face).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • cody_armstrong
    cody_armstrong Moderator, Onshape Employees, Developers, csevp Posts: 229 image
    edited March 2017
    You can grab the edge of the queried face with qEdgeAdjacent.  Something like this...
     var edge = qEdgeAdjacent(face, EntityType.EDGE);
    Then use evCurveDefinition to return the edge as a circle.
    var curve = evCurveDefinition(context, { "edge" : edge });
    Then create an If statement that throws a regen error if the edge is not a circle.

    <div>if (!(curve is Circle)) // if the selected curve is not a circle throw error</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw regenError("Selected face does not have a circular edge");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>

    Now that you know it is a circle you can get the radius.

    var curveRadius = curve.radius;
    I created a straight sided spline feature that does alot of this.  Might be worth checking out.

    Straight Spline Feature
  • peter_morris
    peter_morris Member Posts: 43 ✭✭
    Thank you both for your quick responses which are already helpfing! Very much appreciated.

    Peter