Hey all.
Is there any way of getting ALL objects a Line/ray intersects with?
I am thinking of something like:
*Pseudocode*
Ray ray = new Ray(); ray.To = dest; ray.From = start;
ray.Fire(); var obj = ray.GetFirstHitObject(); /* or null if nothing */ // continue here //
I don't even need the object, a simple true if it hits something, or false if not is enough for me.
Greetings from Austria,
Thomas
Solved! Go to Solution.
Solved by DiningPhilosopher. Go to Solution.
The Entity class has an IntersectWith() method that tells if the entity intersects another Entity.
Hi,
If you are trying to select the objects intersected, you can use Editor.SelectFence(fencePoints, SomeFilter). If you need the intersection points, then use both fence selection to obtain the objects and TT suggestion of IntersectWith to get the points.
Regards,
Gaston Nunez
@DiningPhilosopher wrote:The Entity class has an IntersectWith() method that tells if the entity intersects another Entity.
Thank you, but that was not the question.
@Anonymous wrote:Thank you, but that was not the question.
It wasn't the question, it was one answer to how to do what the question asked.
You can also try Gaston's suggestion, assuming all the candidate objects are visible in the current view.
@Anonymous wrote:
@DiningPhilosopher wrote:
The Entity class has an IntersectWith() method that tells if the entity intersects another Entity.
Thank you, but that was not the question.
Ok! You have to iterate ALL entities in current space (ModelSpace or PaperSpace) and find intersection of entities and yours line/ray. Method with Editor.SelectFence has so many restrictions...
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
@Alexander.Rivilis wrote:Ok! You have to iterate ALL entities in current space (ModelSpace or PaperSpace) and find intersection of entities and yours line/ray. Method with Editor.SelectFence has so many restrictions...
Could you enlighten me about the restrictions of SelectFence()? the only thing i need is to know IF there is something in the way, neither what, nor how big it is.
And if i would give SelectFence a Point modell of a cube for example, would it get all objects that intersect with it?
Thanks again for all the answers 🙂
e1028439 wrote:And if i would give SelectFence a Point modell of a cube for example, would it get all objects that intersect with it?
No. Editor.SelectFence allow to select entities:
1. Visible on active view.
2. Projection of those on active view has intersection with "fence".
3. If entity has not continuous linetype - it will be problem.
4. Zoom factor of current view also affect selection.
5. Allow select entities but not found intersection points - only fact of intersection.
6. Dependent of entities type.
7. Points have to be in UCS (not in WCS)
8. etc.,etc.,etc...
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
I think you need to create a "Virtual Line" (named vl in my code) and do a window selection based on youre 2 points.
The code beneath is not tested but I think it should look like this:
Private Sub MyIntersection() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor Dim db As Database = doc.Database Dim p3dc As Point3dCollection = Nothing Dim ppo As New PromptPointOptions(vbCrLf & "Select point: ") ppo.AllowNone = False Dim pt1 As Point3d = ed.GetPoint(ppo).Value Dim pt2 As Point3d = ed.GetPoint(ppo).Value Dim psr As PromptSelectionResult = ed.SelectWindow(pt1, pt2) Dim vl As New Line(pt1, pt2) Dim oic As New ObjectIdCollection If psr.Status = PromptStatus.OK Then Using dl As DocumentLock = doc.LockDocument Using tr As Transaction = db.TransactionManager.StartTransaction For Each so As SelectedObject In psr.Value p3dc = Nothing Dim ent As Entity = TryCast(tr.GetObject(so.ObjectId, OpenMode.ForRead), Entity) Try vl.IntersectWith(ent, Intersect.ExtendBoth, p3dc, 0, 0) If p3dc.Count > 0 Then oic.Add(ent.ObjectId) End If Catch End Try Next End Using 'Now youre intersecting objects are in the oic (objectIdCollection) End Using End If End Sub
Regards
Peter
@Anonymous wrote:I think you need to create a "Virtual Line" (named vl in my code) and do a window selection based on youre 2 points.
Regards
Peter
Dear Peter, i modified your code a little bit to use Editor.SelectCrossingWindow, and now it throws a eNotImplementedYet exeption on the following line >vl.IntersectWith()<.
I needed to change to SelectCrossingWindow because i need all objects i hit, not only the ones i completely surround.
Greetings
Thomas
@Anonymous wrote:
Dear Peter, i modified your code a little bit to use Editor.SelectCrossingWindow, and now it throws a eNotImplementedYet exeption on the following line >vl.IntersectWith()<.
What kind of entity (name of class) was intersected?
I also recommend to use Intersect.OnBothOperands instead of Intersect.ExtendBoth because many kind of entities can not be extended.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
it was an InfiniteLine, and i tried all 4 of the possible intersect enum types, all throw the same eNotImplementedYet exception
The code you're trying to use doesn't work as posted because it passes null to IntersectWith() in the argument that requires a Point3dCollection.
That may be what is causing the exception. Create a new Point3dCollection and call it's Clear() method just before each call to IntersectWith().
@Anonymous wrote:it was an InfiniteLine, and i tried all 4 of the possible intersect enum types, all throw the same eNotImplementedYet exception
The base AutoCAD product API has no class called "InfiniteLine".
The XLine is an infinite line, so perhaps that's what you meant?
var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var db = doc.Database; var ppo = new PromptPointOptions("\nSelect point: ") { AllowNone = false }; var pt1 = ed.GetPoint(ppo).Value; var pt2 = ed.GetPoint(ppo).Value; var psr = ed.SelectCrossingWindow(pt1, pt2); var vl = new Line(pt1, pt2); var oic = new ObjectIdCollection(); if (psr.Status != PromptStatus.OK) return; using (var dl = doc.LockDocument()) using (var tr = db.TransactionManager.StartTransaction()) { Point3dCollection p3dc; foreach (SelectedObject so in psr.Value) { p3dc = new Point3dCollection(); var ent = tr.GetObject(so.ObjectId, OpenMode.ForRead) as Entity; try { vl.IntersectWith(ent, Intersect.OnBothOperands, p3dc, new IntPtr(), new IntPtr()); if (ent != null && p3dc.Count > 0) oic.Add(ent.ObjectId); } catch (Exception) { } } } ed.WriteMessage("\n" + oic.Count);
thats the code i am currently trying with, and the exception occurs at vl.IntersectWith();
Exception details:
Autodesk.AutoCAD.Runtime.Exception: eNotImplementedYet at Autodesk.AutoCAD.DatabaseServices.Entity.IntersectWith(Entity entityPointer, Intersect intersectType, Point3dCollection points, IntPtr thisGraphicSystemMarker, IntPtr otherGraphicSystemMarker) at AcadPlugin.MyCommands.MyIntersection() in e:\DEV\AcadPlugin1.0\AcadPlugin1.0\Commands.cs:Zeile 154.} System.Exception {Autodesk.AutoCAD.Runtime.Exception} ent = {Autodesk.AutoCAD.DatabaseServices.Solid3d} so = [Autodesk.AutoCAD.EditorInput.CrossingOrWindowSelectedObject] = { (((8754286416000),Crossing,6,) (InfiniteLine,(30825.1342620582,30781.8322475576,4200.53349038419),(-0.577350269189626,-0.577350269189626,-0.577350269189626)) (InfiniteLine,(30315.8322765267,31291.1342330891,4200.53349038419),(-0.577350269189626,-0.5773502691...
Hope this helps.
Autodesk hasn't added support for finding intersections with 3D Solid objects and surfaces.
To do that, you will need to use the BoundaryRepresentation API, and is far more complicated than what has been described thus far.
AutoCAD is 3D CADD mainly in terms of its ability to create 3D objects, but is severely crippled in terms of 3D API functionality, and to a lesser-extent, 3D editing and analytical functionality.
Can't find what you're looking for? Ask the community or share your knowledge.