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.

Options

Having difficulties finding the "other end" of a selection of edges...

eric_pestyeric_pesty Member Posts: 1,607 PRO
Here's the situation, I have a path that I am using to sweep a simple profile. The path can be either a spline generated by the FS or some existing edges.

What I'm trying to do is (optionally) add some straight sections tangent to the ends of the path before doing the sweep. It works fine for the "start" of the path as I am already creating a sketch here and I can reliably "qUnion" a straight bit right there.

I'm having a hard time finding the "end" when it's a user selected path though (it's easy when I"m just generating a single spline)... I am able to find the "last segment" but the end I need to add the line seems to move around  depending on the selection so clearly I am doing it wrong...

I had it "working" for the different cases by treating them differently until I started using different selection and realized there was no "logic" that I could follow anymore (hence the big mess below...). I'm thinking my approach is wrong but I'm not seeing an obvious way to deal with it as the selection 

Since these are straight bits, I could also use an extrude at each end but again it would be easy for the start but I'm not sure how I would identify the "end" face to extrude...

I just realized maybe a "construcPath" would help, however this looks like it breaks a lot of things as I have to figure out how to "extract the edges" back out later when I look for the minimum curvature etc... So I guess I'm going to have to re-write a bunch of stuff...
Unless I just use a "path" to find the end and create my "extension" and revert back to a bunch of edges that I know how to work with...

Any thoughts on the best approach?

        else if (definition.Usepath)
        {

            startLine = evPathTangentLines(context, constructPath(context, definition.edges), [0]).tangentLines[0];
            sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : plane(startLine.origin, startLine.direction) });

            sweeppath = definition.edges;
            sdir = startLine.direction;

        }

        //Add straight section before beginning
        if (definition.straightStart)
        {
            var startsegment = evEdgeTangentLine(context, {
                    "edge" : sweeppath,
                    "parameter" : 0
                });

            var startLG = definition.straightStartLG;

            opFitSpline(context, id + "fitSplinestart", {
                        "points" : [
                            startsegment.origin,
                            (startsegment.origin + startsegment.direction * startLG * -1),
                        ]
                    });
            var startlinesegment = qCreatedBy(id + "fitSplinestart", EntityType.EDGE);

            sweeppath = qUnion([startlinesegment, sweeppath]);
        }

        //Add straight section after end
        if (definition.straightEnd)
        {

            //println(sweeppath);
            var numberofedges = size(evaluateQuery(context, sweeppath));
            //println(numberofedges ~ " edges in sweeppath");
            var lastedge = evaluateQuery(context, sweeppath)[numberofedges - 1];
            //println(lastedge);
            var endsegment;
            var endsegmentflip = 1;


            if (definition.Usepath)
            {
                var numberofpicks = size(evaluateQuery(context, definition.edges));
                println(numberofpicks);
                endsegment = evEdgeTangentLine(context, {
                            "edge" : lastedge,
                            "parameter" : numberofpicks == 1 ? 1 : 0
                        });
                if (!(numberofpicks == 1))
                {
                    endsegmentflip = endsegmentflip * -1;
                }

            }
            else
            {
                endsegment = evEdgeTangentLine(context, {
                            "edge" : lastedge,
                            "parameter" : 1
                        });
            }


            var endLG = definition.straightEndLG;
            

            opFitSpline(context, id + "fitSplineend", {
                        "points" : [
                            endsegment.origin,
                            (endsegment.origin + endsegment.direction * endLG * endsegmentflip),
                        ]
                    });
            var endlinesegment = qCreatedBy(id + "fitSplineend", EntityType.EDGE);

            sweeppath = qUnion([sweeppath, endlinesegment]);
        }


Tagged:

