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 get the parallel distance between two mate connectors?

joshtargojoshtargo Member Posts: 221 EDU
working on my first script.

evdistance is giving me the total distance between two mate connectors, but I want the parallel distance between them (or normal to the first one)

https://cad.onshape.com/documents/68cc6e7f44c7d45ead2a1b38/w/5c67626b11109a69231f9606/e/f5a54e138097299817bb6f7b

Comments

  • joshtargojoshtargo Member Posts: 221 EDU
    edited January 28
    I may have fixed it by converting the two mate connectors into planes:

    const dist is ValueWithUnits = evDistance(context, {
                    "side0" : evPlane(context, {"face" : definition.start}),
                    "side1" : evPlane(context, {"face" : definition.end})
            }).distance;


    but let me know if there's an easier way!!


  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 139 PRO
    edited January 29
    Converting them to planes works fine, but you can also use extendSide0 and extendSide1 to just have evDistance convert the faces into planes. This can be nice if you're working with bodies in evDistance and don't want to find the specific face to make a plane, as extendSide will take all faces and extend them as if they were infinite.

    const dist is ValueWithUnits = evDistance(context, {
             "side0" : definition.start,
             "side1" : definition.end,
             "extendSide0" : true,
             "extendSide1" : true
    }).distance


    Doc:
    https://cad.onshape.com/FsDoc/library.html#evDistance-Context-map
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • joshtargojoshtargo Member Posts: 221 EDU
    Converting them to planes works fine, but you can also use extendSide0 and extendSide1 to just have evDistance convert the faces into planes. This can be nice if you're working with bodies in evDistance and don't want to find the specific face to make a plane, as extendSide will take all faces and extend them as if they were infinite.

    const dist is ValueWithUnits = evDistance(context, {
             "side0" : definition.start,
             "side1" : definition.end,
             "extendSide0" : true,
             "extendSide1" : true
    }).distance


    Doc:
    https://cad.onshape.com/FsDoc/library.html#evDistance-Context-map
    Thanks!

    I also have another question.

    I want the user to specify a direction by clicking a face or a line, but I don't know how to evaluate that to give me EITHER the line's vector or the face's normal vector, depending on what was picked.
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 139 PRO
    I think a solution was provided in another thread, where you can use extractDirection() and that will cover edge and face queries. 

    But to talk a little bit about the query "type," there isn't a function like isQueryFace() or typechecks like that (at least none that I know of). You could make your own function library for this if you want to check this often. You can use qEntityFilter() to see if you can any results when filtering the query by a specific EntityType. 

    Something like
    export function isEntityType(context is Context, id is Id, entity is Query, entityType is EntityType)
    {
          if(isQueryEmpty(context, qEntityFilter(entity, entityType)))
               return false;
    
          return true;
    }

    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • joshtargojoshtargo Member Posts: 221 EDU
    I think i solved it with another suggestion to use AllowsDirection and then they can only pick things where a direction can be extracted, but your example is good for me to learn from.
Sign In or Register to comment.