Hi Guys,
Im new in VB.Net. I tried to create basic objects using Lines circle and try to get the intersection of 2 objects. But it give me some errors.
What I did is to select polyline then another line that is cross to the polyline. After the selecting 2 objects it will detect the intersection and the program will give Points3D. using the points given I will create temporary objects like circle and check the intersection. Thats the error area, were I cannot get the intersection points of the temporary circle and the selected line.
Another problem that I tried is new objects to be intersect to another new objects it will gives error as well.
I hope somebody understand my problem.
Thanks in advance.
Regards,
Alex
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by _gile. Go to Solution.
I might be wrong but I believe that any entities that you use with IntersectsWith will need to be added to the database and have an ObjectId.
Hi,
Here's a working example with an existing polyline and a temporary circle (i.e. the newly created circle is not added to the database).
This example is written in C#, you could convert it with telerik code converter for example*, but assuming you're starting with .NET you should learn C# instead of VB because you'll find more valuable help and examples in C#.
[CommandMethod("TEST")] public static void Test() { var doc = AcAp.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; // prompt the use to select a polyline var peo = new PromptEntityOptions("\nSelect Polyline: "); peo.SetRejectMessage("\nMust be a Polyline."); peo.AddAllowedClass(typeof(Polyline), true); var per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return; // prompt the user to specify center of the circle var ppr = ed.GetPoint("\nSpecify the center: "); if (ppr.Status != PromptStatus.OK) return; // prompt the user to specify the radius of the circle var pdo = new PromptDistanceOptions("\nSpecify the radius: "); pdo.BasePoint = ppr.Value; pdo.UseBasePoint = true; var pdr = ed.GetDistance(pdo); if (pdr.Status != PromptStatus.OK) return; using (var tr = db.TransactionManager.StartTransaction()) { // open the selected polyline for read var pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead); var points = new Point3dCollection(); // create a temporary circle var center = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem); double radius = pdr.Value; // the using statement insures the circle to be disposed instead of been added to the database using (var circle = new Circle(center, Vector3d.ZAxis, radius)) { // search for intersection pline.IntersectWith(circle, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero); // print the output if (points.Count > 0) { ed.WriteMessage("\nIntersections:"); foreach (Point3d point in points) { ed.WriteMessage($" {point:0.00}"); } } else { ed.WriteMessage("\nNone intersection."); } } tr.Commit(); } }
*if you use some automatic converter to convert C# to VB, take care the VB "Infer" and "Strict" options are "On" in your project
Many thanks.
Whole day I tried to find the answer and you just did it in just a couple of minutes.
Once again many thanks.
Instead of creating "temporary entities" for solving geometrical issues, you can use the the geometrical object from the Autodesk.AutoCAD.Geometry namespace.
Here's an example converting a selected Line entity into a LineSegment3d and creating a CircularArc3d to serach intersections.
[CommandMethod("TEST")] public static void Test() { var doc = AcAp.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; // prompt the use to select a line var peo = new PromptEntityOptions("\nSelect Line: "); peo.SetRejectMessage("\nMust be a Polyline."); peo.AddAllowedClass(typeof(Line), true); var per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return; // prompt the user to specify center of the circle var ppr = ed.GetPoint("\nSpecify the center: "); if (ppr.Status != PromptStatus.OK) return; // prompt the user to specify the radius of the circle var pdo = new PromptDistanceOptions("\nSpecify the radius: "); pdo.BasePoint = ppr.Value; pdo.UseBasePoint = true; var pdr = ed.GetDistance(pdo); if (pdr.Status != PromptStatus.OK) return; // get a geometrical line form the selected line LineSegment3d line; using (var tr = new OpenCloseTransaction()) { var pline = (Line)tr.GetObject(per.ObjectId, OpenMode.ForRead); line = (LineSegment3d)pline.GetGeCurve(); } // create a geometrical circle var center = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem); double radius = pdr.Value; var circle = new CircularArc3d(center, Vector3d.ZAxis, radius); // search for intersections betwen the line and circle var points = circle.IntersectWith(line); if (points != null) { ed.WriteMessage("\nIntersections:"); foreach (Point3d point in points) { ed.WriteMessage($" {point:0.00}"); } } else { ed.WriteMessage("\nNone intersection."); } }
Hi Gile,
Thank you for the tip. Very helpful.
I think this is the best approach rather than making temporary objects.
Many thanks again.
Best regards,
Alex