Comments

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,477
    You have to use constructPath - here is an excerpt from my upcoming release of the "clip" feature:
                        const path = constructPath(context, clip.axis);
    
                        if (path.closed)
                            throw false;
    
                        const endPoints = evPathTangentLines(context, path, [0, 1]);
                        startPoint = endPoints.tangentLines[0].origin;
                        endPoint = endPoints.tangentLines[1].origin;
                        startDirection = -endPoints.tangentLines[0].direction;
                        endDirection = endPoints.tangentLines[1].direction;
    
                        if (clip.startOffset > 0 * meter)
                        {
                            opFitSpline(context, clipId + "extend" + "start", {
                                        "points" : [
                                            startPoint,
                                            startPoint + startDirection * clip.startOffset
                                        ]
                                    });
                        }
    
                        if (clip.endOffset > 0 * meter)
                        {
                            opFitSpline(context, clipId + "extend" + "end", {
                                        "points" : [
                                            endPoint,
                                            endPoint + endDirection * clip.endOffset
                                        ]
                                    });
                        }
    
                        if (clip.spline)
                        {
                            opSplineThroughEdges(context, clipId + "clipWires", {
                                        "edges" : qUnion(qUnion(path.edges), qCreatedBy(clipId + "extend", EntityType.EDGE))
                                    });
                        }
                        else
                        {
                            opExtractWires(context, clipId + "clipWires", {
                                        "edges" : qUnion(qUnion(path.edges), qCreatedBy(clipId + "extend", EntityType.EDGE))
                                    });
                        }
    
                        if (clip.startOffset + clip.endOffset > 0 * meter)
                        {
                            opDeleteBodies(context, clipId + "deleteBodies", {
                                        "entities" : qCreatedBy(clipId + "extend")
                                    });
                        }
    You don't have to extract the wires, you can reconstruct the path or get the edges from the path whichever suits.
    Senior Director, Technical Services, EMEAI
  • Options
    eric_pestyeric_pesty Member Posts: 1,607 PRO
    edited October 2022
    Thanks for the example @NeilCooke, it looks very relevant to what I am trying to do!

    Quick question: is there a "shortcut" for adding edges to an existing path or do I just something like
    path = constructPath(context, (path.edges, mynewedge));<br>
    or maybe it's more:
    path = constructPath(context, qUnion(path.edges, mynewedge));

    I thought "constructpath" was going to be the way but I wasn't understanding it well, I read a bit more after posting and I think it's starting to make sense now! I also realized the "start" was going in the wrong place too with the way I was doing it when selecting something in the middle first so it will clean things up...
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,477
    Yeah, you want the second one, especially since qUnion keeps query order intact.
    Senior Director, Technical Services, EMEAI
  • Options
    eric_pestyeric_pesty Member Posts: 1,607 PRO
    Thanks for all the help, that made things a lot cleaner compared to the earlier mess.
    evPathTangentlines is pretty sweet as it does all the hard work!

    //Add straight section before beginning
            if (definition.straightStart)
            {
    
                const startsegment = evPathTangentLines(context, sweeppath, [0]);
                const straightstartpt = startsegment.tangentLines[0].origin;
                const straightstartdir = startsegment.tangentLines[0].direction;
    
                const startLG = definition.straightStartLG;
    
                opFitSpline(context, id + "fitSplinestart", {
                            "points" : [
                                straightstartpt,
                                (straightstartpt + straightstartdir * startLG * -1),
                            ]
                        });
                //var startlinesegment = qCreatedBy(id + "fitSplinestart", EntityType.EDGE);
    
                sweeppath = constructPath(context, qUnion([qCreatedBy(id + "fitSplinestart", EntityType.EDGE), qUnion(sweeppath.edges)]));
            }
    
            //Add straight section after end
            if (definition.straightEnd)
            {
                //println(sweeppath);
                const endsegment = evPathTangentLines(context, sweeppath, [1]);
                const straightendpt = endsegment.tangentLines[0].origin;
                const straightenddir = endsegment.tangentLines[0].direction;
    
                const endLG = definition.straightEndLG;
    
                opFitSpline(context, id + "fitSplineend", {
                            "points" : [
                                straightendpt,
                                (straightendpt + straightenddir * endLG),
                            ]
                        });
                //var startlinesegment = qCreatedBy(id + "fitSplinestart", EntityType.EDGE);
    
                sweeppath = constructPath(context, qUnion([qCreatedBy(id + "fitSplineend", EntityType.EDGE), qUnion(sweeppath.edges)]));
    
            }



Sign In or Register to comment.