.NET

.NET

Reply
Active Member
e1028439
Posts: 9
Registered: ‎02-22-2013
Message 1 of 16 (331 Views)
Accepted Solution

Way of getting all objects between two points.

331 Views, 15 Replies
03-11-2013 04:33 PM

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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 16 (320 Views)

Re: Way of getting all objects between two points.

03-11-2013 06:11 PM in reply to: e1028439

The Entity class has an IntersectWith() method that tells if the entity  intersects another Entity.

 

 

Valued Mentor
gasty1001
Posts: 468
Registered: ‎04-11-2010
Message 3 of 16 (316 Views)

Re: Way of getting all objects between two points.

03-11-2013 06:46 PM in reply to: e1028439

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

 

 

Active Member
e1028439
Posts: 9
Registered: ‎02-22-2013
Message 4 of 16 (306 Views)

Re: Way of getting all objects between two points.

03-11-2013 08:44 PM in reply to: DiningPhilosopher

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.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 16 (297 Views)

Re: Way of getting all objects between two points.

03-11-2013 11:20 PM in reply to: e1028439

e1028439 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.

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 6 of 16 (294 Views)

Re: Way of getting all objects between two points.

03-11-2013 11:26 PM in reply to: e1028439

e1028439 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...


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Member
e1028439
Posts: 9
Registered: ‎02-22-2013
Message 7 of 16 (270 Views)

Re: Way of getting all objects between two points.

03-12-2013 06:29 AM in reply to: Alexander.Rivilis

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 :smileyhappy:

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 8 of 16 (266 Views)

Re: Way of getting all objects between two points.

03-12-2013 06:58 AM in reply to: e1028439

 

 


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...


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
RPeter
Posts: 82
Registered: ‎01-09-2009
Message 9 of 16 (254 Views)

Re: Way of getting all objects between two points.

03-12-2013 09:07 AM in reply to: e1028439

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

Active Member
e1028439
Posts: 9
Registered: ‎02-22-2013
Message 10 of 16 (237 Views)

Re: Way of getting all objects between two points.

03-12-2013 03:02 PM in reply to: RPeter

RPeter 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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.