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.

Creating consistent lines in a path

eric_ma454eric_ma454 Member Posts: 14
Currently, I have a query of lines from input, and I wish to create a path, and then analyze them as lines in order. Currently, I have:

var path = constructPath(context, definition.edges);
var nLines = size(path.edges);
var tangentLines = evPathTangentLines(context, path, range(0,1,nLines));

I am accessing the lines through tangentLines.tangentLines[index]. However, when debugging the lines in a part studio with a basic sketch, upon adding more lines (starting around 4-5 lines), some lines seem to get skipped over, while others have multiple debug vectors. Is there a consistent way to get an array/map of all distinct lines in order of a path, from one end to another?

Best,
Eric Ma

Best Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Posts: 915 ✭✭✭✭✭
    Accepted Answer
    if your path consists of linear edges only, and you need a line of each edge in the path order then you need to iterate through the edges and evaluate the line of each
    for (edge in path.edges)
    {
    var L = evLine(... edge);
    }
  • Jake_RosenfeldJake_Rosenfeld Posts: 1,385
    edited November 2018 Accepted Answer
    @eric_ma454

    For some context on why this is happening, evPathTangentLines divides up the path by the total length.  So if some of the lines are long and some are short, you can imagine that an equal division based on length may not actually hit all of the lines.  @konstantin_shiriazdanov 's solution will provide you with what you need, but you may also have to flip the direction if you need the edge directions to be constantly "forward" in the path:
    for (var i = 0; i < size(path.edges); i += 1)
    {
        var edgeLine = evLine(context, { "edge" : path.edges[i] });
        if (path.flipped[i])
        {
            edgeLine.direction *= -1;
        }
    }

    If your edges are not guaranteed to be linear, you may want to replace evLine with
    evEdgeTangentLine(context, { "edge" : path.edges[i], "parameter" : 0.5 });
    to get the tangent line at the middle of the edge.
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Posts: 1,385
    edited November 2018 Accepted Answer
    @eric_ma454

    Since tangentLines is an array of all the lines you've processed so far, you need:
    tangentLines[i].direction *= -1;
    not
    tangentLines.direction *= -1;

    Jake Rosenfeld - Modeling Team

Answers

  • MBartlett21MBartlett21 Member Posts: 1,624 EDU
    Could you provide a link?
    MB - I make FeatureScripts: view FS (My FS's have "Official" beside them)
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 915 ✭✭✭✭✭
    Accepted Answer
    if your path consists of linear edges only, and you need a line of each edge in the path order then you need to iterate through the edges and evaluate the line of each
    for (edge in path.edges)
    {
    var L = evLine(... edge);
    }
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,385
    edited November 2018 Accepted Answer
    @eric_ma454

    For some context on why this is happening, evPathTangentLines divides up the path by the total length.  So if some of the lines are long and some are short, you can imagine that an equal division based on length may not actually hit all of the lines.  @konstantin_shiriazdanov 's solution will provide you with what you need, but you may also have to flip the direction if you need the edge directions to be constantly "forward" in the path:
    for (var i = 0; i < size(path.edges); i += 1)
    {
        var edgeLine = evLine(context, { "edge" : path.edges[i] });
        if (path.flipped[i])
        {
            edgeLine.direction *= -1;
        }
    }

    If your edges are not guaranteed to be linear, you may want to replace evLine with
    evEdgeTangentLine(context, { "edge" : path.edges[i], "parameter" : 0.5 });
    to get the tangent line at the middle of the edge.
    Jake Rosenfeld - Modeling Team
  • eric_ma454eric_ma454 Member Posts: 14
    @Jake_Rosenfeld
    Thank you for the answer, this method worked very well. However, it seems that if I select lines in the precondition out of order of a path, it throws an error. Is there any way to fix this?
    https://cad.onshape.com/documents/b3341e1949df657d55730d83/w/10c62cb1d20fa73f85db9b2f/e/39b17b46a08eb0173e635858
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,385
    edited November 2018 Accepted Answer
    @eric_ma454

    Since tangentLines is an array of all the lines you've processed so far, you need:
    tangentLines[i].direction *= -1;
    not
    tangentLines.direction *= -1;

    Jake Rosenfeld - Modeling Team
Sign In or Register to comment.