.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Remove One SelectionSet to Another One

3 REPLIES 3
Reply
Message 1 of 4
glanard
603 Views, 3 Replies

Remove One SelectionSet to Another One

Hi,

 

Assuming the model space is active with a zoom extents, my question is:

 

I have 2 selection sets:

- ssA= The first one that contains all the entities (SelectAll).

- ssB= The second one that as been made using the SelectCrossingWindow method.

 

What I want is to remove the 2nd selection set from the first one: in other words, to get (ssA-ssB).

 

In VBA, I remember we had a RemoveItems method, but it seems not in VB.NET.

 

Have you an idea to make this substraction?

I repeat that ssB contains SelectedObjectByWindow...

 

Thanks,

3 REPLIES 3
Message 2 of 4
Hallex
in reply to: glanard

You might want to look closely at FromObjectIds method:

 

Dim newSset As SelectionSet  = SelectionSet.FromObjectIds(ids)

 

 

See docs

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4
glanard
in reply to: glanard

Hi all,

 

Thanks...

 

but I found the answer by myself before Smiley Tongue

 

Something like:

 

ssA = New ObjectIdCollection(objSS.GetObjectIds())

for each objId As ObjectID in ssB.GetObjectIds()
     ssA.Remove(objId)
next

 

 

 

Message 4 of 4
Hallex
in reply to: glanard

Good point

If this is interesting for somebody else

here is how to apply FromObjectIds method to solve this task

{code}

       <CommandMethod("SELWP")> _
        Public Sub WindowPolygonSelect()

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database

            Dim ed As Editor = doc.Editor

            Dim aset As ObjectIdCollection = Nothing

            Dim bset As List(Of ObjectId) = Nothing

            Dim ppo As New PromptPointOptions(vbLf & "Pick first corner: ")

            Dim res As PromptPointResult

            res = ed.GetPoint(ppo)

            If res.Status <> PromptStatus.OK Then

                Return

            End If

            Dim p1 As Point3d = res.Value

            Dim pco As New PromptCornerOptions(vbLf & "Pick opposite corner: ", p1)

            pco.BasePoint = p1

            pco.UseDashedLine = True

            res = ed.GetCorner(pco)

            If res.Status <> PromptStatus.OK Then

                Return

            End If

            Dim p2 As Point3d = res.Value
            Try
                Using tr As Transaction = db.TransactionManager.StartTransaction()

                    Dim sresA As PromptSelectionResult

                    Dim filterList(,) As Object = New Object(,) {{-4, "<or"}, {0, "text"}, {0, "mtext"}, {0, "dimension"}, {0, "insert"}, {0, "leader"}, {-4, "or>"}}

                    Dim tvs(filterList.GetUpperBound(0)) As TypedValue

                    For i As Integer = 0 To filterList.GetUpperBound(0)

                        tvs(i) = New TypedValue(Convert.ToInt32(filterList(i, 0)), filterList(i, 1))

                    Next

                    Dim filt As SelectionFilter = New SelectionFilter(tvs)

                    sresA = ed.SelectCrossingWindow(p1, p2, filt)

                    If res.Status <> PromptStatus.OK Then

                        Return

                    End If

                    Dim ssA As SelectionSet

                    ssA = sresA.Value

                    If ssA Is Nothing Then

                        ed.WriteMessage(vbLf & "Nothing selected...")

                        Return

                    End If

                    ed.WriteMessage(vbLf & "Selected by crosing window:   {0}", ssA.Count)

                    Dim idsA As ObjectId() = ssA.GetObjectIds

                    aset = New ObjectIdCollection(idsA)

                    Dim sresB As PromptSelectionResult

                    sresB = ed.SelectAll

                    ed.WriteMessage(vbLf & "Selected all:   {0}", sresB.Value.Count)

                    Dim ssB As SelectionSet

                    bset = New List(Of ObjectId)

                    ssB = sresB.Value

                    If ssB Is Nothing Then

                        ed.WriteMessage(vbLf & "Nothing selected...")

                        Return

                    End If

                    Dim idsB As ObjectId() = ssB.GetObjectIds

                    For Each id As ObjectId In idsB

                        If Not aset.Contains(id) Then

                            bset.Add(id)

                        End If

                    Next

                    ssB = SelectionSet.FromObjectIds(bset.ToArray)

                    ed.SetImpliedSelection(ssB)


                    ed.WriteMessage(vbLf & "Now in selection is :   {0}", ssB.Count)


                    tr.Commit()

                End Using

            Catch ex As System.Exception

                MsgBox(ex.Message + vbCrLf + ex.StackTrace)

            Finally

            End Try

        End Sub

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost