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.

Feature interface programming

DSPuzzlesDSPuzzles Member Posts: 17 EDU
I am writing a feature that has a significantly complex interface. This means that the precondition in the feature is a mess. Is there a way to simplify the precondition? Such as loading annotations from another FeatureScript file, for example.
Tagged:

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    Factoring portions of the precondition into predicates is the best I can suggest -- see for instance how booleanStepScopePredicate (defined in boolean.fs) is used in std.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • DSPuzzlesDSPuzzles Member Posts: 17 EDU
    This is precisely what I need. Thank you very much!
  • DSPuzzlesDSPuzzles Member Posts: 17 EDU
    Actually, it's not fixing the problem as I thought it would. Is there a way I can reuse a predicate inside a precondition?

    Because I have an interface that uses a query only in certain places, and I'm using an if statement to decide whether to use it or not. The thing is, the condition becomes a long unreadable mess because it's quite complex. Predicates would solve this if it weren't for the fact that they can only be used once.


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    I see -- you want to avoid copy/pasting the if condition.  Unfortunately, there's no current way to do that...
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • DSPuzzlesDSPuzzles Member Posts: 17 EDU
    The issue isn't copy-pasting. It's that my if statements look like this: (taken from the actual feature)

    if ((definition.family == familyEnum.CURVED && (definition.curvedSolid == curvedEnum.CYLINDER || definition.curvedSolid == curvedEnum.CONE || definition.curvedSolid == curvedEnum.BICONE)) || (definition.family == familyEnum.POLYGONAL && (definition.polygonalSolid == polygonalEnum.PRISM || ((definition.polygonalSolid == polygonalEnum.PYRAMID || definition.polygonalSolid == polygonalEnum.BIPYRAMID) && definition.heightTypePYR == pyramidHeightEnum.HEIGHT))))
            {
                // Height
                annotation { "Name" : "Height" }
                isLength(definition.height, LENGTH_BOUNDS);
            }

    In fact, here is a link to the featureScript file, since it is a public tool.
Sign In or Register to comment.