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.

Improvements to skConstraint in feature script

darren_13darren_13 Member, Developers Posts: 117 PRO
I have been struggling to use sketch constraints in feature script and since nobody has been able to help me on the forums I guess nobody knows!! Therefore I would like this to be made simpler. If when creating a manual sketch the set initial guess is done automatically, maybe the feature script equivalent should be the same, removing the need to define this manually. 

My most needed constraints are coincident, tangent and measurement (both length and angle).



  • darren_13darren_13 Member, Developers Posts: 117 PRO
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 459
    Hey Darren,

    Sorry we've put off answering this for so long.

    We did make a conscious decision to not go down the rabbit hole of externally documenting everything about sketch constraints and initial guesses, and there are a few reasons for that:
    1. There are a lot of minutia involved. Each constraint's interface is unique, and can involve a large number of inputs via the constraint function itself, and via the initial guess.

    2. The constants within the initial guesses are designed to be generated by Onshape when the user drags a sketch or creates a constraint. While it's easy for us to calculate these during interactive sketching, it turns out these constants are wicked difficult to pin down inside a custom feature.

      Even seemingly simple things like a flip direction or a parameter along a curve are hard to determine without a lot of manual calculation (since naively, you have no real way of knowing what this direction is being measured with respect to). That calculation is made harder by the fact that you can't use our evaluate functions on entities you "added" to the sketch, since those entities aren't added to the context until the sketch is solved, at which point it's too late.

      Now, to some extent, there's leeway in getting these constants wrong. After all, it's only the "initial guess" before we arrive at the real answer. But from the solver's perspective, the solution space for sketches explodes very quickly, and so our solver needs to make heavy use of these initial guess inputs to determine the user's intent. The result of getting the initial guess wrong is quite often a sketch that fails to solve, or only solves in a small set of cases.

    3. Overall, our main priority with sketch functionality is making interactive sketching awesome. When we have an opportunity to get interactive sketches to behave better by adding a new option to the FeatureScript function, we're almost always going to take that opportunity (which, of course, has lead directly to items 1 and 2).

    It may sound like I'm just spewing bad news here, but there's a happy ending:

    We know sketches work best when they can be designed interactively with Onshape's sketch tools. So, in an ideal world, we want you to be able to use that power when making sketches for custom features too. Specifically, we want you to be able to design a beautifully constrained sketch in a Part Studio (with, say, some dimensions exposed), and then use that sketch in a custom feature with different values for those dimensions.

    The missing link for that ideal world is the ability to build a Part Studio differently based on different input parameters. This isn't possible yet without configurations, but rest assured configurations are something being actively worked on and we hope you'll appreciate their myriad uses it once they arrive!

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 954 ✭✭✭✭✭
    be able to design a beautifully constrained sketch in a Part Studio (with, say, some dimensions exposed), and then use that sketch in a custom feature with different values for those dimensions.
    sounds promising, may be it would help to implement my idea with kinematically-defined curves

  • darren_13darren_13 Member, Developers Posts: 117 PRO
    Thanks @kevin_o_toole_1, I look forward to these changes in the future. For the time being however, can we not have initial guess automatically calculated based upon position of the placed objects, regardless of weather they are placed interactively or via script?

    Kind regards,
Sign In or Register to comment.