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
Solved! Go to Solution.
Solved by arcticad. Go to Solution.
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
Short answer is no.
You will need to iterate the objects in the selection set and compile your own list of the unique names.
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
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
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.