- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi! I'm new to AutoCAD .NET and trying to get the intersection point of 2 lines using Entity.IntersectWith method lately. Usually, it can find the intersection points. but sometimes it doesn't get it when there should be intersection point between 2 lines. Can' t figured it out why. can someone help or give some suggestions? thx!
Below is my code for test. I iterate each 2 lines in all lines selected by user and draw a circle on every intersection point. I write in c#:
```
[CommandMethod("Test")]
public void Test()
{
Active.UsingTransaction(tr =>
{
var lineResult = Selector.GetSelection("\nselect lines: "); //get user selection
if (lineResult.Status != PromptStatus.OK) return;
var lines = new List<Line>();
foreach (var objId in lineResult.Value.GetObjectIds())
lines.Add(objId.GetObject(OpenMode.ForRead) as Line);
for (var i = 0; i < lines.Count; i++)
{
if (i + 1 == lines.Count) break;
for (var j = i + 1; j < lines.Count; j++)
{
Line line1 = lines[i], line2 = lines[j];
var interPts = new Point3dCollection();
line1.IntersectWith(line2, Intersect.OnBothOperands, interPts, IntPtr.Zero, IntPtr.Zero);
if (interPts.Count > 0) Draw.DrawCircle(interPts[0], 1); //draw a circle with radius 1 on intersection point
}
}
});
}
```
Solved! Go to Solution.