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.

Sketch constraints using another sketch?

caden_armstrongcaden_armstrong Member, User Group Leader Posts: 33 PRO
I am creating a sketch using featurescript that is using skConstraint.
I can create constraints for sketch elements within the same sketch, but is it possible to constraint to an element of another sketch?
I can do this in the user interface, ex make a point coincident with one of a different sketch.
Is there a way to do this with featurescript? Since the skConstraint is undocumented its a bit of a black box on what it can/cannot do.

If anyone has any info it would be greatly appreciated.
Software Development Lead - CADSharp

Comments

  • Jacob_CorderJacob_Corder Member Posts: 63 PRO
    edited January 2021
    Sure can.

    use "externalSecond" or "externalFirst"
    skConstraint(sk, "arcBottomTangent", {
                            "constraintType" : ConstraintType.TANGENT,
                            "localFirst" : "offsetArc",
                            "externalSecond" : someCurveQuery
                        });

    where skArc(sk,"offsetArc") is the arc


    I have found sketch constraints extremely unreliable as they do not always solve nor tell you that they didn't solve. I normally evaluate the edges created to determine if tangency or coincident actually occurred. I have tried setting initial guess also, however this is a tough one and rarely seems to fix constraints that are not resolving. I think i have had the initial guess work for me once or twice.
  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 33 PRO
    Thanks Jacob!

    Works exactly as expected.
    Software Development Lead - CADSharp
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,118
    Yes, sketch constraints and FeatureScript are not as great a mix as we would like.  The general recommendation is to get the geometric information using evSomething functions, use that to do explicit computations in FS and create the sketch entities in the right place without constraints.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • aleksei_pomelovaleksei_pomelov Member Posts: 5
    @ilya_baran , I'm also a bit confused with skConstraint and its documentation. Already have looked through forums, but no simple examples. My feature is about to sweep some specific profile. I've prepared the sketch, found the right point to start and now just need to create a profile: an isosceles trapezoid. Start point is "left-bottom corner". It is parametrized by height, upper side length and angle between left and right sides. When I draw it manually a start with a random quadrilateral with one fixed corner and horizontal "bottom". Then I simply add parallel and distance for two sides, angle for another two sides and length for the "top" side.
    When composing a sketch in a feature script I'm creating points with coordinates. Of course a can add a bit of trigonometry here and calculate them, but for some reason I decided to do it with constraints. So I'm frustrating about creating unfixed points and lines, applying constraints and so on. I don't understand if I can apply constraints to line segments that has certain coordinates of the the ends?
    I do appreciate any hints here..
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,228
    @aleksei_pomelov use trig it's much simpler. 
    Director, Technical Services, EMEAI
Sign In or Register to comment.