• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Member
    Posts: 6
    Registered: ‎02-22-2013
    Accepted Solution

    Way of getting all objects between two points.

    196 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

    Please use plain text.
    Valued Mentor
    Posts: 321
    Registered: ‎05-06-2012

    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.

     

     

    Please use plain text.
    Mentor
    Posts: 225
    Registered: ‎04-11-2010

    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

     

     

    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎02-22-2013

    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.

    Please use plain text.
    Valued Mentor
    Posts: 321
    Registered: ‎05-06-2012

    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.

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    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

    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎02-22-2013

    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:

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    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

    Please use plain text.
    Valued Contributor
    Posts: 61
    Registered: ‎01-09-2009

    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

    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎02-22-2013

    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

    Please use plain text.