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 do I make the IsNonNegativeInteger precondition commit?

peter_morrispeter_morris Member Posts: 43 ✭✭
Hi, I'm learning FeatureScript and CAD generally so perhaps I'm trying to do too much, but I'm comfortable with the basics of CAD and have some competent (in my view!) drawings.  I want to add the ability to create a helical gear and believe FeatureScript is the best way do so.  I've completed the tutorials, but as soon as I try to get started on the preconditions I've failed!  The code below is as far as I've got, and the particular line that is causing the problem is that around the IsNonNegativeInteger.  If I use the IsInteger snippet it works fine, but I would prefer either IsNonNegativeInteger or IsPositiveInteger, but I cant get either to work.  Any ideas gratefully received.

</code><code><pre class="CodeBlock"><code>import(path : "onshape/std/geometry.fs", version : "464.0");<br><br><br>annotation { "Feature Type Name" : "MyGear" }<br>export const MyGear = defineFeature(function(context is Context, id is Id, definition is map)<br> precondition<br> {<br> annotation { "Name" : "Pitch Diameter" }<br> isLength(definition.pitchDiameter, LENGTH_BOUNDS);<br> <br> annotation { "Name" : "Gear Module?" }<br> definition.gearModule is boolean;<br> <br> annotation { "Name" : "Number of Teeth:" }<br> isNonNegativeInteger(definition.numTeeth);<br><br> <br> }<br> {<br> // Define the function's action<br> });
/FeatureScript 464;

Best Answer

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    For this the thing to do is:
    isInteger(definition.numTeeth, POSITIVE_COUNT_BOUNDS);

    For more details I'd look at the predicates and bounds exported from the valueBounds module.

    Additional advice: If you want to make a helical gear feature, you could start with a copy of the Spur gear feature, remove the extrude, make a second profile,  and loft between them.
  • peter_morrispeter_morris Member Posts: 43 ✭✭
    Hi Kevin,

    Many thanks for the prompt reply.  The solution you've proposed is what I have now implemented and created my own bounds statement.  I had imagined that I could use the isNonNegativeInteger() in the same manner as isInteger(), the only documentary difference is that against the latter form it does state that it can be used as a Feature Precondition, whereas this is not stated against isNonNegativeInteger(), which is not very easy for anyone learning FeatureScript.  Perhaps improvements in the documentation in this area could be considered for the future?

    With regard to the latter suggestion, I did consider trying to amend the Spur Gear Feature and may well need to resort to that as a solutio, but I hope I will learn more by starting from basics! - I'm already learning a lot!!

    Again, many thanks

    Peter
  • peter_morrispeter_morris Member Posts: 43 ✭✭
    Hi Kevin,

    Apologies, but further to my last post I thought I'd look at the Spur Gear Feature, unfortunately I don't seem to be able to access the code.  I've created a spur gear in a parts studio, but when viewing the code I can't make any sense of it.  It appears to have long hashed names and a structure that doesnt reflect anything in the tutorials. A segment of it is shown below.  What am I doing wrong?

    const buildPrivate = definePartStudio(function(context is Context, configuration is map, lookup is function)
        precondition
        {
        }
        {
            const id is Id = newId();
            annotation { 'unused' : true }
            var features = {};
            features.F95ADTdmMwyvnvg_0 = function(id)
                {
                    annotation { 'unused' : true }
                    var features = features;
                    if (true)
                    {
                        {
                        }
                        annotation { "Feature Name" : "Spur Gear (#teeth teeth)" }
                        d5742c8cde4b06c68b362d748::vc65839fc6078faeb4d2aece1::e01a666571e625f8b819fd75b::me0006d76c0ec7692c3393bb7::SpurGear(context, id + "F95ADTdmMwyvnvg_0", { "teeth" : "25", "numTeeth" : 25.0, "GearInputType" : d5742c8cde4b06c68b362d748::vc65839fc6078faeb4d2aece1::e01a666571e625f8b819fd75b::me0006d76c0ec7692c3393bb7::GearInputType.module, "module" : 1.0 * millimeter, "diametralPitch" : { 'value' : try(25.400000000000002), 'expression' : "25.400000000000002" }.value, "circularPitch" : 3.141592653589793 * millimeter, "pitchCircleDiameter" : 25.0 * millimeter, "pressureAngle" : 20.0 * degree, "centerHole" : false, "centerHoleDia" : 10.0 * millimeter, "key" : false, "keyWidth" : 3.0 * millimeter, "keyHeight" : 3.0 * millimeter, "centerPoint" : false, "center" : qUnion([]), "gearDepth" : 5.0 * millimeter, "flipGear" : false, "offset" : false, "offsetClearance" : 0.0 * millimeter, "offsetDiameter" : 0.0 * millimeter, "offsetAngle" : 0.0 * degree });
                    }
                };
            try(features.F95ADTdmMwyvnvg_0(id));
            return context;
        }, millimeter, {});


  • peter_morrispeter_morris Member Posts: 43 ✭✭
    Kevin, Please ignore my most recent post - I've found the version to copy!! sorry.
Sign In or Register to comment.