Break line at intersection while drawing

Break line at intersection while drawing

Anonymous
Not applicable
883 Views
2 Replies
Message 1 of 3

Break line at intersection while drawing

Anonymous
Not applicable

i have a line jig that returns the intersecting points of the newly created line (jiggedLine) and any existing lines it crosses into a Point3dCollection (jiggedLineIntPoints).  It then appends new lines based on the intersection points so i can modify them.  In this case i want to shorten the start or end point of the newly entrapped line if it sits on one of the intersection points in (jiggedLineIntPoints).

 

This works fine if the jigged line is being drawn up the page.  It does not work if the jigged line is being drawn down the page.  Its as if the entities returned by:

jiggedEnts = jiggedLine.GetSplitCurves(jiggedLineIntPoints);

 

do not follow from start point to intersecting point to intersecting point to end point and jump all over the place.  But it only seems to happen when drawing down the page.  Is there a way to sort the points or have GetSplitCurves return something more uniform?

 

 

phil4GCRJ_0-1627953760007.png

Drawing Up the Page

 

phil4GCRJ_1-1627953801791.png

Drawing Down the page

 

phil4GCRJ_2-1627953982711.png

Individual segments

 

//jiggedLineBreakPoints.Cast<Point3d>().OrderBy(point => point.Y);
                                    
    jiggedEnts = jiggedLine.GetSplitCurves(jiggedLineIntPoints);

    foreach (DBObject ent in jiggedEnts)
    {
    blockRecord.AppendEntity(ent as Entity);
    transaction.AddNewlyCreatedDBObject(ent, true);

    Line newLine = ent as Line;

    foreach (Point3d p in jiggedLineIntPoints)
    {

        if (newLine.StartPoint == p)
        {
            using (var lineSegment3D = new LineSegment3d(newLine.StartPoint, newLine.EndPoint))
            {
                var vec = lineSegment3D.Direction.MultiplyBy(2).Negate();
                using (var segment3D = new LineSegment3d(lineSegment3D.StartPoint.Subtract(vec), lineSegment3D.EndPoint))
                {
                    newLine.EndPoint = segment3D.EndPoint;
                    newLine.StartPoint = segment3D.StartPoint;
                }
            }
        }
        if (newLine.EndPoint == p)
        {
            using (var lineSegment3D = new LineSegment3d(newLine.StartPoint, newLine.EndPoint))
            {
                var vec = lineSegment3D.Direction.MultiplyBy(2).Negate();
                using (var segment3D = new LineSegment3d(lineSegment3D.StartPoint, lineSegment3D.EndPoint.Add(vec)))
                {
                    newLine.EndPoint = segment3D.EndPoint;
                    newLine.StartPoint = segment3D.StartPoint;
                }
            }
        }
    }


    ent.Dispose();
    }

    if (countLines == psr.Value.Count)
    {
        jiggedLine.UpgradeOpen();
        jiggedLine.Erase();
    }

 

0 Likes
Accepted solutions (1)
884 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

i have found a work around for this odd problem.  I can use jiggedLine.ReverseCurve() before getting the intersecting points and then reverse it back after editing the line segments. 

 

Seems to work, at least in testing.

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

So the previous workaround i posted still had the odd occasion when GetSplitCurves would not break the jigging line sequentially even if the point collection was sorted and return overlapping line segments.

 

What i ended up doing was add the start and end points of the jigged line to the point collection, sort it, redraw the line based on the sorted collection, then carry on as previous without using get split curves

 

 

// sort the points
    jiggedLinePoints.Add(jiggedLine.StartPoint);
    jiggedLinePoints.Add(jiggedLine.EndPoint);
    Point3dCollection jiggedLinePointsSorted = new Point3dCollection(jiggedLinePoints.Cast<Point3d>().OrderBy(point => point.Y).ToArray());
    DBObjectCollection lineCollection = new DBObjectCollection();


    for (int i = 0; i <= jiggedLinePointsSorted.Count - 2; i++)
    {
        Line line = new Line(jiggedLinePointsSorted[i], jiggedLinePointsSorted[i + 1]);
        line.Linetype = lineType;
        line.ColorIndex = lineColor;
        line.LinetypeScale = lineScale;
        line.Layer = lineNumber;
        lineCollection.Add(line);
    }

    jiggedLinePointsSorted.Remove(jiggedLine.StartPoint);
    jiggedLinePointsSorted.Remove(jiggedLine.EndPoint);

    //jiggedLineEnts = jiggedLine.GetSplitCurves(jiggedLinePoints);

    foreach (DBObject ent in lineCollection)
    {

        Line newLine = ent as Line;
        blockRecord.AppendEntity(newLine);
        transaction.AddNewlyCreatedDBObject(newLine, true);

        foreach (Point3d p in jiggedLinePointsSorted)
        {

            if (newLine.StartPoint == p)
            {
                using (var lineSegment3D = new LineSegment3d(newLine.StartPoint, newLine.EndPoint))
                {
                    var vec = lineSegment3D.Direction.MultiplyBy(cutLen).Negate();
                    using (var segment3D = new LineSegment3d(lineSegment3D.StartPoint.Subtract(vec), lineSegment3D.EndPoint))
                    {
                        newLine.EndPoint = segment3D.EndPoint;
                        newLine.StartPoint = segment3D.StartPoint;
                    }
                }
            }
            if (newLine.EndPoint == p)
            {
                using (var lineSegment3D = new LineSegment3d(newLine.StartPoint, newLine.EndPoint))
                {
                    var vec = lineSegment3D.Direction.MultiplyBy(cutLen).Negate();
                    using (var segment3D = new LineSegment3d(lineSegment3D.StartPoint, lineSegment3D.EndPoint.Add(vec)))
                    {
                        newLine.EndPoint = segment3D.EndPoint;
                        newLine.StartPoint = segment3D.StartPoint;
                    }
                }
            }
        }
    ent.Dispose();
    }
    jiggedLine.UpgradeOpen();
    jiggedLine.Erase();

 

 

0 Likes