Author Topic: Selection Sets VS. For Each  (Read 3128 times)

0 Members and 1 Guest are viewing this topic.

TR

  • Guest
Selection Sets VS. For Each
« on: May 09, 2005, 05:36:47 PM »
Which do you prefer to use? I have used both methods and I find the For Each Method a lot easier to code and understand. I also haven't noticed that much of a speed difference between the two. Has anyone else?

Note: The code below is just a modified version of some stuff I had. It is for example only and it wasn't tested to see if it works.

For Each:
Code: [Select]

Public Sub Test()
Dim ae As AcadEntity
For Each ae In ThisDrawing.ModelSpace
    If TypeOf ae Is AcadRasterImage Then
       MsgBox (ae.Name)
    End If
Next


Selection Set:
Code: [Select]

Public Sub Test2()
Dim SelSet As AcadSelectionSet
Dim FilterType(0 To 0) As Integer
Dim FilterData(0 To 0) As Variant
Dim AT As AcadAttribute

FilterType(0) = 0
FilterData(0) = "ATTDEF"
On Error GoTo Exit_Error
ThisDrawing.SelectionSets.Add "SelSet"
Set SelSet = ThisDrawing.SelectionSets("SelSet")
SelSet.Clear
             
SelSet.Select acSelectionSetAll, , , FilterType, FilterData
If SelSet.Count <> 0 Then
       For Each AT In SelSet
           MsgBox (AT.Name)
       Next
End If

SelSet.Clear

Exit_Error:
    Select Case Err.Number
    Case -2145386494 'not applicable
        Resume Next
    Case Else
        SelSet.Delete
        Set SelSet = Nothing
        Set AT = Nothing
        Set TXT = Nothing
    End Select
End Sub

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selection Sets VS. For Each
« Reply #1 on: May 09, 2005, 08:46:56 PM »
I regularly use both ... each has their purposes and as you have said.. I have not experienced any significant speed degradation
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hendie

  • Guest
Selection Sets VS. For Each
« Reply #2 on: May 11, 2005, 05:39:18 AM »
I guess I tend to use selection sets more often, but that's mainly because I'm after harvesting groups of like objects, although I have used t'other method once or twice.

My philosophy is.. if it works and doesn't throw a wobbly then it's ok.

hendie

  • Guest
Selection Sets VS. For Each
« Reply #3 on: May 11, 2005, 05:43:01 AM »
I guess I tend to use selection sets more often, but that's mainly because I'm after harvesting groups of like objects, although I have used t'other method once or twice.

My philosophy is.. if it works and doesn't throw a wobbly then it's ok.