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

VB.NET SelectionSet sorting

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
gablackburn
1225 Views, 5 Replies

VB.NET SelectionSet sorting

To make a long story short, I have a layer called DoorsLayer and I have blocks in that layer which are called DOOR1, DOOR2, DOOR3 etc.   Each block may or may not be in there, but I have at least one block called DOOR* in the layer. 

 

I'd like the user to make a selection window, have my code bring up a listbox which shows which blocks were found, then have the user select the block names they'd like to work with.

 

I have a filter set to only return blocks within the layer so that's not a problem.

myTV(0) = New DatabaseServices.TypedValue(0, "INSERT")
myTV(1) = New DatabaseServices.TypedValue(DatabaseServices.DxfCode.LayerName, "DOORSLAYER")
 

My Question;

 

Is it possible to have the SelectionSet return all of the unique block names it found within itself?  For instance, if their window found a total of 100 blocks, comprised of DOOR1, DOOR3 & DOOR7, I'd like it to return just those three block names, and not a list of 100 block names.

 

I realize I can probably go through each object found, get its blockname, save it to an array, then go through my array to pick out all of the unique names and them to my listbox.  However I was wondering if there's a more efficient way.

 

 

Thanks in advance

 

GAB

 

5 REPLIES 5
Message 2 of 6
arcticad
in reply to: gablackburn

 

  You could just sort the list for the values. 

        Dim str As List(Of String)
        For i = 0 To sset.count - 1
            Dim blockname As String =    ' get block name from sset(i)
            If Not str.Contains(BlockName) Then
                str.Add(BlockName))
            End If
Next

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 6

Short answer is no.

 

You will need to iterate the objects in the selection set and compile your own list of the unique names.

Dave O.                                                                  Sig-Logos32.png
Message 4 of 6
gablackburn
in reply to: arcticad

arcticad & chiefbraincloud, thanks for the quick responses.  I'm embarrassed to say I wasn't aware of 'as List (of String)', but it works exactly the way I need it to. 

 

chiefbraincloud, I'm not sure if I can have two accepted solutions, but  you answered the question in that what I want to do is not possible anyway.

 

The one thing I found is that I believe the top line below should have the declaration NEW added to it. 

 

Dim str As List(Of String)

Dim str As New List(Of String)

 

Thanks again.

 

GAB

 

Message 5 of 6
Irvin
in reply to: gablackburn

Hi there,

 

There a methods to get a 'Distinct' selection of a list. Only u need to use linq.

 

Please look at the webpage following this link:

 

http://blogs.msdn.com/b/charlie/archive/2006/11/19/linq-farm-group-and-distinct.aspx

 

Hope this helps.

 

Kind regards,

 

Irvin

Message 6 of 6
chiefbraincloud
in reply to: Irvin

Thanks for the tip.  I was actually under the impression that LINQ was not available to me (on VS 2005), but after a little searching, I found an early release that does work with VB 2005.  Now I'll have to pay more attention to things I read about LINQ.  (and maybe go back and re-read some of Kean's posts on LINQ)

 

For what it's worth, though, GAB will still have to iterate the SelectionSet to create the list of block names.

Dave O.                                                                  Sig-Logos32.png

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